summaryrefslogtreecommitdiffstats
path: root/include/zix
diff options
context:
space:
mode:
Diffstat (limited to 'include/zix')
-rw-r--r--include/zix/string_view.h11
1 files changed, 10 insertions, 1 deletions
diff --git a/include/zix/string_view.h b/include/zix/string_view.h
index f1fe009..f13f8d1 100644
--- a/include/zix/string_view.h
+++ b/include/zix/string_view.h
@@ -1,4 +1,4 @@
-// Copyright 2011-2021 David Robillard <d@drobilla.net>
+// Copyright 2011-2023 David Robillard <d@drobilla.net>
// SPDX-License-Identifier: ISC
#ifndef ZIX_STRING_VIEW_H
@@ -29,6 +29,15 @@ typedef struct {
size_t length; ///< Length of string in bytes
} ZixStringView;
+/// Initialize a string view from a string literal
+// clang-format off
+#if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L)
+# define ZIX_STATIC_STRING(s) (ZixStringView) {s, (sizeof(s) - 1U)}
+#else
+# define ZIX_STATIC_STRING(s) { s, (sizeof(s) - 1U) }
+#endif
+// clang-format on
+
/// Return a view of an empty string
ZIX_ALWAYS_INLINE_FUNC
ZIX_CONST_FUNC