xref: /MusicPlayer2/scintilla/src/CaseConvert.h (revision 8af74909132ed5e696cb05b6689ae4baf14c1c96)
1*8af74909SZhong Yang // Scintilla source code edit control
2*8af74909SZhong Yang // Encoding: UTF-8
3*8af74909SZhong Yang /** @file CaseConvert.h
4*8af74909SZhong Yang  ** Performs Unicode case conversions.
5*8af74909SZhong Yang  ** Does not handle locale-sensitive case conversion.
6*8af74909SZhong Yang  **/
7*8af74909SZhong Yang // Copyright 2013 by Neil Hodgson <[email protected]>
8*8af74909SZhong Yang // The License.txt file describes the conditions under which this software may be distributed.
9*8af74909SZhong Yang 
10*8af74909SZhong Yang #ifndef CASECONVERT_H
11*8af74909SZhong Yang #define CASECONVERT_H
12*8af74909SZhong Yang 
13*8af74909SZhong Yang namespace Scintilla {
14*8af74909SZhong Yang 
15*8af74909SZhong Yang enum CaseConversion {
16*8af74909SZhong Yang 	CaseConversionFold,
17*8af74909SZhong Yang 	CaseConversionUpper,
18*8af74909SZhong Yang 	CaseConversionLower
19*8af74909SZhong Yang };
20*8af74909SZhong Yang 
21*8af74909SZhong Yang class ICaseConverter {
22*8af74909SZhong Yang public:
23*8af74909SZhong Yang 	virtual size_t CaseConvertString(char *converted, size_t sizeConverted, const char *mixed, size_t lenMixed) = 0;
24*8af74909SZhong Yang };
25*8af74909SZhong Yang 
26*8af74909SZhong Yang ICaseConverter *ConverterFor(enum CaseConversion conversion);
27*8af74909SZhong Yang 
28*8af74909SZhong Yang // Returns a UTF-8 string. Empty when no conversion
29*8af74909SZhong Yang const char *CaseConvert(int character, enum CaseConversion conversion);
30*8af74909SZhong Yang 
31*8af74909SZhong Yang // When performing CaseConvertString, the converted value may be up to 3 times longer than the input.
32*8af74909SZhong Yang // Ligatures are often decomposed into multiple characters and long cases include:
33*8af74909SZhong Yang // ΐ "\xce\x90" folds to ΐ "\xce\xb9\xcc\x88\xcc\x81"
34*8af74909SZhong Yang constexpr size_t maxExpansionCaseConversion = 3;
35*8af74909SZhong Yang 
36*8af74909SZhong Yang // Converts a mixed case string using a particular conversion.
37*8af74909SZhong Yang // Result may be a different length to input and the length is the return value.
38*8af74909SZhong Yang // If there is not enough space then 0 is returned.
39*8af74909SZhong Yang size_t CaseConvertString(char *converted, size_t sizeConverted, const char *mixed, size_t lenMixed, enum CaseConversion conversion);
40*8af74909SZhong Yang 
41*8af74909SZhong Yang // Converts a mixed case string using a particular conversion.
42*8af74909SZhong Yang std::string CaseConvertString(const std::string &s, enum CaseConversion conversion);
43*8af74909SZhong Yang 
44*8af74909SZhong Yang }
45*8af74909SZhong Yang 
46*8af74909SZhong Yang #endif
47