diff options
author | Neil <nyamatongwe@gmail.com> | 2022-04-08 10:05:11 +1000 |
---|---|---|
committer | Neil <nyamatongwe@gmail.com> | 2022-04-08 10:05:11 +1000 |
commit | 8a44ef9acfda0ec46a541f0be56333eb5cf6b0ff (patch) | |
tree | 5a916f02eeb2d7ae00412175458291c9934d585d /src/CaseFolder.cxx | |
parent | a1961d248ac5521cea7bd22e4d7e2e203bf2d361 (diff) | |
download | scintilla-mirror-8a44ef9acfda0ec46a541f0be56333eb5cf6b0ff.tar.gz |
Feature [feature-requests:#1389] Initialize CaseFolderTable to ASCII so
subclasses do not need to call StandardASCII.
Avoid some lint warnings.
Diffstat (limited to 'src/CaseFolder.cxx')
-rw-r--r-- | src/CaseFolder.cxx | 34 |
1 files changed, 16 insertions, 18 deletions
diff --git a/src/CaseFolder.cxx b/src/CaseFolder.cxx index b5acc5f96..d66df3f4f 100644 --- a/src/CaseFolder.cxx +++ b/src/CaseFolder.cxx @@ -9,53 +9,51 @@ #include <vector> #include <algorithm> +#include "CharacterType.h" #include "CaseFolder.h" #include "CaseConvert.h" using namespace Scintilla::Internal; -CaseFolder::~CaseFolder() { +namespace { + +constexpr unsigned char IndexFromChar(char ch) { + return static_cast<unsigned char>(ch); +} + } CaseFolderTable::CaseFolderTable() noexcept : mapping{} { - for (size_t iChar=0; iChar<sizeof(mapping); iChar++) { - mapping[iChar] = static_cast<char>(iChar); - } + StandardASCII(); } size_t CaseFolderTable::Fold(char *folded, size_t sizeFolded, const char *mixed, size_t lenMixed) { if (lenMixed > sizeFolded) { return 0; - } else { - for (size_t i=0; i<lenMixed; i++) { - folded[i] = mapping[static_cast<unsigned char>(mixed[i])]; - } - return lenMixed; } + for (size_t i=0; i<lenMixed; i++) { + folded[i] = mapping[IndexFromChar(mixed[i])]; + } + return lenMixed; } void CaseFolderTable::SetTranslation(char ch, char chTranslation) noexcept { - mapping[static_cast<unsigned char>(ch)] = chTranslation; + mapping[IndexFromChar(ch)] = chTranslation; } void CaseFolderTable::StandardASCII() noexcept { - for (size_t iChar=0; iChar<sizeof(mapping); iChar++) { - if (iChar >= 'A' && iChar <= 'Z') { - mapping[iChar] = static_cast<char>(iChar - 'A' + 'a'); - } else { - mapping[iChar] = static_cast<char>(iChar); - } + for (size_t iChar=0; iChar<std::size(mapping); iChar++) { + mapping[iChar] = static_cast<char>(MakeLowerCase(iChar)); } } CaseFolderUnicode::CaseFolderUnicode() { - StandardASCII(); converter = ConverterFor(CaseConversion::fold); } size_t CaseFolderUnicode::Fold(char *folded, size_t sizeFolded, const char *mixed, size_t lenMixed) { if ((lenMixed == 1) && (sizeFolded > 0)) { - folded[0] = mapping[static_cast<unsigned char>(mixed[0])]; + folded[0] = mapping[IndexFromChar(mixed[0])]; return 1; } else { return converter->CaseConvertString(folded, sizeFolded, mixed, lenMixed); |