Branch data Line data Source code
1 : : // Copyright 2021-2024 David Robillard <d@drobilla.net> 2 : : // SPDX-License-Identifier: ISC 3 : : 4 : : /* 5 : : Example code that is included in the documentation. Code in the 6 : : documentation is included from here rather than written inline so that it can 7 : : be tested and avoid rotting. The code here doesn't make much sense, but is 8 : : written such that it at least compiles and will run without crashing. 9 : : */ 10 : : 11 : : #include <zix/attributes.h> 12 : : #include <zix/string_view.h> 13 : : 14 : : static void 15 : 1 : string_views(void) 16 : : { 17 : 1 : const char* const string_pointer = "some string"; 18 : : 19 : : // begin make-empty-string 20 : : ZixStringView empty = zix_empty_string(); 21 : : // end make-empty-string 22 : : (void)empty; 23 : : 24 : : // begin make-static-string 25 : : static const ZixStringView hello = ZIX_STATIC_STRING("hello"); 26 : : // end make-static-string 27 : : (void)hello; 28 : : 29 : : // begin measure-string 30 : : ZixStringView view = zix_string(string_pointer); 31 : : // end measure-string 32 : : (void)view; 33 : : 34 : : // begin make-string-view 35 : : ZixStringView slice = zix_substring(string_pointer, 4); 36 : : // end make-string-view 37 : : (void)slice; 38 : 1 : } 39 : : 40 : : ZIX_CONST_FUNC int 41 : 1 : main(void) 42 : : { 43 : 1 : string_views(); 44 : 1 : return 0; 45 : : }