]>
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.
8 // All languages handled so far can treat all characters >= 0x80 as one class
9 // which just continues the current token or starts an identifier if in default.
10 // DBCS treated specially as the second character can be < 0x80 and hence
11 // syntactically significant. UTF-8 avoids this as all trail bytes are >= 0x80
15 StyleContext
& operator=(const StyleContext
&) {
18 void GetNextChar(unsigned int pos
) {
19 chNext
= static_cast<unsigned char>(styler
.SafeGetCharAt(pos
+1));
20 if (styler
.IsLeadByte(static_cast<char>(chNext
))) {
22 chNext
|= static_cast<unsigned char>(styler
.SafeGetCharAt(pos
+2));
25 // Trigger on CR only (Mac style) or either on LF from CR+LF (Dos/Win)
26 // or on LF alone (Unix). Avoid triggering two times on Dos/Win.
27 atLineEnd
= (ch
== '\r' && chNext
!= '\n') ||
29 (currentPos
>= endPos
);
33 unsigned int currentPos
;
41 StyleContext(unsigned int startPos
, unsigned int length
,
42 int initStyle
, Accessor
&styler_
, char chMask
=31) :
44 endPos(startPos
+ length
),
48 state(initStyle
& chMask
), // Mask off all bits which aren't in the chMask.
52 styler
.StartAt(startPos
, chMask
);
53 styler
.StartSegment(startPos
);
54 unsigned int pos
= currentPos
;
55 ch
= static_cast<unsigned char>(styler
.SafeGetCharAt(pos
));
56 if (styler
.IsLeadByte(static_cast<char>(ch
))) {
59 ch
|= static_cast<unsigned char>(styler
.SafeGetCharAt(pos
));
64 styler
.ColourTo(currentPos
- 1, state
);
67 return currentPos
< endPos
;
70 if (currentPos
< endPos
) {
71 atLineStart
= atLineEnd
;
77 GetNextChar(currentPos
+ ((ch
>= 0x100) ? 1 : 0));
86 void Forward(int nb
) {
87 for (int i
= 0; i
< nb
; i
++) {
91 void ChangeState(int state_
) {
94 void SetState(int state_
) {
95 styler
.ColourTo(currentPos
- 1, state
);
98 void ForwardSetState(int state_
) {
100 styler
.ColourTo(currentPos
- 1, state
);
103 int LengthCurrent() {
104 return currentPos
- styler
.GetStartSegment();
106 int GetRelative(int n
) {
107 return static_cast<unsigned char>(styler
.SafeGetCharAt(currentPos
+n
));
109 bool Match(char ch0
) {
112 bool Match(char ch0
, char ch1
) {
113 return (ch
== ch0
) && (chNext
== ch1
);
115 bool Match(const char *s
) {
122 for (int n
=2; *s
; n
++) {
123 if (*s
!= styler
.SafeGetCharAt(currentPos
+n
))
129 bool MatchIgnoreCase(const char *s
) {
130 if (tolower(ch
) != *s
)
133 if (tolower(chNext
) != *s
)
136 for (int n
=2; *s
; n
++) {
138 tolower(static_cast<unsigned char>(styler
.SafeGetCharAt(currentPos
+n
))))
145 void GetCurrent(char *s
, unsigned int len
);
146 void GetCurrentLowered(char *s
, unsigned int len
);
149 inline bool IsASpace(unsigned int ch
) {
150 return (ch
== ' ') || ((ch
>= 0x09) && (ch
<= 0x0d));
153 inline bool IsASpaceOrTab(unsigned int ch
) {
154 return (ch
== ' ') || (ch
== '\t');
157 inline bool IsADigit(unsigned int ch
) {
158 return (ch
>= '0') && (ch
<= '9');
161 inline bool IsADigit(unsigned int ch
, unsigned int base
) {
163 return (ch
>= '0') && (ch
< '0' + base
);
165 return ((ch
>= '0') && (ch
<= '9')) ||
166 ((ch
>= 'A') && (ch
< 'A' + base
- 10)) ||
167 ((ch
>= 'a') && (ch
< 'a' + base
- 10));