diff options
author | David Robillard <d@drobilla.net> | 2023-05-10 16:00:29 -0400 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2023-05-10 18:27:55 -0400 |
commit | 67526c25f4a751be27d2f9eed38d07fe52342aa5 (patch) | |
tree | 69039501fb0c15d6386d2fe73174af47085f673f /include/zix/string_view.h | |
parent | ff5104de74122477459b48df8b046d06d2db506b (diff) | |
download | zix-67526c25f4a751be27d2f9eed38d07fe52342aa5.tar.gz zix-67526c25f4a751be27d2f9eed38d07fe52342aa5.tar.bz2 zix-67526c25f4a751be27d2f9eed38d07fe52342aa5.zip |
Add ZIX_STATIC_STRING()
Diffstat (limited to 'include/zix/string_view.h')
-rw-r--r-- | include/zix/string_view.h | 11 |
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 |