Menu

#14 CurrentPos wrong Value on Multi-Byte UTF-8 chars (patch)

open
nobody
None
5
2006-06-21
2006-06-21
No

When entering German Umlauts in Scintilla.Net (äöü)
CurrentPos at the end of the Text is actually at
myControl.Text.Length + n (n depending on the number
of umlauts).

This is apperantly because Scintilla returns the byte
position, but of course .Net expects a character
position for functions like substring.

SelectionStart is wrong as well - haven't checked
SelectionEnd

Here's a quick hack that fixes at least the get part -
I personally don't set the currentPos in my app (nor
do I change the selection - but those need fixing as
well), so this is only a partial fix.

unsafe public int CurrentPos
{
get
{
//should probably be merged with
GetText
int sz = (int)SPerform(2182,
(uint)Length, 0);
byte[] buffer = new byte[sz + 1];
fixed (byte* b = buffer)
SPerform(2182, (uint)Length + 1,
(uint)b);

int iPos = (int)SPerform(2008, 0, 0);
fixed (byte* b = buffer)
iPos =
System.Text.UTF8Encoding.UTF8.GetCharCount(
b, iPos);
return iPos;
}
set
{
SPerform(2141, (uint)value, 0);
}
}

So long,
Tyberius Prime

Discussion


Log in to post a comment.

Monday.com Logo