Re: Getting the ASCII code of a Unicode multibyte character
Jean Lalonde <[email protected]> Sat, 25 Jan 2025 15:14:22 -0800 (PST)
| Newsgroups | gmane.comp.lib.scintilla.devel |
|---|---|
| Message-ID | <[email protected]> |
> Strictly speaking, ASCII is a 7-bit encoding. The equivalent here is the
Unicode code point value.
This is true. The function could be renamed to be more accurate but, for
now, here, I'll keep the actual name.
> It would be better to ask for the number of bytes in the character by
calling SCI_POSITIONAFTER then retrieving the bytes of that character and
calculating the code point from the UTF-8 bytes.
I was sure there would be a more straightforward technique for this. The
revised code could be:
;---------------------------------------------------------
GetAsciiCode(intPos := 0, ByRef intNbBytes := 0)
;---------------------------------------------------------
{
intPosAfter := o_Sci.POSITIONAFTER(intPos)
str := GetTextRange(intPos, intPosAfter)
intNbBytes := intPosAfter - intPos
return Asc(str)
}
;---------------------------------------------------------
Thank you Neil,
Jean
Le samedi 25 janvier 2025 à 17 h 54 min 33 s UTC-5, Neil Hodgson a écrit :
> Jean Lalonde:
>
> > I needed to get the ASCII code of a multibyte character.
>
> Strictly speaking, ASCII is a 7-bit encoding. The equivalent here is the
> Unicode code point value.
>
> > The following code (AutoHotkey v1.1) shows the ASCII code of the 3
> characters in the Scintilla editor. The second character is a multibyte
> character. The function GetAsciiCode() gets the code by looking ahead in
> the editor stream when the Asc() function returns an error.
> >
> > Am I missing a built-in Scintilla command that would allow to do that
> without the GetAsciiCode() workaround?
>
> It would be better to ask for the number of bytes in the character by
> calling SCI_POSITIONAFTER then retrieving the bytes of that character and
> calculating the code point from the UTF-8 bytes.
> https://scintilla.org/ScintillaDoc.html#SCI_POSITIONAFTER
>
> Neil
--
You received this message because you are subscribed to the Google Groups "scintilla-interest" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To view this discussion visit https://groups.google.com/d/msgid/scintilla-interest/8d41525d-b06d-4075-858e-b3cb2ef448adn%40googlegroups.com.