1 // Scintilla source code edit control
2 /** @file CharClassify.cxx
3 ** Character classifications used by Document and RESearch.
5 // Copyright 2006 by Neil Hodgson <neilh@scintilla.org>
6 // The License.txt file describes the conditions under which this software may be distributed.
13 #include "CharacterSet.h"
14 #include "CharClassify.h"
16 using namespace Scintilla
;
18 CharClassify::CharClassify() : charClass
{} {
19 SetDefaultCharClasses(true);
22 void CharClassify::SetDefaultCharClasses(bool includeWordClass
) {
23 // Initialize all char classes to default values
24 for (int ch
= 0; ch
< 256; ch
++) {
25 if (ch
== '\r' || ch
== '\n')
26 charClass
[ch
] = ccNewLine
;
27 else if (ch
< 0x20 || ch
== ' ')
28 charClass
[ch
] = ccSpace
;
29 else if (includeWordClass
&& (ch
>= 0x80 || IsAlphaNumeric(ch
) || ch
== '_'))
30 charClass
[ch
] = ccWord
;
32 charClass
[ch
] = ccPunctuation
;
36 void CharClassify::SetCharClasses(const unsigned char *chars
, cc newCharClass
) {
37 // Apply the newCharClass to the specifed chars
40 charClass
[*chars
] = static_cast<unsigned char>(newCharClass
);
46 int CharClassify::GetCharsOfClass(cc characterClass
, unsigned char *buffer
) const {
47 // Get characters belonging to the given char class; return the number
48 // of characters (if the buffer is NULL, don't write to it).
50 for (int ch
= maxChar
- 1; ch
>= 0; --ch
) {
51 if (charClass
[ch
] == characterClass
) {
54 *buffer
= static_cast<unsigned char>(ch
);