1 // SciTE - Scintilla based Text Editor
2 // Accessor.h - rapid easy access to contents of a Scintilla
3 // Copyright 1998-2000 by Neil Hodgson <neilh@scintilla.org>
4 // The License.txt file describes the conditions under which this software may be distributed.
6 enum { wsSpace
= 1, wsTab
= 2, wsSpaceTab
= 4, wsInconsistent
=8};
10 // bufferSize is a trade off between time taken to copy the characters and SendMessage overhead
11 // slopSize positions the buffer before the desired position in case there is some backtracking
12 enum {bufferSize
=4000, slopSize
=bufferSize
/8};
13 char buf
[bufferSize
+1];
19 int offset
; // Optional but including an offset makes GCC generate better code
21 bool InternalIsLeadByte(char ch
);
22 void Fill(int position
);
24 Accessor(WindowID id_
, PropSet
&props_
, int offset_
=0) :
25 id(id_
), props(props_
), startPos(0x7FFFFFFF), endPos(0),
26 lenDoc(-1), offset(offset_
), codePage(0) {
28 void SetCodePage(int codePage_
) { codePage
= codePage_
; }
29 char operator[](int position
) {
31 if (position
< startPos
|| position
>= endPos
) {
34 return buf
[position
- startPos
];
36 char SafeGetCharAt(int position
, char chDefault
=' ') {
37 // Safe version of operator[], returning a defined value for invalid position
39 if (position
< startPos
|| position
>= endPos
) {
41 if (position
< startPos
|| position
>= endPos
) {
42 // Position is outside range of document
46 return buf
[position
- startPos
];
48 bool IsLeadByte(char ch
) {
49 return codePage
&& InternalIsLeadByte(ch
);
51 char StyleAt(int position
);
52 int GetLine(int position
);
53 int LineStart(int line
);
54 int LevelAt(int line
);
57 startPos
= 0x7FFFFFFF;
60 int GetLineState(int line
);
61 int SetLineState(int line
, int state
);
62 PropSet
&GetPropSet() { return props
; }
67 typedef bool (*PFNIsCommentLeader
)(StylingContext
&styler
, int pos
, int len
);
69 class StylingContext
: public Accessor
{
70 char styleBuf
[bufferSize
];
74 unsigned int startSeg
;
76 StylingContext(WindowID id_
, PropSet
&props_
, int offset_
=0) :
77 Accessor(id_
,props_
,offset_
), validLen(0), chFlags(0) {}
78 void StartAt(unsigned int start
, char chMask
=31);
79 void SetFlags(char chFlags_
, char chWhile_
) {chFlags
= chFlags_
; chWhile
= chWhile_
; };
80 unsigned int GetStartSegment() { return startSeg
; }
81 void StartSegment(unsigned int pos
);
82 void ColourTo(unsigned int pos
, int chAttr
);
83 int GetLine(int position
);
84 void SetLevel(int line
, int level
);
86 int IndentAmount(int line
, int *flags
, PFNIsCommentLeader pfnIsCommentLeader
= 0);