diff options
Diffstat (limited to 'include')
-rw-r--r-- | include/serd/serd.h | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/include/serd/serd.h b/include/serd/serd.h index 649217f3..dcc872ef 100644 --- a/include/serd/serd.h +++ b/include/serd/serd.h @@ -197,6 +197,36 @@ typedef struct { size_t len; ///< Length of chunk in bytes } SerdStringView; +#ifdef __cplusplus + +# define SERD_EMPTY_STRING(str) \ + SerdStringView { "", 0 } + +# define SERD_STATIC_STRING(str) \ + SerdStringView { (str), sizeof(str) - 1 } + +# define SERD_MEASURE_STRING(str) \ + SerdStringView { (str), (str) ? strlen(str) : 0 } + +# define SERD_STRING_VIEW(str, len) \ + SerdStringView { (str), (len) } + +#else + +# define SERD_EMPTY_STRING(str) \ + (SerdStringView) { "", 0 } + +# define SERD_STATIC_STRING(str) \ + (SerdStringView) { (str), sizeof(str) - 1 } + +# define SERD_MEASURE_STRING(str) \ + (SerdStringView) { (str), (str != NULL) ? strlen(str) : 0 } + +# define SERD_STRING_VIEW(str, len) \ + (SerdStringView) { (str), (len) } + +#endif + /// A mutable buffer in memory typedef struct { void* SERD_NULLABLE buf; ///< Buffer |