MCPcopy Create free account
hub / github.com/F-Stack/f-stack / xo_count_utf8_cols

Function xo_count_utf8_cols

tools/libxo/libxo/libxo.c:3059–3093  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3057}
3058
3059static ssize_t
3060xo_count_utf8_cols (const char *str, ssize_t len)
3061{
3062 ssize_t tlen;
3063 wchar_t wc;
3064 ssize_t cols = 0;
3065 const char *ep = str + len;
3066
3067 while (str < ep) {
3068 tlen = xo_utf8_to_wc_len(str);
3069 if (tlen < 0) /* Broken input is very bad */
3070 return cols;
3071
3072 wc = xo_utf8_char(str, tlen);
3073 if (wc == (wchar_t) -1)
3074 return cols;
3075
3076 /* We only print printable characters */
3077 if (iswprint((wint_t) wc)) {
3078 /*
3079 * Find the width-in-columns of this character, which must be done
3080 * in wide characters, since we lack a mbswidth() function.
3081 */
3082 ssize_t width = xo_wcwidth(wc);
3083 if (width < 0)
3084 width = iswcntrl(wc) ? 0 : 1;
3085
3086 cols += width;
3087 }
3088
3089 str += tlen;
3090 }
3091
3092 return cols;
3093}
3094
3095#ifdef HAVE_GETTEXT
3096static inline const char *

Callers 1

xo_format_gettextFunction · 0.85

Calls 3

xo_utf8_to_wc_lenFunction · 0.85
xo_utf8_charFunction · 0.85
xo_wcwidthFunction · 0.85

Tested by

no test coverage detected