Re: RFC: Small mod to fl_utf8len() to detect invalid single char UTF-8 bytes
Greg Ercolano
17:59 Aug 12
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;
} [..]
[..]
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.
I've opened up issue # 1576 for
this, and will associate the commit with that issue, so there can be
a chance for comments and digressions.
Due to the increased chances of invalid return values of -1, I
asked codex to check all of FLTK code to look for possible
mishandling of the -1 return from fl_utf8len(), and it did find at
least one case in Fl_Input_::expandpos(), so solving that and
whatever else can be connected to that issue.
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'.