Introduction
Introduction Statistics Contact Development Disclaimer Help
mbsprint: fix character encoding errors handling - sacc - sacc - sacc(omys), si…
git clone git://git.codemadness.org/sacc
Log
Files
Refs
LICENSE
---
commit cd386e712b7587740115c0fb0815a43052758ae2
parent 0a5b9f60e25411cf2fbd6688e8be5a7326f2b28d
Author: Quentin Rameau <[email protected]>
Date: Sun, 24 Jan 2021 14:53:06 +0100
mbsprint: fix character encoding errors handling
We were not advancing the input string correctly in case of error.
Now we do that and print in a slightly more unified way.
Send remarks to [email protected]
Diffstat:
M sacc.c | 22 +++++++++++++---------
1 file changed, 13 insertions(+), 9 deletions(-)
---
diff --git a/sacc.c b/sacc.c
@@ -103,7 +103,8 @@ mbsprint(const char *s, size_t len)
{
wchar_t wc;
size_t col = 0, i, slen;
- int rl, w;
+ const char *p;
+ int rl, pl, w;
if (!len)
return col;
@@ -112,20 +113,23 @@ mbsprint(const char *s, size_t len)
for (i = 0; i < slen; i += rl) {
rl = mbtowc(&wc, s + i, slen - i < 4 ? slen - i : 4);
if (rl == -1) {
- mbtowc(NULL, NULL, 0); /* reset state */
- fputs("\xef\xbf\xbd", stdout); /* replacement characte…
- col++;
- rl = 1;
- continue;
+ /* reset state */
+ mbtowc(NULL, NULL, 0);
+ p = "\xef\xbf\xbd"; /* replacement character */
+ pl = 3;
+ rl = w = 1;
+ } else {
+ if ((w = wcwidth(wc)) == -1)
+ continue;
+ pl = rl;
+ p = s + i;
}
- if ((w = wcwidth(wc)) == -1)
- continue;
if (col + w > len || (col + w == len && s[i + rl])) {
fputs("\xe2\x80\xa6", stdout); /* ellipsis */
col++;
break;
}
- fwrite(s + i, 1, rl, stdout);
+ fwrite(p, 1, pl, stdout);
col += w;
}
return col;
You are viewing proxied material from codemadness.org. The copyright of proxied material belongs to its original authors. Any comments or complaints in relation to proxied material should be directed to the original authors of the content concerned. Please see the disclaimer for more details.