summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--eval.c1
-rw-r--r--lib.c5
-rw-r--r--lib.h1
-rw-r--r--txr.118
4 files changed, 25 insertions, 0 deletions
diff --git a/eval.c b/eval.c
index 97e9c5ee..40e97ce9 100644
--- a/eval.c
+++ b/eval.c
@@ -6701,6 +6701,7 @@ void eval_init(void)
reg_fun(intern(lit("stringp"), user_package), func_n1(stringp));
reg_fun(intern(lit("lazy-stringp"), user_package), func_n1(lazy_stringp));
reg_fun(intern(lit("length-str"), user_package), func_n1(length_str));
+ reg_fun(intern(lit("coded-length"), user_package), func_n1(coded_length));
reg_fun(intern(lit("search-str"), user_package), func_n4o(search_str, 2));
reg_fun(intern(lit("search-str-tree"), user_package), func_n4o(search_str_tree, 2));
reg_fun(intern(lit("match-str"), user_package), func_n3o(match_str, 2));
diff --git a/lib.c b/lib.c
index f4cd1306..d5e8fec4 100644
--- a/lib.c
+++ b/lib.c
@@ -3648,6 +3648,11 @@ val length_str(val str)
}
}
+val coded_length(val str)
+{
+ return unum(utf8_to_buf(0, c_str(str), 0));
+}
+
const wchar_t *c_str(val obj)
{
switch (type(obj)) {
diff --git a/lib.h b/lib.h
index 76497d42..5be2c037 100644
--- a/lib.h
+++ b/lib.h
@@ -827,6 +827,7 @@ val string_extend(val str, val tail);
val stringp(val str);
val lazy_stringp(val str);
val length_str(val str);
+val coded_length(val str);
const wchar_t *c_str(val str);
val search_str(val haystack, val needle, val start_num, val from_end);
val search_str_tree(val haystack, val tree, val start_num, val from_end);
diff --git a/txr.1 b/txr.1
index 82533914..6feee618 100644
--- a/txr.1
+++ b/txr.1
@@ -22293,6 +22293,24 @@ function returns the length
.meta string
in characters. The argument must be a string.
+.coNP Function @ coded-length
+.synb
+.mets (coded-length << string )
+.syne
+.desc
+The
+.code coded-length
+function returns the number of bytes required to encode
+.meta string
+in UTF-8.
+
+The argument must be a character string.
+
+If the string contains only characters in the ASCII range U+0001 to U+007F
+range, then the value returned shall be the same as that returned by the
+.code length-str
+function.
+
.coNP Function @ search-str
.synb
.mets (search-str < haystack < needle >> [ start <> [ from-end ]])