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() --- doc/overview_code.c | 5 +++-- doc/string_views.rst | 13 ++++++++++++- 2 files changed, 15 insertions(+), 3 deletions(-) (limited to 'doc') diff --git a/doc/overview_code.c b/doc/overview_code.c index 1370292..2f6a099 100644 --- a/doc/overview_code.c +++ b/doc/overview_code.c @@ -1,4 +1,4 @@ -// Copyright 2021-2022 David Robillard +// Copyright 2021-2023 David Robillard // SPDX-License-Identifier: ISC /* @@ -26,8 +26,9 @@ string_views(void) // end make-empty-string // begin make-static-string - ZixStringView hello = zix_string("hello"); + static const ZixStringView hello = ZIX_STATIC_STRING("hello"); // end make-static-string + (void)hello; // begin measure-string ZixStringView view = zix_string(string_pointer); diff --git a/doc/string_views.rst b/doc/string_views.rst index b6e3fd9..6c049f3 100644 --- a/doc/string_views.rst +++ b/doc/string_views.rst @@ -1,5 +1,5 @@ .. - Copyright 2020-2022 David Robillard + Copyright 2020-2023 David Robillard SPDX-License-Identifier: ISC String Views @@ -15,6 +15,17 @@ This forces code to be explicit about string measurement, which discourages common patterns of repeated measurement of the same string. For convenience, several macros and functions are provided for constructing string views: +:macro:`ZIX_STATIC_STRING` + + Initializes a string view from a string literal. Note that this may only be + used with inlined string literals, passing a pointer to an arbitrary string + is undefined behaviour, for example: + + .. literalinclude:: overview_code.c + :start-after: begin make-static-string + :end-before: end make-static-string + :dedent: 2 + :func:`zix_empty_string` Constructs a view of an empty string, for example: -- cgit v1.2.1