Branch data Line data Source code
1 : : // Copyright 2007-2025 David Robillard <d@drobilla.net> 2 : : // SPDX-License-Identifier: ISC 3 : : 4 : : #include <zix/string_view.h> 5 : : 6 : : #include <zix/allocator.h> 7 : : #include <zix/attributes.h> 8 : : 9 : : #include <stdbool.h> 10 : : #include <string.h> 11 : : 12 : : char* 13 : 64 : zix_string_view_copy(ZixAllocator* const allocator, const ZixStringView view) 14 : : { 15 : 64 : char* const copy = (char*)zix_malloc(allocator, view.length + 1U); 16 [ + + ]: 64 : if (copy) { 17 : 60 : memcpy(copy, view.data, view.length); 18 : 60 : copy[view.length] = '\0'; 19 : : } 20 : 64 : return copy; 21 : : } 22 : : 23 : : ZIX_NONBLOCKING bool 24 : 13 : zix_string_view_equals(const ZixStringView lhs, const ZixStringView rhs) 25 : : { 26 [ + + ]: 13 : if (lhs.length != rhs.length) { 27 : 3 : return false; 28 : : } 29 : : 30 [ + + ]: 10 : if (lhs.data != rhs.data) { 31 [ + + ]: 32 : for (size_t i = 0U; i < lhs.length; ++i) { 32 [ + + ]: 27 : if (lhs.data[i] != rhs.data[i]) { 33 : 3 : return false; 34 : : } 35 : : } 36 : : } 37 : : 38 : 7 : return true; 39 : : }