]> git.saurik.com Git - wxWidgets.git/blob - src/stc/scintilla/src/CharacterSet.h
4e8ffbdf6fe8a1907593581a9b396bbae4a33ba5
[wxWidgets.git] / src / stc / scintilla / src / CharacterSet.h
1 // Scintilla source code edit control
2 /** @file CharacterSet.h
3 ** Encapsulates a set of characters. Used to test if a character is within a set.
4 **/
5 // Copyright 2007 by Neil Hodgson <neilh@scintilla.org>
6 // The License.txt file describes the conditions under which this software may be distributed.
7
8 class CharacterSet {
9 int size;
10 bool valueAfter;
11 bool *bset;
12 public:
13 enum setBase {
14 setNone=0,
15 setLower=1,
16 setUpper=2,
17 setDigits=4,
18 setAlpha=setLower|setUpper,
19 setAlphaNum=setAlpha|setDigits
20 };
21 CharacterSet(setBase base=setNone, const char *initialSet="", int size_=0x80, bool valueAfter_=false) {
22 size = size_;
23 valueAfter = valueAfter_;
24 bset = new bool[size];
25 for (int i=0; i < size; i++) {
26 bset[i] = false;
27 }
28 AddString(initialSet);
29 if (base & setLower)
30 AddString("abcdefghijklmnopqrstuvwxyz");
31 if (base & setUpper)
32 AddString("ABCDEFGHIJKLMNOPQRSTUVWXYZ");
33 if (base & setDigits)
34 AddString("0123456789");
35 }
36 ~CharacterSet() {
37 delete []bset;
38 bset = 0;
39 size = 0;
40 }
41 void Add(int val) {
42 PLATFORM_ASSERT(val >= 0);
43 PLATFORM_ASSERT(val < size);
44 bset[val] = true;
45 }
46 void AddString(const char *CharacterSet) {
47 for (const char *cp=CharacterSet; *cp; cp++) {
48 int val = static_cast<unsigned char>(*cp);
49 PLATFORM_ASSERT(val >= 0);
50 PLATFORM_ASSERT(val < size);
51 bset[val] = true;
52 }
53 }
54 bool Contains(int val) const {
55 PLATFORM_ASSERT(val >= 0);
56 return (val < size) ? bset[val] : valueAfter;
57 }
58 };