diff options
author | David Robillard <d@drobilla.net> | 2023-02-06 20:56:28 -0500 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2023-02-06 20:56:28 -0500 |
commit | 89f9e1fcfb721a17f8043e0c6231ebe7e986e4b7 (patch) | |
tree | d8ec7131fbc601d1576f4c42c3d07d81f3db06de | |
parent | 18e62483cb7173c6604f7dd2097299e47c2a4c0c (diff) | |
download | zix-89f9e1fcfb721a17f8043e0c6231ebe7e986e4b7.tar.gz zix-89f9e1fcfb721a17f8043e0c6231ebe7e986e4b7.tar.bz2 zix-89f9e1fcfb721a17f8043e0c6231ebe7e986e4b7.zip |
Simplify string view interface
-rw-r--r-- | include/zix/string_view.h | 20 | ||||
-rw-r--r-- | src/path.c | 18 |
2 files changed, 10 insertions, 28 deletions
diff --git a/include/zix/string_view.h b/include/zix/string_view.h index f4cd6c2..f1fe009 100644 --- a/include/zix/string_view.h +++ b/include/zix/string_view.h @@ -71,24 +71,10 @@ zix_substring(const char* const ZIX_NONNULL str, const size_t len) ZIX_ALWAYS_INLINE_FUNC ZIX_PURE_FUNC static inline ZixStringView -zix_string(const char* const ZIX_NONNULL str) +// NOLINTNEXTLINE(clang-diagnostic-unused-function) +zix_string(const char* const ZIX_NULLABLE str) { - const ZixStringView view = {str, strlen(str)}; - return view; -} - -/** - Return a view of an entire string by measuring it. - - This makes a view of the given string by measuring it with `strlen`. - - @param str Pointer to the start of a null-terminated C string, or null. -*/ -ZIX_PURE_FUNC -static inline ZixStringView -zix_optional_string(const char* const ZIX_NULLABLE str) -{ - return str ? zix_string(str) : zix_empty_string(); + return str ? zix_substring(str, strlen(str)) : zix_empty_string(); } /** @@ -237,12 +237,12 @@ zix_path_join(ZixAllocator* const allocator, const char* const a, const char* const b) { - const ZixStringView b_view = zix_optional_string(b); + const ZixStringView b_view = zix_string(b); if (!a || !a[0]) { return zix_string_view_copy(allocator, b_view); } - const ZixStringView a_view = zix_optional_string(a); + const ZixStringView a_view = zix_string(a); const ZixRootSlices a_root = zix_path_root_slices(a); const ZixRootSlices b_root = zix_path_root_slices(b); @@ -644,8 +644,7 @@ zix_path_stem(const char* const path) ZixStringView zix_path_extension(const char* const path) { - return range_string_view(path, - zix_path_extension_range(zix_optional_string(path))); + return range_string_view(path, zix_path_extension_range(zix_string(path))); } // Queries @@ -677,28 +676,25 @@ zix_path_has_relative_path(const char* const path) bool zix_path_has_parent_path(const char* const path) { - return !zix_is_empty_range( - zix_path_parent_path_range(zix_optional_string(path))); + return !zix_is_empty_range(zix_path_parent_path_range(zix_string(path))); } bool zix_path_has_filename(const char* const path) { - return !zix_is_empty_range( - zix_path_filename_range(zix_optional_string(path))); + return !zix_is_empty_range(zix_path_filename_range(zix_string(path))); } bool zix_path_has_stem(const char* const path) { - return !zix_is_empty_range(zix_path_stem_range(zix_optional_string(path))); + return !zix_is_empty_range(zix_path_stem_range(zix_string(path))); } bool zix_path_has_extension(const char* const path) { - return !zix_is_empty_range( - zix_path_extension_range(zix_optional_string(path))); + return !zix_is_empty_range(zix_path_extension_range(zix_string(path))); } bool |