diff options
author | Elias Fleckenstein <eliasfleckenstein@web.de> | 2022-01-01 19:42:10 +0100 |
---|---|---|
committer | Elias Fleckenstein <eliasfleckenstein@web.de> | 2022-01-01 19:42:10 +0100 |
commit | 7b375939be901cf2114916193da9f4b9864f0504 (patch) | |
tree | 8fceafb2b1cc3817ee9f9d39eb9509f2d8e93033 /str.c | |
download | uwu-std-7b375939be901cf2114916193da9f4b9864f0504.tar.xz |
Diffstat (limited to 'str.c')
-rw-r--r-- | str.c | 36 |
1 files changed, 36 insertions, 0 deletions
@@ -0,0 +1,36 @@ +#include <string.h> +#include <stdlib.h> +#include "api/vm.h" +#include "api/str.h" +#include "api/util.h" + +UwUVMValue uwu_cat(UwUVMArgs *args) +{ + size_t total_len = 0; + size_t lengths[args->num]; + char *substrs[args->num]; + + for (size_t i = 0; i < args->num; i++) { + substrs[i] = uwustr_get(uwuvm_get_arg(args, i)); + lengths[i] = strlen(substrs[i]); + total_len += lengths[i]; + } + + char result[total_len + 1]; + char *result_ptr = result; + + for (size_t i = 0; i < args->num; i++) { + strcpy(result_ptr, substrs[i]); + free(substrs[i]); + result_ptr += lengths[i]; + } + + *result_ptr = 0; + + return uwustr_create(result); +} + +UwUVMValue uwu_is(UwUVMArgs *args) +{ + return uwuutil_is_type("str.is", args, &uwustr_type); +} |