Update Scintilla to version 3.4.4
[TortoiseGit.git] / ext / scintilla / src / CaseFolder.cxx
blob829bf1662a2b68a176d930f5a7c11a4452cb19d8
1 // Scintilla source code edit control
2 /** @file CaseFolder.cxx
3 ** Classes for case folding.
4 **/
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.
8 #include <vector>
9 #include <algorithm>
11 #include "CaseFolder.h"
12 #include "CaseConvert.h"
13 #include "UniConversion.h"
15 #ifdef SCI_NAMESPACE
16 using namespace Scintilla;
17 #endif
19 CaseFolder::~CaseFolder() {
22 CaseFolderTable::CaseFolderTable() {
23 for (size_t iChar=0; iChar<sizeof(mapping); iChar++) {
24 mapping[iChar] = static_cast<char>(iChar);
28 CaseFolderTable::~CaseFolderTable() {
31 size_t CaseFolderTable::Fold(char *folded, size_t sizeFolded, const char *mixed, size_t lenMixed) {
32 if (lenMixed > sizeFolded) {
33 return 0;
34 } else {
35 for (size_t i=0; i<lenMixed; i++) {
36 folded[i] = mapping[static_cast<unsigned char>(mixed[i])];
38 return lenMixed;
42 void CaseFolderTable::SetTranslation(char ch, char chTranslation) {
43 mapping[static_cast<unsigned char>(ch)] = chTranslation;
46 void CaseFolderTable::StandardASCII() {
47 for (size_t iChar=0; iChar<sizeof(mapping); iChar++) {
48 if (iChar >= 'A' && iChar <= 'Z') {
49 mapping[iChar] = static_cast<char>(iChar - 'A' + 'a');
50 } else {
51 mapping[iChar] = static_cast<char>(iChar);
56 CaseFolderUnicode::CaseFolderUnicode() {
57 StandardASCII();
58 converter = ConverterFor(CaseConversionFold);
61 size_t CaseFolderUnicode::Fold(char *folded, size_t sizeFolded, const char *mixed, size_t lenMixed) {
62 if ((lenMixed == 1) && (sizeFolded > 0)) {
63 folded[0] = mapping[static_cast<unsigned char>(mixed[0])];
64 return 1;
65 } else {
66 return converter->CaseConvertString(folded, sizeFolded, mixed, lenMixed);