summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2022-10-23 12:58:06 -0400
committerDavid Robillard <d@drobilla.net>2022-10-23 13:42:13 -0400
commitf95a698b94069ed03f6a8f2d0f7eb089d66c91ef (patch)
tree92da0fe8ece8a1890bf23fe67a38eb95556d03d8 /src
parente883ea50dd1154294e21e946e391dd38e04d6527 (diff)
downloadzix-f95a698b94069ed03f6a8f2d0f7eb089d66c91ef.tar.gz
zix-f95a698b94069ed03f6a8f2d0f7eb089d66c91ef.tar.bz2
zix-f95a698b94069ed03f6a8f2d0f7eb089d66c91ef.zip
Add string view API
Diffstat (limited to 'src')
-rw-r--r--src/string_view.c18
1 files changed, 18 insertions, 0 deletions
diff --git a/src/string_view.c b/src/string_view.c
new file mode 100644
index 0000000..9d98258
--- /dev/null
+++ b/src/string_view.c
@@ -0,0 +1,18 @@
+// Copyright 2007-2022 David Robillard <d@drobilla.net>
+// SPDX-License-Identifier: ISC
+
+#include "zix/string_view.h"
+#include "zix/allocator.h"
+
+#include <string.h>
+
+char*
+zix_string_view_copy(ZixAllocator* const allocator, const ZixStringView view)
+{
+ char* const copy = (char*)zix_malloc(allocator, view.length + 1U);
+ if (copy) {
+ memcpy(copy, view.data, view.length);
+ copy[view.length] = '\0';
+ }
+ return copy;
+}