I realized that in wxStyledTextCtrl if the user's comments contains non-ASCII characters, the positions reported by WordStartPosition
and WordEndPosition
are wrong. What is a good way of dealing with non-ASCII characters in wxStyledTextCtrl? How can I identify the characters that are non-ASCII?

- 973
- 9
- 27
-
I should answer my question: Although it might not be the best approach, one way would be to inspect the lengths of RawText which is wxCharBuffer and the text is wxString. wxCharBuffer includes additional characters to accomodate non-ascii characters. – macroland Sep 25 '16 at 00:40
1 Answers
You've probably answered this question by now, but in the experiments I've done, WordStartPosition and WordEndPosition still work with non-ASCII characters. The data internally in the control is stored in UTF-8 format, and those functions give the number of bytes in that data where the word starts and ends. If that's not what's happening for you, can you post a sample where they don't work?
As for determining which characters are and aren't ASCII, something like the following seems to work (assuming a is the start and b is the end position):
wxString s = m_stc->GetTextRange(a,b);
for (wxString::const_iterator i = s.begin(); i != s.end(); ++i)
{
wxUniChar uni_ch = *i;
if(uni_ch.IsAscii())
{
//something
}
else
{
//something else
}
}
One thing I did notice is that if you use a value for a or b that falls in the middle of one of the non-ASCII characters, the resulting string will be empty. I hope this of some help if you haven't already found a solution.

- 3,484
- 1
- 14
- 24
-
You are right about the `WordStartPosition` and `WordEndPosition`. However, `GetTextRange` did not work for me when there was non-ASCII in the text. `GetTextRangeRaw` seemed to be a better way to inspect non-ASCII as if you stream it to std::cout, you can see the non-ASCII characters. – macroland Sep 26 '16 at 01:30