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 "CaseFolder.h"
13 #include "CaseConvert.h"
14 #include "UniConversion.h"
17 using namespace Scintilla
;
20 CaseFolder::~CaseFolder() {
23 CaseFolderTable::CaseFolderTable() {
24 for (size_t iChar
=0; iChar
<sizeof(mapping
); iChar
++) {
25 mapping
[iChar
] = static_cast<char>(iChar
);
29 CaseFolderTable::~CaseFolderTable() {
32 size_t CaseFolderTable::Fold(char *folded
, size_t sizeFolded
, const char *mixed
, size_t lenMixed
) {
33 if (lenMixed
> sizeFolded
) {
36 for (size_t i
=0; i
<lenMixed
; i
++) {
37 folded
[i
] = mapping
[static_cast<unsigned char>(mixed
[i
])];
43 void CaseFolderTable::SetTranslation(char ch
, char chTranslation
) {
44 mapping
[static_cast<unsigned char>(ch
)] = chTranslation
;
47 void CaseFolderTable::StandardASCII() {
48 for (size_t iChar
=0; iChar
<sizeof(mapping
); iChar
++) {
49 if (iChar
>= 'A' && iChar
<= 'Z') {
50 mapping
[iChar
] = static_cast<char>(iChar
- 'A' + 'a');
52 mapping
[iChar
] = static_cast<char>(iChar
);
57 CaseFolderUnicode::CaseFolderUnicode() {
59 converter
= ConverterFor(CaseConversionFold
);
62 size_t CaseFolderUnicode::Fold(char *folded
, size_t sizeFolded
, const char *mixed
, size_t lenMixed
) {
63 if ((lenMixed
== 1) && (sizeFolded
> 0)) {
64 folded
[0] = mapping
[static_cast<unsigned char>(mixed
[0])];
67 return converter
->CaseConvertString(folded
, sizeFolded
, mixed
, lenMixed
);