Re: RFC: Small mod to fl_utf8len() to detect invalid single char UTF-8 bytes
Greg Ercolano
15:38 Aug 12
On 8/12/26 14:14,
'Albrecht Schlosser' via fltk.coredev wrote:
On 8/12/26 09:30, Greg
Ercolano wrote:
I should mention though; FWIW, codex initially
suggested rewriting the code to be as follows, as per RFC
3629:
int fl_utf8len(char c) { const unsigned char u =
(unsigned char)c; if (u <= 0x7f) return 1; if (u >= 0xc2 &&
u <= 0xdf) return 2; if (u >= 0xe0 &&
u <= 0xef) return 3; if (u >= 0xf0 &&
u <= 0xf4) return 4; return -1; }
int fl_utf8len1(char c) {
const int len = fl_utf8len(c);
return len < 0 ? 1 : len;
} [..]
+1 on this version of the code, for these reasons:
- clarity and maintainability
(fl_utf8len)
- correctness for UTF-8, according to RFC 3629
(fl_utf8len)
- no duplication of code in fl_utf8len1
[..]
Note: meanwhile I'm convinced that we should make this
kind of changes NOW, i.e. before we release FLTK 1.5.0 !
OK, great, I'll commit it today, as it would seriously help the
terminal tests.
We can always revert if other devs makes a compelling argument
to the contrary.
Comments are owned by the poster. All other content is copyright 1998-2026 by Bill Spitzak and others. This project is hosted by The FLTK Team. Please report site problems to 'erco@seriss.com'.