From 8ab163cb5aca7aabf2bd8ea523c024da0ea36e06 Mon Sep 17 00:00:00 2001 From: Thomas Goyne Date: Wed, 10 Jul 2013 17:43:41 -0700 Subject: [PATCH] Make GetReverseUnicodePosition less horribly awful --- aegisub/src/scintilla_text_ctrl.cpp | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) diff --git a/aegisub/src/scintilla_text_ctrl.cpp b/aegisub/src/scintilla_text_ctrl.cpp index 36cc07761..04d9d0231 100644 --- a/aegisub/src/scintilla_text_ctrl.cpp +++ b/aegisub/src/scintilla_text_ctrl.cpp @@ -51,19 +51,7 @@ int ScintillaTextCtrl::GetUnicodePosition(int pos) { /// @brief Reverse unicode-compatible position int ScintillaTextCtrl::GetReverseUnicodePosition(int pos) { wxCharBuffer buffer = GetTextRaw(); - - // 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(); + return wxString::FromUTF8(buffer.data(), std::min(pos, buffer.length())).length(); } /// @brief Start unicode-safe styling