From 67526c25f4a751be27d2f9eed38d07fe52342aa5 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Wed, 10 May 2023 16:00:29 -0400 Subject: Add ZIX_STATIC_STRING() --- include/zix/string_view.h | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'include/zix') 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 +// Copyright 2011-2023 David Robillard // 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 -- cgit v1.2.1