aboutsummaryrefslogtreecommitdiff
path: root/std/str.c
diff options
context:
space:
mode:
authorElias Fleckenstein <eliasfleckenstein@web.de>2021-12-30 14:18:15 +0100
committerElias Fleckenstein <eliasfleckenstein@web.de>2021-12-30 14:18:15 +0100
commitecc06c082036aa93f6810ec21e73610c55f5a57b (patch)
treeaff479c3bc5b39ead9f65dffb01d399b341fa4ba /std/str.c
downloaduwu-lang-ecc06c082036aa93f6810ec21e73610c55f5a57b.tar.xz
Initial commit
Diffstat (limited to 'std/str.c')
-rw-r--r--std/str.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/std/str.c b/std/str.c
new file mode 100644
index 0000000..16f756b
--- /dev/null
+++ b/std/str.c
@@ -0,0 +1,30 @@
+#include <string.h>
+#include <stdlib.h>
+#include "../api/vm.h"
+#include "../api/str.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);
+}