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
&);
20 void GetNextChar(unsigned int pos
) {
21 chNext
= static_cast<unsigned char>(styler
.SafeGetCharAt(pos
+1));
22 if (styler
.IsLeadByte(static_cast<char>(chNext
))) {
24 chNext
|= static_cast<unsigned char>(styler
.SafeGetCharAt(pos
+2));
27 // Trigger on CR only (Mac style) or either on LF from CR+LF (Dos/Win)
28 // or on LF alone (Unix). Avoid triggering two times on Dos/Win.
29 atLineEnd
= (ch
== '\r' && chNext
!= '\n') ||
31 (currentPos
>= endPos
);
35 unsigned int currentPos
;
43 StyleContext(unsigned int startPos
, unsigned int length
,
44 int initStyle
, Accessor
&styler_
, char chMask
=31) :
46 endPos(startPos
+ length
),
50 state(initStyle
& chMask
), // Mask off all bits which aren't in the chMask.
54 styler
.StartAt(startPos
, chMask
);
55 styler
.StartSegment(startPos
);
56 unsigned int pos
= currentPos
;
57 ch
= static_cast<unsigned char>(styler
.SafeGetCharAt(pos
));
58 if (styler
.IsLeadByte(static_cast<char>(ch
))) {
61 ch
|= static_cast<unsigned char>(styler
.SafeGetCharAt(pos
));
66 styler
.ColourTo(currentPos
- 1, state
);
69 return currentPos
< endPos
;
72 if (currentPos
< endPos
) {
73 atLineStart
= atLineEnd
;
79 GetNextChar(currentPos
+ ((ch
>= 0x100) ? 1 : 0));
88 void Forward(int nb
) {
89 for (int i
= 0; i
< nb
; i
++) {
93 void ChangeState(int state_
) {
96 void SetState(int state_
) {
97 styler
.ColourTo(currentPos
- 1, state
);
100 void ForwardSetState(int state_
) {
102 styler
.ColourTo(currentPos
- 1, state
);
105 int LengthCurrent() {
106 return currentPos
- styler
.GetStartSegment();
108 int GetRelative(int n
) {
109 return static_cast<unsigned char>(styler
.SafeGetCharAt(currentPos
+n
));
111 bool Match(char ch0
) {
112 return ch
== static_cast<unsigned char>(ch0
);
114 bool Match(char ch0
, char ch1
) {
115 return (ch
== static_cast<unsigned char>(ch0
)) && (chNext
== static_cast<unsigned char>(ch1
));
117 bool Match(const char *s
) {
118 if (ch
!= static_cast<unsigned char>(*s
))
123 if (chNext
!= static_cast<unsigned char>(*s
))
126 for (int n
=2; *s
; n
++) {
127 if (*s
!= styler
.SafeGetCharAt(currentPos
+n
))
133 bool MatchIgnoreCase(const char *s
) {
134 if (tolower(ch
) != static_cast<unsigned char>(*s
))
137 if (tolower(chNext
) != static_cast<unsigned char>(*s
))
140 for (int n
=2; *s
; n
++) {
141 if (static_cast<unsigned char>(*s
) !=
142 tolower(static_cast<unsigned char>(styler
.SafeGetCharAt(currentPos
+n
))))
149 void GetCurrent(char *s
, unsigned int len
);
150 void GetCurrentLowered(char *s
, unsigned int len
);
157 inline bool IsASpace(unsigned int ch
) {
158 return (ch
== ' ') || ((ch
>= 0x09) && (ch
<= 0x0d));
161 inline bool IsASpaceOrTab(unsigned int ch
) {
162 return (ch
== ' ') || (ch
== '\t');
165 inline bool IsADigit(unsigned int ch
) {
166 return (ch
>= '0') && (ch
<= '9');
169 inline bool IsADigit(unsigned int ch
, unsigned int base
) {
171 return (ch
>= '0') && (ch
< '0' + base
);
173 return ((ch
>= '0') && (ch
<= '9')) ||
174 ((ch
>= 'A') && (ch
< 'A' + base
- 10)) ||
175 ((ch
>= 'a') && (ch
< 'a' + base
- 10));