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 "'Albrecht Schlosser' via fltk.coredev" 12:38 Jul 20  
 
Title: Re: [fltk.coredev] RFC/vote: A fl_utf8 function for detecting continuation bytes
On 7/20/26 12:01 'Melcher Matthias' via fltk.coredev wrote:
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.

OK, this explains the naming: the text position (index) should be aligned to a character boundary. This method is not documented, but according to the code it does something similar to fl_utf8back() inside the text buffer.

Note that we have fl_utf8back() and fl_utf8fwd() but these functions operate on plain character arrays (strings). 

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.

I agree that it should use the correct function (internally). But it's a very special case because it operates on Fl_Text_Buffer. No matter how we call it, it should be documented with doxygen comments, since it's a public method. I'm not sure whether we want (need) to create another method and deprecate the old one. Proper documentation should IMHO suffice.

+1 for completing utf-8 support and using the right terminology.

Summary: we have three types of bytes in a valid UTF-8 sequence: (1) ASCII, (2) UTF-8 lead bytes, and (3) UTF-8 continuation bytes. If a byte is neither a lead nor a continuation byte, then it's pure (7-bit) ASCII.

IMHO it would be enough to detect continuation bytes (3). If a byte is not a continuation byte, it is a valid start of a UTF-8 character, either ASCII (1) or a lead byte (2) -- or are there invalid bytes that can't appear in a UTF-8 sequence?

My personal conclusion is that we should add fl_utf8_[is_]cont[inuation]() to detect continuation bytes as Greg suggested, and that's enough. And of course document Fl_Text_Buffer::utf8_align() properly.

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

If you agree, please vote for one of these (1-5).

My vote is (2).

Please feel free to suggest other useful functions like fl_utf8_lead() if you think these are useful (I don't).

--
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/29d4a314-ce6b-49f8-98a9-4a93d5120794%40aljus.de.
[ 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'.