aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2021-02-24 15:44:27 -0500
committerDavid Robillard <d@drobilla.net>2021-03-07 15:32:23 -0500
commit3ec66799f0b9be2f83251721f91a8b913abd29ec (patch)
treee45c3959705137c2e29aa0ef9603a5be6ad47bdd /include
parent37acc7772335e5a0987531fb42f0dd9e529b3b4d (diff)
downloadserd-3ec66799f0b9be2f83251721f91a8b913abd29ec.tar.gz
serd-3ec66799f0b9be2f83251721f91a8b913abd29ec.tar.bz2
serd-3ec66799f0b9be2f83251721f91a8b913abd29ec.zip
Add string view construction macros
Diffstat (limited to 'include')
-rw-r--r--include/serd/serd.h30
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