mirror of https://github.com/odrling/Aegisub
Make GetReverseUnicodePosition less horribly awful
This commit is contained in:
parent
5ff42d9469
commit
8ab163cb5a
|
@ -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
|
||||||
|
|
Loading…
Reference in New Issue