aboutsummaryrefslogtreecommitdiffhomepage
path: root/win32/ScintillaWin.cxx
diff options
context:
space:
mode:
authorNeil <nyamatongwe@gmail.com>2020-06-24 15:00:50 +1000
committerNeil <nyamatongwe@gmail.com>2020-06-24 15:00:50 +1000
commit69d678787645b2dd7d0cd40db4aa5c538ab13f9b (patch)
tree2058ecc0057a30473b082e2cd08a5f766e4eba79 /win32/ScintillaWin.cxx
parentb047c81396af14e5497d969b37b1df9d67d09d17 (diff)
downloadscintilla-mirror-69d678787645b2dd7d0cd40db4aa5c538ab13f9b.tar.gz
Converting between UTF-8 and current encoding.
Allows platform-independent code to be written just to handle Unicode.
Diffstat (limited to 'win32/ScintillaWin.cxx')
-rw-r--r--win32/ScintillaWin.cxx23
1 files changed, 23 insertions, 0 deletions
diff --git a/win32/ScintillaWin.cxx b/win32/ScintillaWin.cxx
index d96199170..bde9ef66b 100644
--- a/win32/ScintillaWin.cxx
+++ b/win32/ScintillaWin.cxx
@@ -403,6 +403,9 @@ class ScintillaWin :
UINT CodePageOfDocument() const noexcept;
bool ValidCodePage(int codePage) const override;
+ std::string UTF8FromEncoded(std::string_view encoded) const override;
+ std::string EncodedFromUTF8(std::string_view utf8) const override;
+
std::string EncodeWString(std::wstring_view wsv);
sptr_t DefWndProc(unsigned int iMessage, uptr_t wParam, sptr_t lParam) override;
void IdleWork() override;
@@ -2053,6 +2056,26 @@ bool ScintillaWin::ValidCodePage(int codePage) const {
codePage == 950 || codePage == 1361;
}
+std::string ScintillaWin::UTF8FromEncoded(std::string_view encoded) const {
+ if (IsUnicodeMode()) {
+ return std::string(encoded);
+ } else {
+ // Pivot through wide string
+ std::wstring ws = StringDecode(encoded, CodePageOfDocument());
+ return StringEncode(ws, SC_CP_UTF8);
+ }
+}
+
+std::string ScintillaWin::EncodedFromUTF8(std::string_view utf8) const {
+ if (IsUnicodeMode()) {
+ return std::string(utf8);
+ } else {
+ // Pivot through wide string
+ std::wstring ws = StringDecode(utf8, SC_CP_UTF8);
+ return StringEncode(ws, CodePageOfDocument());
+ }
+}
+
sptr_t ScintillaWin::DefWndProc(unsigned int iMessage, uptr_t wParam, sptr_t lParam) {
return ::DefWindowProc(MainHWND(), iMessage, wParam, lParam);
}