/* See how many bytes to copy from string so its at most maxlen bytes
* long and maxwid columns wide */
-int mutt_wstr_trunc (const char *src, size_t maxlen, size_t maxwid, size_t *width)
+size_t mutt_wstr_trunc (const char *src, size_t maxlen, size_t maxwid, size_t *width)
{
wchar_t wc;
- int w = 0, l = 0, cl;
- int cw, n;
+ size_t n, w = 0, l = 0, cl;
+ int cw;
mbstate_t mbstate;
if (!src)
memset (&mbstate, 0, sizeof (mbstate));
for (w = 0; n && (cl = mbrtowc (&wc, src, n, &mbstate)); src += cl, n -= cl)
{
- if (cl == (size_t)(-1) || cl == (size_t)(-2)) {
- cw = cl = 1;
- memset(&mbstate, 0, sizeof (mbstate));
- }
- else
+ if (cl == (size_t)(-1) || cl == (size_t)(-2))
{
- cw = wcwidth (wc);
- /* hack because M_TREE symbols aren't turned into characters
- * until rendered by print_enriched_string (#3364) */
- if (cw < 0 && cl == 1 && src[0] && src[0] < M_TREE_MAX)
- cw = 1;
- else if (cw < 0)
- cw = 0; /* unprintable wchar */
+ if (cl == (size_t)(-1))
+ memset (&mbstate, 0, sizeof (mbstate));
+ cl = (cl == (size_t)(-1)) ? 1 : n;
+ wc = replacement_char ();
}
+ cw = wcwidth (wc);
+ /* hack because M_TREE symbols aren't turned into characters
+ * until rendered by print_enriched_string (#3364) */
+ if (cw < 0 && cl == 1 && src[0] && src[0] < M_TREE_MAX)
+ cw = 1;
+ else if (cw < 0)
+ cw = 0; /* unprintable wchar */
if (cl + l > maxlen || cw + w > maxwid)
break;
l += cl;
int mutt_smtp_send (const ADDRESS *, const ADDRESS *, const ADDRESS *,
const ADDRESS *, const char *, int);
#endif
-int mutt_wstr_trunc (const char *, size_t, size_t, size_t *);
+size_t mutt_wstr_trunc (const char *, size_t, size_t, size_t *);
int mutt_charlen (const char *s, int *);
int mutt_strwidth (const char *);
int mutt_compose_menu (HEADER *, char *, size_t, HEADER *, int);