aboutsummaryrefslogtreecommitdiffstats
path: root/src/node.c
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2011-05-11 22:27:18 +0000
committerDavid Robillard <d@drobilla.net>2011-05-11 22:27:18 +0000
commit926f29ed81a34a50c9221a2d562119db84a136cb (patch)
tree382406a7c0bb3ba60f364339cffec431b9e66c96 /src/node.c
parentefd2a2ecb17a8c633f634c2cf38fb8be48db9af5 (diff)
downloadserd-926f29ed81a34a50c9221a2d562119db84a136cb.tar.gz
serd-926f29ed81a34a50c9221a2d562119db84a136cb.tar.bz2
serd-926f29ed81a34a50c9221a2d562119db84a136cb.zip
Create SerdNodeFlags typedef for flags.
Expose serd_strlen. Make serd_node_copy tolerate a NULL parameter. git-svn-id: http://svn.drobilla.net/serd/trunk@168 490d8e77-9747-427b-9fa3-0b8f29cee8a0
Diffstat (limited to 'src/node.c')
-rw-r--r--src/node.c38
1 files changed, 33 insertions, 5 deletions
diff --git a/src/node.c b/src/node.c
index edd0db86..e4bb87cf 100644
--- a/src/node.c
+++ b/src/node.c
@@ -20,6 +20,32 @@
#include "serd_internal.h"
SERD_API
+size_t
+serd_strlen(const uint8_t* str, size_t* n_bytes, SerdNodeFlags* flags)
+{
+ size_t n_chars = 0;
+ size_t i = 0;
+ for (; str[i]; ++i) {
+ if ((str[i] & 0xC0) != 0x80) {
+ // Does not start with `10', start of a new character
+ ++n_chars;
+ switch (str[i]) {
+ case '\r':
+ case '\n':
+ *flags |= SERD_HAS_NEWLINE;
+ break;
+ case '"':
+ *flags |= SERD_HAS_QUOTE;
+ }
+ }
+ }
+ if (n_bytes) {
+ *n_bytes = i + 1;
+ }
+ return n_chars;
+}
+
+SERD_API
SerdNode
serd_node_from_string(SerdType type, const uint8_t* buf)
{
@@ -34,12 +60,14 @@ SERD_API
SerdNode
serd_node_copy(const SerdNode* node)
{
- SerdNode copy = *node;
- if (node->buf) {
- uint8_t* buf = malloc(copy.n_bytes);
- memcpy(buf, node->buf, copy.n_bytes);
- copy.buf = buf;
+ if (!node || !node->buf) {
+ return SERD_NODE_NULL;
}
+
+ SerdNode copy = *node;
+ uint8_t* buf = malloc(copy.n_bytes);
+ memcpy(buf, node->buf, copy.n_bytes);
+ copy.buf = buf;
return copy;
}