Make GetReverseUnicodePosition less horribly awful

This commit is contained in:
Thomas Goyne 2013-07-10 17:43:41 -07:00
parent 5ff42d9469
commit 8ab163cb5a
1 changed files with 1 additions and 13 deletions

View File

@ -51,19 +51,7 @@ int ScintillaTextCtrl::GetUnicodePosition(int pos) {
/// @brief Reverse unicode-compatible position /// @brief Reverse unicode-compatible position
int ScintillaTextCtrl::GetReverseUnicodePosition(int pos) { int ScintillaTextCtrl::GetReverseUnicodePosition(int pos) {
wxCharBuffer buffer = GetTextRaw(); wxCharBuffer buffer = GetTextRaw();
return wxString::FromUTF8(buffer.data(), std::min<int>(pos, buffer.length())).length();
// Limit position to it
if (pos > (signed)buffer.length()) pos = buffer.length();
// Get UTF8 substring
char *buf2 = new char[pos+1];
memcpy(buf2,buffer,pos);
buf2[pos] = 0;
// Convert back and return its length
wxString buf3(buf2,wxConvUTF8);
delete[] buf2;
return buf3.Length();
} }
/// @brief Start unicode-safe styling /// @brief Start unicode-safe styling