]>
git.saurik.com Git - wxWidgets.git/blob - src/stc/scintilla/src/StyleContext.h
1 // Scintilla source code edit control
2 /** @file StyleContext.cxx
3 ** Lexer infrastructure.
5 // Copyright 1998-2004 by Neil Hodgson <neilh@scintilla.org>
6 // This file is in the public domain.
12 // All languages handled so far can treat all characters >= 0x80 as one class
13 // which just continues the current token or starts an identifier if in default.
14 // DBCS treated specially as the second character can be < 0x80 and hence
15 // syntactically significant. UTF-8 avoids this as all trail bytes are >= 0x80
19 StyleContext
& operator=(const StyleContext
&) {
22 void GetNextChar(unsigned int pos
) {
23 chNext
= static_cast<unsigned char>(styler
.SafeGetCharAt(pos
+1));
24 if (styler
.IsLeadByte(static_cast<char>(chNext
))) {
26 chNext
|= static_cast<unsigned char>(styler
.SafeGetCharAt(pos
+2));
29 // Trigger on CR only (Mac style) or either on LF from CR+LF (Dos/Win)
30 // or on LF alone (Unix). Avoid triggering two times on Dos/Win.
31 atLineEnd
= (ch
== '\r' && chNext
!= '\n') ||
33 (currentPos
>= endPos
);
37 unsigned int currentPos
;
45 StyleContext(unsigned int startPos
, unsigned int length
,
46 int initStyle
, Accessor
&styler_
, char chMask
=31) :
48 endPos(startPos
+ length
),
52 state(initStyle
& chMask
), // Mask off all bits which aren't in the chMask.
56 styler
.StartAt(startPos
, chMask
);
57 styler
.StartSegment(startPos
);
58 unsigned int pos
= currentPos
;
59 ch
= static_cast<unsigned char>(styler
.SafeGetCharAt(pos
));
60 if (styler
.IsLeadByte(static_cast<char>(ch
))) {
63 ch
|= static_cast<unsigned char>(styler
.SafeGetCharAt(pos
));
68 styler
.ColourTo(currentPos
- 1, state
);
71 return currentPos
< endPos
;
74 if (currentPos
< endPos
) {
75 atLineStart
= atLineEnd
;
81 GetNextChar(currentPos
+ ((ch
>= 0x100) ? 1 : 0));
90 void Forward(int nb
) {
91 for (int i
= 0; i
< nb
; i
++) {
95 void ChangeState(int state_
) {
98 void SetState(int state_
) {
99 styler
.ColourTo(currentPos
- 1, state
);
102 void ForwardSetState(int state_
) {
104 styler
.ColourTo(currentPos
- 1, state
);
107 int LengthCurrent() {
108 return currentPos
- styler
.GetStartSegment();
110 int GetRelative(int n
) {
111 return static_cast<unsigned char>(styler
.SafeGetCharAt(currentPos
+n
));
113 bool Match(char ch0
) {
114 return ch
== static_cast<unsigned char>(ch0
);
116 bool Match(char ch0
, char ch1
) {
117 return (ch
== static_cast<unsigned char>(ch0
)) && (chNext
== static_cast<unsigned char>(ch1
));
119 bool Match(const char *s
) {
120 if (ch
!= static_cast<unsigned char>(*s
))
125 if (chNext
!= static_cast<unsigned char>(*s
))
128 for (int n
=2; *s
; n
++) {
129 if (*s
!= styler
.SafeGetCharAt(currentPos
+n
))
135 bool MatchIgnoreCase(const char *s
) {
136 if (tolower(ch
) != static_cast<unsigned char>(*s
))
139 if (tolower(chNext
) != static_cast<unsigned char>(*s
))
142 for (int n
=2; *s
; n
++) {
143 if (static_cast<unsigned char>(*s
) !=
144 tolower(static_cast<unsigned char>(styler
.SafeGetCharAt(currentPos
+n
))))
151 void GetCurrent(char *s
, unsigned int len
);
152 void GetCurrentLowered(char *s
, unsigned int len
);
159 inline bool IsASpace(unsigned int ch
) {
160 return (ch
== ' ') || ((ch
>= 0x09) && (ch
<= 0x0d));
163 inline bool IsASpaceOrTab(unsigned int ch
) {
164 return (ch
== ' ') || (ch
== '\t');
167 inline bool IsADigit(unsigned int ch
) {
168 return (ch
>= '0') && (ch
<= '9');
171 inline bool IsADigit(unsigned int ch
, unsigned int base
) {
173 return (ch
>= '0') && (ch
< '0' + base
);
175 return ((ch
>= '0') && (ch
<= '9')) ||
176 ((ch
>= 'A') && (ch
< 'A' + base
- 10)) ||
177 ((ch
>= 'a') && (ch
< 'a' + base
- 10));