]>
git.saurik.com Git - wxWidgets.git/blob - src/stc/scintilla/lexlib/LexAccessor.h
1 // Scintilla source code edit control
2 /** @file LexAccessor.h
3 ** Interfaces between Scintilla and lexers.
5 // Copyright 1998-2010 by Neil Hodgson <neilh@scintilla.org>
6 // The License.txt file describes the conditions under which this software may be distributed.
18 enum {extremePosition
=0x7FFFFFFF};
19 /** @a bufferSize is a trade off between time taken to copy the characters
20 * and retrieval overhead.
21 * @a slopSize positions the buffer before the desired position
22 * in case there is some backtracking. */
23 enum {bufferSize
=4000, slopSize
=bufferSize
/8};
24 char buf
[bufferSize
+1];
30 char styleBuf
[bufferSize
];
34 unsigned int startSeg
;
37 void Fill(int position
) {
38 startPos
= position
- slopSize
;
39 if (startPos
+ bufferSize
> lenDoc
)
40 startPos
= lenDoc
- bufferSize
;
43 endPos
= startPos
+ bufferSize
;
47 pAccess
->GetCharRange(buf
, startPos
, endPos
-startPos
);
48 buf
[endPos
-startPos
] = '\0';
52 LexAccessor(IDocument
*pAccess_
) :
53 pAccess(pAccess_
), startPos(extremePosition
), endPos(0),
54 codePage(pAccess
->CodePage()), lenDoc(pAccess
->Length()),
55 mask(127), validLen(0), chFlags(0), chWhile(0),
56 startSeg(0), startPosStyling(0) {
58 char operator[](int position
) {
59 if (position
< startPos
|| position
>= endPos
) {
62 return buf
[position
- startPos
];
64 /** Safe version of operator[], returning a defined value for invalid position. */
65 char SafeGetCharAt(int position
, char chDefault
=' ') {
66 if (position
< startPos
|| position
>= endPos
) {
68 if (position
< startPos
|| position
>= endPos
) {
69 // Position is outside range of document
73 return buf
[position
- startPos
];
75 bool IsLeadByte(char ch
) {
76 return pAccess
->IsDBCSLeadByte(ch
);
79 bool Match(int pos
, const char *s
) {
80 for (int i
=0; *s
; i
++) {
81 if (*s
!= SafeGetCharAt(pos
+i
))
87 char StyleAt(int position
) {
88 return static_cast<char>(pAccess
->StyleAt(position
) & mask
);
90 int GetLine(int position
) {
91 return pAccess
->LineFromPosition(position
);
93 int LineStart(int line
) {
94 return pAccess
->LineStart(line
);
96 int LevelAt(int line
) {
97 return pAccess
->GetLevel(line
);
103 startPos
= extremePosition
;
105 pAccess
->SetStyles(validLen
, styleBuf
);
106 startPosStyling
+= validLen
;
110 int GetLineState(int line
) {
111 return pAccess
->GetLineState(line
);
113 int SetLineState(int line
, int state
) {
114 return pAccess
->SetLineState(line
, state
);
117 void StartAt(unsigned int start
, char chMask
=31) {
118 // Store the mask specified for use with StyleAt.
120 pAccess
->StartStyling(start
, chMask
);
121 startPosStyling
= start
;
123 void SetFlags(char chFlags_
, char chWhile_
) {
127 unsigned int GetStartSegment() const {
130 void StartSegment(unsigned int pos
) {
133 void ColourTo(unsigned int pos
, int chAttr
) {
134 // Only perform styling if non empty range
135 if (pos
!= startSeg
- 1) {
136 assert(pos
>= startSeg
);
137 if (pos
< startSeg
) {
141 if (validLen
+ (pos
- startSeg
+ 1) >= bufferSize
)
143 if (validLen
+ (pos
- startSeg
+ 1) >= bufferSize
) {
144 // Too big for buffer so send directly
145 pAccess
->SetStyleFor(pos
- startSeg
+ 1, static_cast<char>(chAttr
));
147 if (chAttr
!= chWhile
)
149 chAttr
= static_cast<char>(chAttr
| chFlags
);
150 for (unsigned int i
= startSeg
; i
<= pos
; i
++) {
151 assert((startPosStyling
+ validLen
) < Length());
152 styleBuf
[validLen
++] = static_cast<char>(chAttr
);
158 void SetLevel(int line
, int level
) {
159 pAccess
->SetLevel(line
, level
);
161 void IndicatorFill(int start
, int end
, int indicator
, int value
) {
162 pAccess
->DecorationSetCurrentIndicator(indicator
);
163 pAccess
->DecorationFillRange(start
, value
, end
- start
);
166 void ChangeLexerState(int start
, int end
) {
167 pAccess
->ChangeLexerState(start
, end
);