diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2015-08-13 06:18:32 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2015-08-13 06:18:32 -0700 |
commit | 48e0e179ca9579eca414804aa4f8e7ae8fb040bb (patch) | |
tree | bccbaf5cf1764989f394e866661c7ff114fa4318 /lib.c | |
parent | 0a2ef84a7a1c5e898c9fbf7c9e84a65d965212c6 (diff) | |
download | txr-48e0e179ca9579eca414804aa4f8e7ae8fb040bb.tar.gz txr-48e0e179ca9579eca414804aa4f8e7ae8fb040bb.tar.bz2 txr-48e0e179ca9579eca414804aa4f8e7ae8fb040bb.zip |
New display-width function.
* eval.c (eval_init): Register display-width intrinsic.
* lib.c (display_width): New function.
* lib.h (display_width): Declared.
* txr.1: Documented display-width.
Diffstat (limited to 'lib.c')
-rw-r--r-- | lib.c | 22 |
1 files changed, 22 insertions, 0 deletions
@@ -7211,6 +7211,28 @@ val tostringp(val obj) return get_string_from_stream(ss); } +val display_width(val obj) +{ + if (stringp(obj)) { + const wchar_t *s = c_str(obj); + cnum width = 0; + for (; *s; s++) { + if (iswcntrl(*s)) + continue; + width += 1 + wide_display_char_p(*s); + } + return num(width); + } else if (chrp(obj)) { + wchar_t ch = c_chr(obj); + if (iswcntrl(ch)) + return zero; + return num_fast(1 + wide_display_char_p(ch)); + } + + uw_throwf(type_error_s, lit("display-width: ~s isn't a character or string"), + obj, nao); +} + val time_sec(void) { struct timeval tv; |