1 // Scintilla source code edit control
2 /** @file CaseFolder.cxx
3 ** Classes for case folding.
5 // Copyright 1998-2013 by Neil Hodgson <neilh@scintilla.org>
6 // The License.txt file describes the conditions under which this software may be distributed.
12 #include "CharacterType.h"
13 #include "CaseFolder.h"
14 #include "CaseConvert.h"
16 using namespace Scintilla::Internal
;
20 constexpr unsigned char IndexFromChar(char ch
) {
21 return static_cast<unsigned char>(ch
);
26 CaseFolderTable::CaseFolderTable() noexcept
: mapping
{} {
30 size_t CaseFolderTable::Fold(char *folded
, size_t sizeFolded
, const char *mixed
, size_t lenMixed
) {
31 if (lenMixed
> sizeFolded
) {
34 for (size_t i
=0; i
<lenMixed
; i
++) {
35 folded
[i
] = mapping
[IndexFromChar(mixed
[i
])];
40 void CaseFolderTable::SetTranslation(char ch
, char chTranslation
) noexcept
{
41 mapping
[IndexFromChar(ch
)] = chTranslation
;
44 void CaseFolderTable::StandardASCII() noexcept
{
45 for (size_t iChar
=0; iChar
<std::size(mapping
); iChar
++) {
46 mapping
[iChar
] = static_cast<char>(MakeLowerCase(iChar
));
50 CaseFolderUnicode::CaseFolderUnicode() {
51 converter
= ConverterFor(CaseConversion::fold
);
54 size_t CaseFolderUnicode::Fold(char *folded
, size_t sizeFolded
, const char *mixed
, size_t lenMixed
) {
55 if ((lenMixed
== 1) && (sizeFolded
> 0)) {
56 folded
[0] = mapping
[IndexFromChar(mixed
[0])];
59 return converter
->CaseConvertString(folded
, sizeFolded
, mixed
, lenMixed
);