From dad0081820141b9823f8a4ad633b28515f055f1f Mon Sep 17 00:00:00 2001 From: Neil Date: Thu, 11 Jul 2013 10:43:40 +1000 Subject: Include case conversion data in Scintilla so that all platforms will perform case conversion of Unicode text in accordance with Unicode. --- qt/ScintillaEditBase/ScintillaQt.cpp | 45 ++++++++---------------------------- 1 file changed, 10 insertions(+), 35 deletions(-) (limited to 'qt/ScintillaEditBase/ScintillaQt.cpp') diff --git a/qt/ScintillaEditBase/ScintillaQt.cpp b/qt/ScintillaEditBase/ScintillaQt.cpp index 4d0d62082..a956ff714 100644 --- a/qt/ScintillaEditBase/ScintillaQt.cpp +++ b/qt/ScintillaEditBase/ScintillaQt.cpp @@ -488,30 +488,6 @@ QByteArray ScintillaQt::BytesForDocument(const QString &text) const } -class CaseFolderUTF8 : public CaseFolderTable { -public: - CaseFolderUTF8() { - StandardASCII(); - } - virtual size_t Fold(char *folded, size_t sizeFolded, const char *mixed, size_t lenMixed) { - if ((lenMixed == 1) && (sizeFolded > 0)) { - folded[0] = mapping[static_cast(mixed[0])]; - return 1; - } else { - QString su = QString::fromUtf8(mixed, lenMixed); - QString suFolded = su.toCaseFolded(); - QByteArray bytesFolded = suFolded.toUtf8(); - if (bytesFolded.length() < static_cast(sizeFolded)) { - memcpy(folded, bytesFolded, bytesFolded.length()); - return bytesFolded.length(); - } else { - folded[0] = '\0'; - return 0; - } - } - } -}; - class CaseFolderDBCS : public CaseFolderTable { QTextCodec *codec; public: @@ -541,7 +517,7 @@ public: CaseFolder *ScintillaQt::CaseFolderForEncoding() { if (pdoc->dbcsCodePage == SC_CP_UTF8) { - return new CaseFolderUTF8(); + return new CaseFolderUnicode(); } else { const char *charSetBuffer = CharacterSetIDOfDocument(); if (charSetBuffer) { @@ -571,21 +547,20 @@ CaseFolder *ScintillaQt::CaseFolderForEncoding() std::string ScintillaQt::CaseMapString(const std::string &s, int caseMapping) { - if (s.size() == 0) - return std::string(); - - if (caseMapping == cmSame) + if ((s.size() == 0) || (caseMapping == cmSame)) return s; - QTextCodec *codec = 0; - QString text; if (IsUnicodeMode()) { - text = QString::fromUtf8(s.c_str(), s.length()); - } else { - codec = QTextCodec::codecForName(CharacterSetIDOfDocument()); - text = codec->toUnicode(s.c_str(), s.length()); + std::string retMapped(s.length() * maxExpansionCaseConversion, 0); + size_t lenMapped = CaseConvertString(&retMapped[0], retMapped.length(), s.c_str(), s.length(), + (caseMapping == cmUpper) ? CaseConversionUpper : CaseConversionLower); + retMapped.resize(lenMapped); + return retMapped; } + QTextCodec *codec = QTextCodec::codecForName(CharacterSetIDOfDocument()); + QString text = codec->toUnicode(s.c_str(), s.length()); + if (caseMapping == cmUpper) { text = text.toUpper(); } else { -- cgit v1.2.3