From 28836cf81f5076aeb94142081fd26fbbba9f27fc Mon Sep 17 00:00:00 2001 From: Kevin Day Date: Sun, 14 Jun 2020 23:54:58 -0500 Subject: [PATCH] Feature: add macro initializers for static string and string ranges Creating defines with present lengths and them using these in static strings, sometimes with ranges, has become more common. Provide the macros to make this simpler and ever be more usable for creating constant static strings and constant string ranges. --- level_0/f_string/c/string.h | 12 ++++++++++++ level_0/f_utf/c/utf.h | 8 ++++++++ 2 files changed, 20 insertions(+) diff --git a/level_0/f_string/c/string.h b/level_0/f_string/c/string.h index a672e9e..6201b7a 100644 --- a/level_0/f_string/c/string.h +++ b/level_0/f_string/c/string.h @@ -152,6 +152,8 @@ extern "C" { * Therefore, a range from 0 to 0 would be include position 0. * Set start to some value larger than stop to designate that there is no range (such as start = 1, stop = 0). * + * A special f_macro_string_range_initialize() is provided for the special purpose of easily initialize a static string range. + * * start: the start position. * stop: the stop position. */ @@ -162,6 +164,12 @@ extern "C" { } f_string_range; #define f_string_range_initialize { 1, 0 } + + #define f_macro_string_range_initialize(length) { 0, length - 1 } + + #define f_macro_string_range_clear(range) \ + range.start = 1; \ + range.stop = 0; #endif // _di_f_string_range_ /** @@ -252,6 +260,8 @@ extern "C" { * * The f_string_static type should never be directly allocated or deallocated. * + * A special f_macro_string_static_initialize() is provided for the special purpose of easily initialize a static string. + * * string: the string. * size: total amount of space available. * used: total number of space used. @@ -270,6 +280,8 @@ extern "C" { string_static.string = 0; \ string_static.size = 0; \ string_static.used = 0; + + #define f_macro_string_static_initialize(string, length) { string, length, length } #endif // _di_f_string_static_ /** diff --git a/level_0/f_utf/c/utf.h b/level_0/f_utf/c/utf.h index 7858da7..6ce6cd0 100644 --- a/level_0/f_utf/c/utf.h +++ b/level_0/f_utf/c/utf.h @@ -212,6 +212,8 @@ extern "C" { /** * Designates a start and stop position that represents a sub-string inside of some parent string. * use this to avoid resizing, restructuring, and reallocating the parent string to separate the sub-string. + * + * A special f_macro_utf_string_range_initialize() is provided for the special purpose of easily initialize a static string range. */ #ifndef _di_f_utf_string_range_ typedef struct { @@ -221,6 +223,8 @@ extern "C" { #define f_utf_string_range_initialize { 1, 0 } + #define f_macro_utf_string_range_initialize(length) { 0, length - 1 } + #define f_macro_utf_string_range_new(status, utf_string_range, length) status = f_memory_new((void **) & utf_string_range, sizeof(f_utf_string_range), length) #define f_macro_utf_string_range_delete(status, utf_string_range, size) status = f_memory_delete((void **) & utf_string_range, sizeof(f_utf_string_range), size) #define f_macro_utf_string_range_destroy(status, utf_string_range, size) status = f_memory_destroy((void **) & utf_string_range, sizeof(f_utf_string_range), size) @@ -317,6 +321,8 @@ extern "C" { * * The f_utf_string_static type should never be directly allocated or deallocated. * + * A special f_macro_utf_string_static_initialize() is provided for the special purpose of easily initialize a static string. + * * string: the string. * size: total amount of space available. * used: total number of space used. @@ -335,6 +341,8 @@ extern "C" { string_static.string = 0; \ string_static.size = 0; \ string_static.used = 0; + + #define f_macro_utf_string_static_initialize(string, length) { string, length, length } #endif // _di_f_string_static_ /** -- 1.8.3.1