From ce981fefe0c4d4f9c871b574a92eec06e3149e3e Mon Sep 17 00:00:00 2001 From: David Robillard Date: Tue, 15 Mar 2016 14:52:47 -0400 Subject: Make sord_node_get_counted return byte count Also clarify formerly ambiguous documentation, and add sord_node_get_string_measured to get both byte and character counts. Technically, this breaks behaviour, but most (if not all) existing code that uses this function was actually expecting a byte count. This is unsurprising since a UTF-8 character count is almost always useless. This approach causes less problems in reality, since it fixes broken behaviour in the wild without requiring any changes in user code. --- src/sord.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'src/sord.c') 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; } -- cgit v1.2.1