geany  1.38
About: Geany is a text editor (using GTK2) with basic features of an integrated development environment (syntax highlighting, code folding, symbol name auto-completion, ...). F: office T: editor programming GTK+ IDE
  Fossies Dox: geany-1.38.tar.bz2  ("unofficial" and yet experimental doxygen-generated source code documentation)  

LexAccessor.h
Go to the documentation of this file.
1// Scintilla source code edit control
2/** @file LexAccessor.h
3 ** Interfaces between Scintilla and lexers.
4 **/
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.
7
8#ifndef LEXACCESSOR_H
9#define LEXACCESSOR_H
10
11namespace Scintilla {
12
14
16private:
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. */
24 char buf[bufferSize+1];
35
40 if (startPos < 0)
41 startPos = 0;
43 if (endPos > lenDoc)
44 endPos = lenDoc;
45
47 buf[endPos-startPos] = '\0';
48 }
49
50public:
51 explicit LexAccessor(IDocument *pAccess_) :
52 pAccess(pAccess_), startPos(extremePosition), endPos(0),
53 codePage(pAccess->CodePage()),
56 validLen(0),
58 documentVersion(pAccess->Version()) {
59 // Prevent warnings by static analyzers about uninitialized buf and styleBuf.
60 buf[0] = 0;
61 styleBuf[0] = 0;
62 switch (codePage) {
63 case 65001:
65 break;
66 case 932:
67 case 936:
68 case 949:
69 case 950:
70 case 1361:
72 }
73 }
75 if (position < startPos || position >= endPos) {
77 }
78 return buf[position - startPos];
79 }
82 return static_cast<IDocumentWithLineEnd *>(pAccess);
83 }
84 return 0;
85 }
86 /** Safe version of operator[], returning a defined value for invalid position. */
87 char SafeGetCharAt(Sci_Position position, char chDefault=' ') {
88 if (position < startPos || position >= endPos) {
90 if (position < startPos || position >= endPos) {
91 // Position is outside range of document
92 return chDefault;
93 }
94 }
95 return buf[position - startPos];
96 }
97 bool IsLeadByte(char ch) const {
98 return pAccess->IsDBCSLeadByte(ch);
99 }
100 EncodingType Encoding() const noexcept {
101 return encodingType;
102 }
103 bool Match(Sci_Position pos, const char *s) {
104 for (int i=0; *s; i++) {
105 if (*s != SafeGetCharAt(pos+i))
106 return false;
107 s++;
108 }
109 return true;
110 }
112 return pAccess->StyleAt(position);
113 }
116 }
118 return pAccess->LineStart(line);
119 }
121 if (documentVersion >= dvLineEnd) {
122 return (static_cast<IDocumentWithLineEnd *>(pAccess))->LineEnd(line);
123 } else {
124 // Old interface means only '\r', '\n' and '\r\n' line ends.
125 Sci_Position startNext = pAccess->LineStart(line+1);
126 const char chLineEnd = SafeGetCharAt(startNext-1);
127 if (chLineEnd == '\n' && (SafeGetCharAt(startNext-2) == '\r'))
128 return startNext - 2;
129 else
130 return startNext - 1;
131 }
132 }
134 return pAccess->GetLevel(line);
135 }
137 return lenDoc;
138 }
139 void Flush() {
140 if (validLen > 0) {
143 validLen = 0;
144 }
145 }
147 return pAccess->GetLineState(line);
148 }
150 return pAccess->SetLineState(line, state);
151 }
152 // Style setting
153 void StartAt(Sci_PositionU start) {
154 pAccess->StartStyling(start, '\377');
155 startPosStyling = start;
156 }
158 return startSeg;
159 }
161 startSeg = pos;
162 }
163 void ColourTo(Sci_PositionU pos, int chAttr) {
164 // Only perform styling if non empty range
165 if (pos != startSeg - 1) {
166 assert(pos >= startSeg);
167 if (pos < startSeg) {
168 return;
169 }
170
171 if (validLen + (pos - startSeg + 1) >= bufferSize)
172 Flush();
173 const char attr = static_cast<char>(chAttr);
174 if (validLen + (pos - startSeg + 1) >= bufferSize) {
175 // Too big for buffer so send directly
176 pAccess->SetStyleFor(pos - startSeg + 1, attr);
177 } else {
178 for (Sci_PositionU i = startSeg; i <= pos; i++) {
179 assert((startPosStyling + validLen) < Length());
180 styleBuf[validLen++] = attr;
181 }
182 }
183 }
184 startSeg = pos+1;
185 }
186 void SetLevel(Sci_Position line, int level) {
187 pAccess->SetLevel(line, level);
188 }
189 void IndicatorFill(Sci_Position start, Sci_Position end, int indicator, int value) {
191 pAccess->DecorationFillRange(start, value, end - start);
192 }
193
195 pAccess->ChangeLexerState(start, end);
196 }
197};
198
200 int value;
201 const char *name;
202 const char *tags;
203 const char *description;
204};
205
206}
207
208#endif
ptrdiff_t Sci_Position
Definition: Sci_Position.h:15
size_t Sci_PositionU
Definition: Sci_Position.h:18
virtual void GetCharRange(char *buffer, Sci_Position position, Sci_Position lengthRetrieve) const =0
virtual bool SetStyles(Sci_Position length, const char *styles)=0
virtual void ChangeLexerState(Sci_Position start, Sci_Position end)=0
virtual int SetLevel(Sci_Position line, int level)=0
virtual char StyleAt(Sci_Position position) const =0
virtual int GetLineState(Sci_Position line) const =0
virtual void DecorationFillRange(Sci_Position position, int value, Sci_Position fillLength)=0
virtual void StartStyling(Sci_Position position, char mask)=0
virtual Sci_Position LineFromPosition(Sci_Position position) const =0
virtual Sci_Position LineStart(Sci_Position line) const =0
virtual int GetLevel(Sci_Position line) const =0
virtual bool SetStyleFor(Sci_Position length, char style)=0
virtual void DecorationSetCurrentIndicator(int indicator)=0
virtual bool IsDBCSLeadByte(char ch) const =0
virtual int SetLineState(Sci_Position line, int state)=0
enum EncodingType encodingType
Definition: LexAccessor.h:28
EncodingType Encoding() const noexcept
Definition: LexAccessor.h:100
Sci_PositionU GetStartSegment() const
Definition: LexAccessor.h:157
int GetLineState(Sci_Position line) const
Definition: LexAccessor.h:146
char SafeGetCharAt(Sci_Position position, char chDefault=' ')
Safe version of operator[], returning a defined value for invalid position.
Definition: LexAccessor.h:87
char buf[bufferSize+1]
Definition: LexAccessor.h:24
Sci_Position LineEnd(Sci_Position line)
Definition: LexAccessor.h:120
char StyleAt(Sci_Position position) const
Definition: LexAccessor.h:111
void Fill(Sci_Position position)
Definition: LexAccessor.h:36
Sci_Position Length() const
Definition: LexAccessor.h:136
Sci_Position GetLine(Sci_Position position) const
Definition: LexAccessor.h:114
Sci_PositionU startSeg
Definition: LexAccessor.h:32
void IndicatorFill(Sci_Position start, Sci_Position end, int indicator, int value)
Definition: LexAccessor.h:189
int LevelAt(Sci_Position line) const
Definition: LexAccessor.h:133
Sci_Position validLen
Definition: LexAccessor.h:31
void SetLevel(Sci_Position line, int level)
Definition: LexAccessor.h:186
char styleBuf[bufferSize]
Definition: LexAccessor.h:30
Sci_Position endPos
Definition: LexAccessor.h:26
int SetLineState(Sci_Position line, int state)
Definition: LexAccessor.h:149
Sci_Position lenDoc
Definition: LexAccessor.h:29
char operator[](Sci_Position position)
Definition: LexAccessor.h:74
void StartAt(Sci_PositionU start)
Definition: LexAccessor.h:153
IDocumentWithLineEnd * MultiByteAccess() const noexcept
Definition: LexAccessor.h:80
bool Match(Sci_Position pos, const char *s)
Definition: LexAccessor.h:103
Sci_Position LineStart(Sci_Position line) const
Definition: LexAccessor.h:117
void ColourTo(Sci_PositionU pos, int chAttr)
Definition: LexAccessor.h:163
void ChangeLexerState(Sci_Position start, Sci_Position end)
Definition: LexAccessor.h:194
Sci_Position startPos
Definition: LexAccessor.h:25
void StartSegment(Sci_PositionU pos)
Definition: LexAccessor.h:160
LexAccessor(IDocument *pAccess_)
Definition: LexAccessor.h:51
Sci_Position startPosStyling
Definition: LexAccessor.h:33
bool IsLeadByte(char ch) const
Definition: LexAccessor.h:97
gint pos
Definition: editor.c:87
vString * line
Definition: geany_cobol.c:133
Styling buffer using one element for each run rather than using a filled buffer.
Definition: Converter.h:9
@ dvLineEnd
Definition: ILexer.h:15
gint position[2]
Definition: search.c:120
const char * description
Definition: LexAccessor.h:203