aboutsummaryrefslogtreecommitdiffstats
path: root/include/serd/string.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/serd/string.h')
-rw-r--r--include/serd/string.h63
1 files changed, 63 insertions, 0 deletions
diff --git a/include/serd/string.h b/include/serd/string.h
new file mode 100644
index 00000000..373dfdf0
--- /dev/null
+++ b/include/serd/string.h
@@ -0,0 +1,63 @@
+// Copyright 2011-2022 David Robillard <d@drobilla.net>
+// SPDX-License-Identifier: ISC
+
+#ifndef SERD_STRING_H
+#define SERD_STRING_H
+
+#include "serd/attributes.h"
+#include "serd/node.h"
+
+#include <stddef.h>
+
+SERD_BEGIN_DECLS
+
+/**
+ @defgroup serd_string String Utilities
+ @ingroup serd_utilities
+ @{
+*/
+
+/**
+ Measure a UTF-8 string.
+
+ @return Length of `str` in bytes.
+ @param str A null-terminated UTF-8 string.
+ @param flags (Output) Set to the applicable flags.
+*/
+SERD_API size_t
+serd_strlen(const char* SERD_NONNULL str, SerdNodeFlags* SERD_NULLABLE flags);
+
+/**
+ Parse a string to a double.
+
+ The API of this function is identical to the standard C strtod function,
+ except this function is locale-independent and always matches the lexical
+ format used in the Turtle grammar (the decimal point is always ".").
+*/
+SERD_API double
+serd_strtod(const char* SERD_NONNULL str,
+ char* SERD_NONNULL* SERD_NULLABLE endptr);
+
+/**
+ Decode a base64 string.
+
+ This function can be used to deserialise a blob node created with
+ serd_node_new_blob().
+
+ @param str Base64 string to decode.
+ @param len The length of `str`.
+ @param size Set to the size of the returned blob in bytes.
+ @return A newly allocated blob which must be freed with serd_free().
+*/
+SERD_API void* SERD_ALLOCATED
+serd_base64_decode(const char* SERD_NONNULL str,
+ size_t len,
+ size_t* SERD_NONNULL size);
+
+/**
+ @}
+*/
+
+SERD_END_DECLS
+
+#endif // SERD_STRING_H