]> git.saurik.com Git - wxWidgets.git/blob - src/stc/scintilla/lexlib/Accessor.cxx
Define __VISUALC__ for ICC under Windows again.
[wxWidgets.git] / src / stc / scintilla / lexlib / Accessor.cxx
1 // Scintilla source code edit control
2 /** @file KeyWords.cxx
3 ** Colourise for particular languages.
4 **/
5 // Copyright 1998-2002 by Neil Hodgson <neilh@scintilla.org>
6 // The License.txt file describes the conditions under which this software may be distributed.
7
8 #include <stdlib.h>
9 #include <string.h>
10 #include <stdio.h>
11 #include <stdarg.h>
12 #include <assert.h>
13 #include <ctype.h>
14
15 #include "ILexer.h"
16 #include "Scintilla.h"
17 #include "SciLexer.h"
18
19 #include "PropSetSimple.h"
20 #include "WordList.h"
21 #include "LexAccessor.h"
22 #include "Accessor.h"
23
24 #ifdef SCI_NAMESPACE
25 using namespace Scintilla;
26 #endif
27
28 Accessor::Accessor(IDocument *pAccess_, PropSetSimple *pprops_) : LexAccessor(pAccess_), pprops(pprops_) {
29 }
30
31 int Accessor::GetPropertyInt(const char *key, int defaultValue) {
32 return pprops->GetInt(key, defaultValue);
33 }
34
35 int Accessor::IndentAmount(int line, int *flags, PFNIsCommentLeader pfnIsCommentLeader) {
36 int end = Length();
37 int spaceFlags = 0;
38
39 // Determines the indentation level of the current line and also checks for consistent
40 // indentation compared to the previous line.
41 // Indentation is judged consistent when the indentation whitespace of each line lines
42 // the same or the indentation of one line is a prefix of the other.
43
44 int pos = LineStart(line);
45 char ch = (*this)[pos];
46 int indent = 0;
47 bool inPrevPrefix = line > 0;
48 int posPrev = inPrevPrefix ? LineStart(line-1) : 0;
49 while ((ch == ' ' || ch == '\t') && (pos < end)) {
50 if (inPrevPrefix) {
51 char chPrev = (*this)[posPrev++];
52 if (chPrev == ' ' || chPrev == '\t') {
53 if (chPrev != ch)
54 spaceFlags |= wsInconsistent;
55 } else {
56 inPrevPrefix = false;
57 }
58 }
59 if (ch == ' ') {
60 spaceFlags |= wsSpace;
61 indent++;
62 } else { // Tab
63 spaceFlags |= wsTab;
64 if (spaceFlags & wsSpace)
65 spaceFlags |= wsSpaceTab;
66 indent = (indent / 8 + 1) * 8;
67 }
68 ch = (*this)[++pos];
69 }
70
71 *flags = spaceFlags;
72 indent += SC_FOLDLEVELBASE;
73 // if completely empty line or the start of a comment...
74 if ((LineStart(line) == Length()) || (ch == ' ' || ch == '\t' || ch == '\n' || ch == '\r') ||
75 (pfnIsCommentLeader && (*pfnIsCommentLeader)(*this, pos, end-pos)))
76 return indent | SC_FOLDLEVELWHITEFLAG;
77 else
78 return indent;
79 }