aboutsummaryrefslogtreecommitdiffhomepage
path: root/lexers/LexOthers.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'lexers/LexOthers.cxx')
-rw-r--r--lexers/LexOthers.cxx21
1 files changed, 16 insertions, 5 deletions
diff --git a/lexers/LexOthers.cxx b/lexers/LexOthers.cxx
index 5f4eaed2d..259059fd9 100644
--- a/lexers/LexOthers.cxx
+++ b/lexers/LexOthers.cxx
@@ -500,6 +500,10 @@ static void ColouriseBatchDoc(
}
}
+#define DIFF_BUFFER_START_SIZE 16
+// Note that ColouriseDiffLine analyzes only the first DIFF_BUFFER_START_SIZE
+// characters of each line to classify the line.
+
static void ColouriseDiffLine(char *lineBuffer, int endLine, Accessor &styler) {
// It is needed to remember the current state to recognize starting
// comment lines before the first "diff " or "--- ". If a real
@@ -556,20 +560,27 @@ static void ColouriseDiffLine(char *lineBuffer, int endLine, Accessor &styler) {
}
static void ColouriseDiffDoc(unsigned int startPos, int length, int, WordList *[], Accessor &styler) {
- char lineBuffer[1024];
+ char lineBuffer[DIFF_BUFFER_START_SIZE];
styler.StartAt(startPos);
styler.StartSegment(startPos);
unsigned int linePos = 0;
for (unsigned int i = startPos; i < startPos + length; i++) {
- lineBuffer[linePos++] = styler[i];
- if (AtEOL(styler, i) || (linePos >= sizeof(lineBuffer) - 1)) {
- // End of line (or of line buffer) met, colourise it
- lineBuffer[linePos] = '\0';
+ if (AtEOL(styler, i)) {
+ if (linePos < DIFF_BUFFER_START_SIZE) {
+ lineBuffer[linePos] = 0;
+ }
ColouriseDiffLine(lineBuffer, i, styler);
linePos = 0;
+ } else if (linePos < DIFF_BUFFER_START_SIZE - 1) {
+ lineBuffer[linePos++] = styler[i];
+ } else if (linePos == DIFF_BUFFER_START_SIZE - 1) {
+ lineBuffer[linePos++] = 0;
}
}
if (linePos > 0) { // Last line does not have ending characters
+ if (linePos < DIFF_BUFFER_START_SIZE) {
+ lineBuffer[linePos] = 0;
+ }
ColouriseDiffLine(lineBuffer, startPos + length - 1, styler);
}
}