aboutsummaryrefslogtreecommitdiffstats
path: root/src/serd_internal.h
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2011-01-24 23:27:15 +0000
committerDavid Robillard <d@drobilla.net>2011-01-24 23:27:15 +0000
commite4daedb841acef2a4839a33e7c17ee8ea5fa6913 (patch)
treed24a5a955c3be4b5f2cc938ea5c090c9e80de06c /src/serd_internal.h
parent6903e56e2443a1a5b023d688cb7fd54e3580316d (diff)
downloadserd-e4daedb841acef2a4839a33e7c17ee8ea5fa6913.tar.gz
serd-e4daedb841acef2a4839a33e7c17ee8ea5fa6913.tar.bz2
serd-e4daedb841acef2a4839a33e7c17ee8ea5fa6913.zip
Remove SerdString cruft.
git-svn-id: http://svn.drobilla.net/serd/trunk@54 490d8e77-9747-427b-9fa3-0b8f29cee8a0
Diffstat (limited to 'src/serd_internal.h')
-rw-r--r--src/serd_internal.h43
1 files changed, 21 insertions, 22 deletions
diff --git a/src/serd_internal.h b/src/serd_internal.h
index 1b601e12..7adf1567 100644
--- a/src/serd_internal.h
+++ b/src/serd_internal.h
@@ -99,27 +99,26 @@ is_digit(const uint8_t c)
return in_range(c, '0', '9');
}
-/** Measured UTF-8 string. */
-typedef struct {
- size_t n_bytes; ///< Size in bytes including trailing null byte
- size_t n_chars; ///< Length in characters
- uint8_t buf[]; ///< Buffer
-} SerdString;
-
-#if 0
-/** Create a new UTF-8 string from @a utf8. */
-SerdString*
-serd_string_new(const uint8_t* utf8);
-
-/** Copy @a string. */
-SerdString*
-serd_string_copy(const SerdString* str);
-#endif
-
-void
-serd_string_free(SerdString* str);
-
-SerdString*
-serd_string_new_from_node(const SerdNode* node);
+/** UTF-8 strlen.
+ * @return Lengh of @a utf8 in characters.
+ * @param utf8 A null-terminated UTF-8 string.
+ * @param out_n_bytes (Output) Set to the size of @a utf8 in bytes.
+ */
+static inline size_t
+serd_strlen(const uint8_t* utf8, size_t* out_n_bytes)
+{
+ size_t n_chars = 0;
+ size_t i = 0;
+ for (; utf8[i]; ++i) {
+ if ((utf8[i] & 0xC0) != 0x80) {
+ // Does not start with `10', start of a new character
+ ++n_chars;
+ }
+ }
+ if (out_n_bytes) {
+ *out_n_bytes = i + 1;
+ }
+ return n_chars;
+}
#endif // SERD_INTERNAL_H