diff options
Diffstat (limited to 'src/Accessor.cxx')
-rw-r--r-- | src/Accessor.cxx | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/src/Accessor.cxx b/src/Accessor.cxx index 60c5968c5..f080742bd 100644 --- a/src/Accessor.cxx +++ b/src/Accessor.cxx @@ -4,6 +4,7 @@ // The License.txt file describes the conditions under which this software may be distributed. #include <stdlib.h> +#include <ctype.h> #include <stdio.h> #include "Platform.h" @@ -12,6 +13,17 @@ #include "Accessor.h" #include "Scintilla.h" +bool Accessor::InternalIsLeadByte(char ch) { +#if PLAT_GTK + // TODO: support DBCS under GTK+ + return false; +#elif PLAT_WIN + return IsDBCSLeadByteEx(codePage, ch); +#elif PLAT_WX + return false; +#endif +} + void Accessor::Fill(int position) { if (lenDoc == -1) lenDoc = Platform::SendScintilla(id, WM_GETTEXTLENGTH, 0, 0); @@ -106,3 +118,49 @@ void StylingContext::Flush() { validLen = 0; } } + +int StylingContext::IndentAmount(int line, int *flags, PFNIsCommentLeader pfnIsCommentLeader) { + int end = Length(); + int spaceFlags = 0; + + // Determines the indentation level of the current line and also checks for consistent + // indentation compared to the previous line. + // Indentation is judged consistent when the indentation whitespace of each line lines + // the same or the indentation of one line is a prefix of the other. + + int pos = LineStart(line); + char ch = (*this)[pos]; + int indent = 0; + bool inPrevPrefix = line > 0; + int posPrev = inPrevPrefix ? LineStart(line-1) : 0; + while ((ch == ' ' || ch == '\t') && (pos < end)) { + if (inPrevPrefix) { + char chPrev = (*this)[posPrev++]; + if (chPrev == ' ' || chPrev == '\t') { + if (chPrev != ch) + spaceFlags |= wsInconsistent; + } else { + inPrevPrefix = false; + } + } + if (ch == ' ') { + spaceFlags |= wsSpace; + indent++; + } else { // Tab + spaceFlags |= wsTab; + if (spaceFlags & wsSpace) + spaceFlags |= wsSpaceTab; + indent = (indent / 8 + 1) * 8; + } + ch = (*this)[++pos]; + } + + *flags = spaceFlags; + indent += SC_FOLDLEVELBASE; + // if completely empty line or the start of a comment... + if (isspace(ch) || (pfnIsCommentLeader && (*pfnIsCommentLeader)(*this, pos, end-pos)) ) + return indent | SC_FOLDLEVELWHITEFLAG; + else + return indent; +} + |