inline bool fl_utf8_is_aligned(char c) {The above code pattern of testing (byte & 0xc0) against 0x80 is repeated throughout fltk. It seems like this should be an actual utf8 function, to avoid having utf8 magic numbers scattered everywhere:
// Byte 1 Byte 2 Byte 3 ..etc..
// ASCII: 0xxxxxxx
// UTF8(2): 110xxxxx 10xxxxxx
// UTF8(3): 1110xxxx 10xxxxxx 10xxxxxx
// UTF8(4): 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx
// UTF8(5): 111110xx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx
// UTF8(6): 1111110x 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx
// \______/ \______________________________________________/
// Start byte Continuation bytes
// (c & 0xc0) == 0x80
return ((c & 0xc0) == 0x80);
}
$ git grep '0xc0.*=.*0x80'Seeking comments/votes:
FL/Fl_Terminal.H: // (c & 0xc0) == 0x80
FL/Fl_Terminal.H: return ((c & 0xc0) == 0x80);
src/Fl_File_Chooser2.cxx: if (ptr[1] && (ptr[1]&0xc0)!=0x80) break;
src/Fl_File_Chooser2.cxx: if (ptr[1] && (ptr[1]&0xc0)!=0x80) break;
src/Fl_File_Chooser2.cxx: if (ptr[1] && (ptr[1]&0xc0)!=0x80) break;
src/Fl_File_Chooser2.cxx: if (ptr[1] && (ptr[1]&0xc0)!=0x80) break;
src/Fl_File_Chooser2.cxx: if (ptr[1] && (ptr[1]&0xc0)!=0x80) break;
src/Fl_File_Chooser2.cxx: if (ptr[1] && (ptr[1]&0xc0)!=0x80) break;
src/Fl_Text_Buffer.cxx: while ( (c&0xc0) == 0x80) {
src/fl_utf8.cxx: if ( (end && p+1 >= end) || (p[1]&0xc0) != 0x80) goto FAIL;
src/fl_utf8.cxx: if ( (end && p+2 >= end) || (p[2]&0xc0) != 0x80) goto FAIL;
src/fl_utf8.cxx: if ( (end && p+3 >= end) || (p[2]&0xc0) != 0x80 || (p[3]&0xc0) != 0x80) goto FAIL;
src/fl_utf8.cxx: if ((*p&0xc0) != 0x80) return p;
src/fl_utf8.cxx: if ((*p&0xc0) != 0x80) return p;
Seeking comments/votes:
> Does it make sense to add this as an fl_utf8() inline function, and refit existing code to use it (+1/-1/0)
> Suggesting 'is_aligned' or 'is_align' or 'is_continuation' as the fl_utf8_xxx suffix, but open to other suggestions
--
You received this message because you are subscribed to the Google Groups "fltk.coredev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to fltkcoredev...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/fltkcoredev/40a63ee1-4842-41be-b7ec-c2bba74784e4n%40googlegroups.com.
On 7/17/26 09:49, Bill Spitzak wrote:
I have no idea why you think "align" is a descriptive word for this.
/*
Align an index to the current UTF-8 boundary.
*/
int Fl_Text_Buffer::utf8_align(int pos) const
{
char c = byte_at(pos);
while ( (c&0xc0) == 0x80) {
pos--;
c = byte_at(pos);
}
return pos;
}
But yeah, "align" is not as good as "continuation" (the
actual utf8 name for detecting the bit pattern).
The only nice thing about "align" is it's short,
as short names are something I've always liked about
forms/xforms/fltk function/method names.
I would use either is_continuation() or !is_leading()
Ya, is_continuation() is what I went with in
Fl_Terminal, so a move to the fl_utf8 suite would mean fl_utf8_is_continuation(),
whose name is longer than the actual in-line code
`(c&0xc0)==0x80`, so I'm always trying to find something
shorter.
Le jeudi 16 juillet 2026 à 19:21:06 UTC+2, er...@seriss.com a écrit :
Seeking comments/votes:
> Does it make sense to add this as an fl_utf8() inline function, and refit existing code to use it (+1/-1/0)
Yes it makes sense. +1
> Suggesting 'is_aligned' or 'is_align' or 'is_continuation' as the fl_utf8_xxx suffix, but open to other suggestions
I would support fl_utf8_is_continuation_byte().
I wrote utf8_align 20 years ago, knowing very little about Unicode. The method is used to ensure that the text buffer cursor is at the start of a utf8 sequence and was introduced when text buffer was extended to support utf-8.
The standard uses "self-synchronizing", "lead byte", and "continuation byte", so our functions should reflect that terminology. As for Fl_Text_Buffer::utf8_align(), code should instead use the new correctly named functions, and this method could be marked deprecated.
+1 for completing utf-8 support and using the right terminology.
The question for a good name of this new function remains. I propose:
(1) fl_utf8_is_continuation()
(2) fl_utf8_is_cont()
(3) fl_utf8_continuation()
(4) fl_utf8_cont()
(5) none of these, I propose: ...
+1 for (2) only because:
On 7/20/26 09:13, Greg Ercolano wrote:
[..]
I did some further research in the "continuation" terminology, and was surprised to find: while the wikipedia page uses it, the RFCs for the UTF-8 spec and Unicode specs does not. I went down that rabbit hole, and I'll follow up separately in this thread with all that noise, but in the end I think "continuation" is fine.
So here's my adventure down the rabbit hole regarding
"continuation" terminology.
As I said, after my return from this excursion, I'm left
thinking "continuation" is still OK; see green text below.
* * *
Regarding "continuation" terminology, I put on my pedantic hat
to dig down into the actual RFC for UTF-8 to verify
the terminology the spec uses, since wikipedia is not really
authoritative.
So I looked up the RFC that defines UTF-8, specifically RFC 3629,
there is no mention of
this "continuation" terminology.
They seem instead to refer to the sequence this way, e.g.
Section 3:
So I asked AI (google AI/Gemini) a few questions:
I'm trying to determine if there's specific terminology for the bytes in the middle of a UTF-8 sequence. The wikipedia page calls them "continuation" bytes, but the RFCs do not mention this.
..and it replied:
You are completely right to notice the vocabulary difference. [Gemini, lol, you are such a suck-up! -erco] While Wikipedia relies on informal industry jargon like "continuation bytes", formal specifications use much stricter structural terminology. [1]The official terminology for those middle or subsequent bytes depends on which standard or section you look at:1. The Official ABNF Term:
UTF8-tailIn Section 4 of RFC 3629, the Internet Engineering Task Force (IETF) defines the formal syntax of UTF-8 using Augmented Backus-Naur Form (ABNF). [2]
- The specification explicitly brands these bytes as
UTF8-tail.- The ABNF rule is normatively defined as:
UTF8-tail = %x80-BF. [2, 3]2. The Textual Description Term: "Subsequent Octets"
In the narrative text of RFC 3629 (Section 3), the author does not use the word "byte" (preferring the networking standard term "octet"). [4, 5]
- The first byte is explicitly called the "initial octet".
- Any bytes following it are formally referred to as "subsequent octet(s)" or "following octet(s)". [4]
3. The Unicode Standard Term: "Trailing Bytes"
Because RFC 3629 is explicitly written to align with the Unicode Standard, it is also helpful to check their terminology. The Unicode Consortium formally refers to the initial byte as the leading byte and all subsequent bytes in the sequence as trailing bytes. [1, 4, 6, 7]Summary Comparison
Source First Byte Terminology Following/Middle Bytes Terminology RFC 3629 (ABNF Syntax) UTF8-1/UTF8-2/UTF8-3/UTF8-4UTF8-tailRFC 3629 (Text Narrative) Initial octet Subsequent octet(s) / Following octet(s) The Unicode Standard Leading byte Trailing byte Wikipedia / Industry Jargon Leading byte Continuation byte Are you writing a parser or an ABNF schema where you need to implement these exactUTF8-tailconstraints? [..]
I'm writing a utf-8 parser, in particular trying to name a function that tests if it's in the middle of a utf-8 sequence, or has reached the beginning or end. Can you suggest a proper name for a function that tests bytes (octets) in a utf-8 string?
..and it replied:
Since you are writing a parser, naming your functions after the official Unicode Standard or RFC 3629 ABNF terms will make your code immediately understandable to other systems engineers.Here are the best function names categorized by the specific design pattern you are using, alongside names for your beginning/end checks.Option 1: The "Trailing" Pattern (Recommended)
This maps directly to the Unicode Standard. It is the most common industry convention for systems-level parsers (like those in Rust, Go, or C++).
is_trailing_byte(b)(oris_trail_byte): Returns true if the byte is in the middle of a sequence (0x80to0xBF).is_leading_byte(b)(oris_lead_byte): Returns true if the byte can start a sequence (0x00to0x7F, or0xC2to0xF4).Option 2: The "Tail" Pattern (RFC 3629 ABNF Alignment)
If your parser strictly follows the formal IETF grammar nomenclature, name it after the exact ABNF production rule.
is_utf8_tail(b): Returns true if the byte matches theUTF8-taildefinition (%x80-BF).Option 3: The Boundary Check Pattern
If your function is not just inspecting a single byte, but checking an iterator or index pointer to see if it is currently sitting safely on a character boundary (the beginning or end of a full sequence):
is_char_boundary(index): Returns true if the index points to a valid starting byte or the end of the string.is_inside_sequence(index): Returns true if the index is currently sitting on a middle/subsequent byte.
Implementation Reference (Hex Ranges)
[..hex table snipped..]
In code, a byte is a middle/trailing byte if and only if its top two bits are10. You can test this instantly with a bitwise mask:[So Gemini is suggesting "is_trailing_byte()", or I guess we could abbreviate "is_trail()", but I think that's not as clear as "continuation" -erco]
For competeness, I switched to using Codex/ChatGPT,
and asked it the same two questions..
Here's that conversation, which seemed to prefer the
"continuation" terminology:
> I'm trying to determine if there's specific terminology for the bytes in the middle of a UTF-8 sequence. The wikipedia page calls
them "continuation" bytes, but the RFCs do not mention this.
• I’ll check the primary specs rather than relying on memory, since UTF-8 terminology varies a bit between Unicode, RFC 3629, and secondary summaries.
• Searched the web for Unicode Standard UTF-8 continuation byte terminology
• Searched the web for https://www.rfc-editor.org/info/rfc3629/
• Searched the web for 'continuation' in https://www.unicode.org/versions/Unicode17.0.0/core-spec/chapter-3/
• Searched the web for WHATWG Encoding UTF-8 continuation byte definition
• Yes. The common term is continuation byte, and it is widely understood for UTF-8 bytes of the form 10xxxxxx, generally 0x80..0xBF.
If you want terminology closer to primary standards:
- The Unicode Standard uses leading byte and trailing byte terminology. Chapter 2 says UTF-8 has a first/leading element and
subsequent/trailing elements, and Chapter 3 refers to “trailing byte range” in the well-formed UTF-8 table. Sources: Unicode Chapter
2, §2.5.3 and Unicode Chapter 3, §3.9.3.
- RFC 3629 does not appear to use “continuation byte”. Its ABNF calls them UTF8-tail, defined as %x80-BF, and the prose calls them the
“following octet(s)”. Source: RFC 3629 §3-4.
So for spec-aligned wording, use UTF-8 trailing byte or UTF-8 tail byte. For general programming/documentation wording, UTF-8
continuation byte is normal and clear. [Because of this, I think we're OK with "continuation" - erco]
One nuance: every UTF-8 continuation/trailing byte has the bit shape 10xxxxxx, but not every syntactically valid second byte can be
described only as 0x80..0xBF in context. Well-formed UTF-8 has extra restrictions for some first bytes, e.g. E0 A0..BF, F0 90..BF, F4
80..8F.
────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
› I'm writing a utf-8 parser, in particular trying to name a function that tests if it's in the middle of a utf-8 sequence. Can you
suggest a proper name for such a function that tests bytes (octets) in a utf-8 string?
• Use a name based on continuation or trail bytes.
Good options:
is_utf8_continuation_byte(unsigned char c)
or, if you want Unicode/ICU-style terminology:
is_utf8_trail_byte(unsigned char c)
I’d pick is_utf8_continuation_byte() for readability unless the surrounding code already uses “lead/trail” terminology. [ <-- So here again, chatgpt seems OK with "continuation" and even prefers it. And I'm fine leaving out the "byte" suffix, which seems unnecessary, due to the function prototype. -erco]
The test itself is usually:
return (c & 0xC0) == 0x80; /* 10xxxxxx */
If the function means “this byte cannot begin a UTF-8 character and must continue one,” then is_utf8_continuation_byte is exact. If it
means “we are currently after a lead byte and still expecting more bytes,” name the parser-state function differently, e.g.:
utf8_in_sequence()
utf8_expect_continuation()
utf8_need_trail_byte()
On 7/20/26 10:33, 'melcher....@googlemail.com' via fltk.coredev wrote:
That was ssurprsingly entertaining for me ;-D
So how about (which could be confused with the start and end of a string):`fl_utf8_is_head()` and `fl_utf8_is_tail()`or the long version which makes the job very clear`fl_utf8_is_leading_byte()` and `fl_utf8_is_trailing_byte()` or `fl_utf8_is_continuation_byte()`
--
You received this message because you are subscribed to the Google Groups "fltk.coredev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to fltkcoredev...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/fltkcoredev/4331f9e1-6329-41ba-9d83-4ef1b789f136%40seriss.com.