From f95a698b94069ed03f6a8f2d0f7eb089d66c91ef Mon Sep 17 00:00:00 2001 From: David Robillard Date: Sun, 23 Oct 2022 12:58:06 -0400 Subject: Add string view API --- src/string_view.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 src/string_view.c (limited to 'src/string_view.c') 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 +// SPDX-License-Identifier: ISC + +#include "zix/string_view.h" +#include "zix/allocator.h" + +#include + +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; +} -- cgit v1.2.1