summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--NEWS6
-rw-r--r--sord/sord.h14
-rw-r--r--src/sord.c14
-rw-r--r--src/sord_test.c31
-rw-r--r--wscript2
5 files changed, 53 insertions, 14 deletions
diff --git a/NEWS b/NEWS
index 6d8e96d..b89f6fb 100644
--- a/NEWS
+++ b/NEWS
@@ -1,10 +1,12 @@
-sord (0.14.1) unstable;
+sord (0.15.1) unstable;
* Fix documentation generation
* Return error from sord_inserter_write_statement() if a node can not be written
(e.g. undefined prefix)
+ * Make sord_node_get_counted return byte count, and clarify documentation
+ * Add sord_node_get_string_measured to get both byte and character counts
- -- David Robillard <d@drobilla.net> Fri, 04 Dec 2015 21:23:36 -0500
+ -- David Robillard <d@drobilla.net> Tue, 15 Mar 2016 14:51:35 -0400
sord (0.14.0) stable;
diff --git a/sord/sord.h b/sord/sord.h
index dd671de..e93cff8 100644
--- a/sord/sord.h
+++ b/sord/sord.h
@@ -248,11 +248,21 @@ const uint8_t*
sord_node_get_string(const SordNode* node);
/**
- Return the string value of a node, and set `len` to its length.
+ Return the string value of a node, and set `bytes` to its length in bytes.
*/
SORD_API
const uint8_t*
-sord_node_get_string_counted(const SordNode* node, size_t* len);
+sord_node_get_string_counted(const SordNode* node, size_t* bytes);
+
+/**
+ Return the string value of a node, and set `bytes` to its length in bytes,
+ and `count` to its length in characters.
+*/
+SORD_API
+const uint8_t*
+sord_node_get_string_measured(const SordNode* node,
+ size_t* bytes,
+ size_t* chars);
/**
Return the language of a literal node (or NULL).
diff --git a/src/sord.c b/src/sord.c
index c6b2b38..fbc33f7 100644
--- a/src/sord.c
+++ b/src/sord.c
@@ -919,9 +919,19 @@ sord_node_get_string(const SordNode* node)
}
const uint8_t*
-sord_node_get_string_counted(const SordNode* node, size_t* len)
+sord_node_get_string_counted(const SordNode* node, size_t* bytes)
{
- *len = node->node.n_chars;
+ *bytes = node->node.n_bytes;
+ return node->node.buf;
+}
+
+const uint8_t*
+sord_node_get_string_measured(const SordNode* node,
+ size_t* bytes,
+ size_t* chars)
+{
+ *bytes = node->node.n_bytes;
+ *chars = node->node.n_chars;
return node->node.buf;
}
diff --git a/src/sord_test.c b/src/sord_test.c
index ea258b0..c6e6a5b 100644
--- a/src/sord_test.c
+++ b/src/sord_test.c
@@ -515,17 +515,34 @@ main(int argc, char** argv)
goto fail;
}
- size_t len;
- const uint8_t* str = sord_node_get_string_counted(lit_id2, &len);
+ if (sord_num_nodes(world) != initial_num_nodes) {
+ return test_fail("Num nodes %zu != %zu\n",
+ sord_num_nodes(world), initial_num_nodes);
+ }
+
+ const uint8_t ni_hao[] = { 0xE4, 0xBD, 0xA0, 0xE5, 0xA5, 0xBD };
+ SordNode* chello = sord_new_literal(world, NULL, ni_hao, "cmn");
+
+ // Test literal length
+ size_t n_bytes;
+ size_t n_chars;
+ const uint8_t* str = sord_node_get_string_counted(lit_id2, &n_bytes);
if (strcmp((const char*)str, "hello")) {
return test_fail("Literal node corrupt\n");
- } else if (len != strlen("hello")) {
- return test_fail("Literal length incorrect\n");
+ } else if (n_bytes != strlen("hello")) {
+ return test_fail("ASCII literal byte count incorrect\n");
}
- if (sord_num_nodes(world) != initial_num_nodes) {
- return test_fail("Num nodes %zu != %zu\n",
- sord_num_nodes(world), initial_num_nodes);
+ str = sord_node_get_string_measured(lit_id2, &n_bytes, &n_chars);
+ if (n_bytes != strlen("hello") || n_chars != strlen("hello")) {
+ return test_fail("ASCII literal measured length incorrect\n");
+ }
+
+ str = sord_node_get_string_measured(chello, &n_bytes, &n_chars);
+ if (n_bytes != 6) {
+ return test_fail("Multi-byte literal byte count incorrect\n");
+ } else if (n_chars != 2) {
+ return test_fail("Multi-byte literal character count incorrect\n");
}
// Check interning doesn't clash non-equivalent values
diff --git a/wscript b/wscript
index 36ef0f3..5fcd76e 100644
--- a/wscript
+++ b/wscript
@@ -11,7 +11,7 @@ import waflib.extras.autowaf as autowaf
# major increment <=> incompatible changes
# minor increment <=> compatible changes (additions)
# micro increment <=> no interface changes
-SORD_VERSION = '0.14.1'
+SORD_VERSION = '0.15.1'
SORD_MAJOR_VERSION = '0'
# Mandatory waf variables