FLTK logo

Re: [fltk.coredev] RFC/vote: A fl_utf8 function for detecting continuation bytes

FLTK matrix user chat room
(using Element browser app)   FLTK gitter user chat room   GitHub FLTK Project   FLTK News RSS Feed  
  FLTK Library      Forums      Links      Apps     Login 
[  All Forums  |  Back to fltk.coredev  ]
 
[ Previous Message ] [ New Message | Reply ] [ Next Message ]

Re: RFC/vote: A fl_utf8 function for detecting continuation bytes Greg Ercolano 16:43 Jul 20  
 

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:

  • First byte is the "initial octet"
  • The continuation bytes are called "subsequent octets" or "following octets"
    Apparently the UTF-8 spec was written with the Unicode standard in mind, and that refers to these bytes as:
  • "leading byte"
  • "trailing bytes"

    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-tail

In 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-4 UTF8-tail
RFC 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 exact UTF8-tail constraints? [..]


    So I followed up to google/gemini with this reply to its question at the end of the above:
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) (or is_trail_byte): Returns true if the byte is in the middle of a sequence (0x80 to 0xBF).
  • is_leading_byte(b) (or is_lead_byte): Returns true if the byte can start a sequence (0x00 to 0x7F, or 0xC2 to 0xF4).

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 the UTF8-tail definition (%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 are 10. You can test this instantly with a bitwise mask:
// Evaluates to true only for middle/subsequent bytes (0x80 to 0xBF)
bool is_trailing_byte(uint8_t byte) {
    return (byte & 0xC0) == 0x80;                // <-- SAME CODE WE USE IN FLTK -ERCO
}

// Evaluates to true if the pointer is at a safe splitting/starting point
bool is_char_boundary(uint8_t byte) {
    return !is_trailing_byte(byte);
}
[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()


 



--
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+unsubscribe@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/fltkcoredev/c97ff5ed-79e6-4fc5-a971-2e360752f334%40seriss.com.
[ Direct Link to Message ]
 
     
[ Previous Message ] [ New Message | Reply ] [ Next Message ]
 
 

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'.