utf8bytelength: count UTF8 string bytelength

[Builtin name changed, and it only works on string inputs. -Nico]
This commit is contained in:
Joel Nothman authored and Nicolas Williams committed 2015-09-13 01:01:24 -05:00
1 parent 63dd033da7
commit 83e8ec587f
3 files changed
+28

No files matched your search

+7
View File
@@ -367,6 +367,12 @@ static jv f_tostring(jq_state *jq, jv input) {
}
}
static jv f_utf8bytelength(jq_state *jq, jv input) {
if (jv_get_kind(input) != JV_KIND_STRING)
return type_error(input, "only strings have UTF-8 byte length");
return jv_number(jv_string_length_bytes(input));
}
#define CHARS_ALPHANUM "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"
static jv escape_string(jv input, const char* escapings) {
@@ -1273,6 +1279,7 @@ static const struct cfunction function_list[] = {
{(cfunction_ptr)f_greatereq, "_greatereq", 3},
{(cfunction_ptr)f_contains, "contains", 2},
{(cfunction_ptr)f_length, "length", 1},
{(cfunction_ptr)f_utf8bytelength, "utf8bytelength", 1},
{(cfunction_ptr)f_type, "type", 1},
{(cfunction_ptr)f_isinfinite, "isinfinite", 1},
{(cfunction_ptr)f_isnan, "isnan", 1},