]>
git.saurik.com Git - wxWidgets.git/blob - src/stc/scintilla/lexlib/CharacterSet.h
a0c45b2fbccf63f6f2936171bbb40e99c0432db6
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.
5 // Copyright 2007 by Neil Hodgson <neilh@scintilla.org>
6 // The License.txt file describes the conditions under which this software may be distributed.
25 setAlpha
=setLower
|setUpper
,
26 setAlphaNum
=setAlpha
|setDigits
28 CharacterSet(setBase base
=setNone
, const char *initialSet
="", int size_
=0x80, bool valueAfter_
=false) {
30 valueAfter
= valueAfter_
;
31 bset
= new bool[size
];
32 for (int i
=0; i
< size
; i
++) {
35 AddString(initialSet
);
37 AddString("abcdefghijklmnopqrstuvwxyz");
39 AddString("ABCDEFGHIJKLMNOPQRSTUVWXYZ");
41 AddString("0123456789");
43 CharacterSet(const CharacterSet
&other
) {
45 valueAfter
= other
.valueAfter
;
46 bset
= new bool[size
];
47 for (int i
=0; i
< size
; i
++) {
48 bset
[i
] = other
.bset
[i
];
56 CharacterSet
&operator=(const CharacterSet
&other
) {
58 bool *bsetNew
= new bool[other
.size
];
59 for (int i
=0; i
< other
.size
; i
++) {
60 bsetNew
[i
] = other
.bset
[i
];
64 valueAfter
= other
.valueAfter
;
74 void AddString(const char *setToAdd
) {
75 for (const char *cp
=setToAdd
; *cp
; cp
++) {
76 int val
= static_cast<unsigned char>(*cp
);
82 bool Contains(int val
) const {
84 if (val
< 0) return false;
85 return (val
< size
) ? bset
[val
] : valueAfter
;
89 // Functions for classifying characters
91 inline bool IsASpace(int ch
) {
92 return (ch
== ' ') || ((ch
>= 0x09) && (ch
<= 0x0d));
95 inline bool IsASpaceOrTab(int ch
) {
96 return (ch
== ' ') || (ch
== '\t');
99 inline bool IsADigit(int ch
) {
100 return (ch
>= '0') && (ch
<= '9');
103 inline bool IsADigit(int ch
, int base
) {
105 return (ch
>= '0') && (ch
< '0' + base
);
107 return ((ch
>= '0') && (ch
<= '9')) ||
108 ((ch
>= 'A') && (ch
< 'A' + base
- 10)) ||
109 ((ch
>= 'a') && (ch
< 'a' + base
- 10));
113 inline bool IsASCII(int ch
) {
114 return (ch
>= 0) && (ch
< 0x80);
117 inline bool IsLowerCase(int ch
) {
118 return (ch
>= 'a') && (ch
<= 'z');
121 inline bool IsUpperCase(int ch
) {
122 return (ch
>= 'A') && (ch
<= 'Z');
125 inline bool IsAlphaNumeric(int ch
) {
127 ((ch
>= '0') && (ch
<= '9')) ||
128 ((ch
>= 'a') && (ch
<= 'z')) ||
129 ((ch
>= 'A') && (ch
<= 'Z'));
133 * Check if a character is a space.
134 * This is ASCII specific but is safe with chars >= 0x80.
136 inline bool isspacechar(int ch
) {
137 return (ch
== ' ') || ((ch
>= 0x09) && (ch
<= 0x0d));
140 inline bool iswordchar(int ch
) {
141 return IsAlphaNumeric(ch
) || ch
== '.' || ch
== '_';
144 inline bool iswordstart(int ch
) {
145 return IsAlphaNumeric(ch
) || ch
== '_';
148 inline bool isoperator(int ch
) {
149 if (IsAlphaNumeric(ch
))
151 if (ch
== '%' || ch
== '^' || ch
== '&' || ch
== '*' ||
152 ch
== '(' || ch
== ')' || ch
== '-' || ch
== '+' ||
153 ch
== '=' || ch
== '|' || ch
== '{' || ch
== '}' ||
154 ch
== '[' || ch
== ']' || ch
== ':' || ch
== ';' ||
155 ch
== '<' || ch
== '>' || ch
== ',' || ch
== '/' ||
156 ch
== '?' || ch
== '!' || ch
== '.' || ch
== '~')
161 // Simple case functions for ASCII.
163 inline char MakeUpperCase(char ch
) {
164 if (ch
< 'a' || ch
> 'z')
167 return static_cast<char>(ch
- 'a' + 'A');
170 int CompareCaseInsensitive(const char *a
, const char *b
);
171 int CompareNCaseInsensitive(const char *a
, const char *b
, size_t len
);