| 3057 | } |
| 3058 | |
| 3059 | static ssize_t |
| 3060 | xo_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 |
| 3096 | static inline const char * |
no test coverage detected