addch (' ');
}
+/*
+ * returns the number of bytes the first (multibyte) character
+ * of input consumes:
+ * < 0 ... conversion error
+ * = 0 ... end of input
+ * > 0 ... length (bytes)
+ */
+int mutt_charlen (const char *s, int *width)
+{
+ wchar_t wc;
+ mbstate_t mbstate;
+ size_t k, n;
+
+ if (!s || !*s)
+ return 0;
+
+ n = mutt_strlen (s);
+ memset (&mbstate, 0, sizeof (mbstate));
+ k = mbrtowc (&wc, s, n, &mbstate);
+ if (width)
+ *width = wcwidth (wc);
+ return (k == (size_t)(-1) || k == (size_t)(-2)) ? -1 : k;
+}
+
/*
* mutt_strwidth is like mutt_strlen except that it returns the width
* refering to the number of characters cells.
}
else
{
- *wptr++ = *src++;
- wlen++;
- col++;
+ int tmp, w;
+ /* in case of error, simply copy byte */
+ if ((tmp = mutt_charlen (src, &w)) < 0)
+ tmp = 1;
+ if (tmp > 0 && wlen + tmp < destlen)
+ {
+ memcpy (wptr, src, tmp);
+ wptr += tmp;
+ src += tmp;
+ wlen += tmp;
+ col += w;
+ }
+ else
+ {
+ src += destlen - wlen;
+ wlen = destlen;
+ }
}
}
*wptr = 0;
int mutt_smtp_send (const ADDRESS *, const ADDRESS *, const ADDRESS *,
const ADDRESS *, const char *, int);
#endif
+int mutt_charlen (const char *s, int *);
int mutt_strwidth (const char *);
int mutt_compose_menu (HEADER *, char *, size_t, HEADER *);
int mutt_thread_set_flag (HEADER *, int, int, int);