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.
15 static inline int MakeLowerCase(int ch
) {
16 if (ch
< 'A' || ch
> 'Z')
19 return ch
- 'A' + 'a';
22 // All languages handled so far can treat all characters >= 0x80 as one class
23 // which just continues the current token or starts an identifier if in default.
24 // DBCS treated specially as the second character can be < 0x80 and hence
25 // syntactically significant. UTF-8 avoids this as all trail bytes are >= 0x80
29 StyleContext
&operator=(const StyleContext
&);
30 void GetNextChar(unsigned int pos
) {
31 chNext
= static_cast<unsigned char>(styler
.SafeGetCharAt(pos
+1));
32 if (styler
.IsLeadByte(static_cast<char>(chNext
))) {
34 chNext
|= static_cast<unsigned char>(styler
.SafeGetCharAt(pos
+2));
37 // Trigger on CR only (Mac style) or either on LF from CR+LF (Dos/Win)
38 // or on LF alone (Unix). Avoid triggering two times on Dos/Win.
39 atLineEnd
= (ch
== '\r' && chNext
!= '\n') ||
41 (currentPos
>= endPos
);
45 unsigned int currentPos
;
53 StyleContext(unsigned int startPos
, unsigned int length
,
54 int initStyle
, LexAccessor
&styler_
, char chMask
=31) :
56 endPos(startPos
+ length
),
59 state(initStyle
& chMask
), // Mask off all bits which aren't in the chMask.
63 styler
.StartAt(startPos
, chMask
);
64 styler
.StartSegment(startPos
);
65 atLineStart
= static_cast<unsigned int>(styler
.LineStart(styler
.GetLine(startPos
))) == startPos
;
66 unsigned int pos
= currentPos
;
67 ch
= static_cast<unsigned char>(styler
.SafeGetCharAt(pos
));
68 if (styler
.IsLeadByte(static_cast<char>(ch
))) {
71 ch
|= static_cast<unsigned char>(styler
.SafeGetCharAt(pos
));
76 styler
.ColourTo(currentPos
- 1, state
);
80 return currentPos
< endPos
;
83 if (currentPos
< endPos
) {
84 atLineStart
= atLineEnd
;
90 GetNextChar(currentPos
+ ((ch
>= 0x100) ? 1 : 0));
99 void Forward(int nb
) {
100 for (int i
= 0; i
< nb
; i
++) {
104 void ChangeState(int state_
) {
107 void SetState(int state_
) {
108 styler
.ColourTo(currentPos
- 1, state
);
111 void ForwardSetState(int state_
) {
113 styler
.ColourTo(currentPos
- 1, state
);
116 int LengthCurrent() {
117 return currentPos
- styler
.GetStartSegment();
119 int GetRelative(int n
) {
120 return static_cast<unsigned char>(styler
.SafeGetCharAt(currentPos
+n
));
122 bool Match(char ch0
) const {
123 return ch
== static_cast<unsigned char>(ch0
);
125 bool Match(char ch0
, char ch1
) const {
126 return (ch
== static_cast<unsigned char>(ch0
)) && (chNext
== static_cast<unsigned char>(ch1
));
128 bool Match(const char *s
) {
129 if (ch
!= static_cast<unsigned char>(*s
))
134 if (chNext
!= static_cast<unsigned char>(*s
))
137 for (int n
=2; *s
; n
++) {
138 if (*s
!= styler
.SafeGetCharAt(currentPos
+n
))
144 bool MatchIgnoreCase(const char *s
) {
145 if (MakeLowerCase(ch
) != static_cast<unsigned char>(*s
))
148 if (MakeLowerCase(chNext
) != static_cast<unsigned char>(*s
))
151 for (int n
=2; *s
; n
++) {
152 if (static_cast<unsigned char>(*s
) !=
153 MakeLowerCase(static_cast<unsigned char>(styler
.SafeGetCharAt(currentPos
+n
))))
160 void GetCurrent(char *s
, unsigned int len
);
161 void GetCurrentLowered(char *s
, unsigned int len
);