diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/EditView.cxx | 64 |
1 files changed, 35 insertions, 29 deletions
diff --git a/src/EditView.cxx b/src/EditView.cxx index 727efbcdd..7ce152489 100644 --- a/src/EditView.cxx +++ b/src/EditView.cxx @@ -344,6 +344,34 @@ LineLayout *EditView::RetrieveLineLayout(Sci::Line lineNumber, const EditModel & model.LinesOnScreen() + 1, model.pdoc->LinesTotal()); } +namespace { + +/** +* Return the chDoc argument with case transformed as indicated by the caseForce argument. +* chPrevious is needed for camel casing. +* This only affects ASCII characters and is provided for languages with case-insensitive +* ASCII keywords where the user wishes to view keywords in a preferred case. +*/ +inline char CaseForce(Style::ecaseForced caseForce, char chDoc, char chPrevious) { + switch (caseForce) { + case Style::caseMixed: + return chDoc; + case Style::caseLower: + return MakeLowerCase(chDoc); + case Style::caseUpper: + return MakeUpperCase(chDoc); + case Style::caseCamel: + default: // default should not occur, included to avoid warnings + if (IsUpperOrLowerCase(chDoc) && !IsUpperOrLowerCase(chPrevious)) { + return MakeUpperCase(chDoc); + } else { + return MakeLowerCase(chDoc); + } + } +} + +} + /** * Fill in the LineLayout data for the given line. * Copy the given @a line and its styles from the document into local arrays. @@ -372,29 +400,16 @@ void EditView::LayoutLine(const EditModel &model, Sci::Line line, Surface *surfa // Check base line layout int styleByte = 0; int numCharsInLine = 0; + char chPrevious = 0; while (numCharsInLine < lineLength) { const Sci::Position charInDoc = numCharsInLine + posLineStart; const char chDoc = model.pdoc->CharAt(charInDoc); styleByte = model.pdoc->StyleIndexAt(charInDoc); allSame = allSame && (ll->styles[numCharsInLine] == styleByte); - if (vstyle.styles[ll->styles[numCharsInLine]].caseForce == Style::caseMixed) - allSame = allSame && - (ll->chars[numCharsInLine] == chDoc); - else if (vstyle.styles[ll->styles[numCharsInLine]].caseForce == Style::caseLower) - allSame = allSame && - (ll->chars[numCharsInLine] == MakeLowerCase(chDoc)); - else if (vstyle.styles[ll->styles[numCharsInLine]].caseForce == Style::caseUpper) - allSame = allSame && - (ll->chars[numCharsInLine] == MakeUpperCase(chDoc)); - else { // Style::caseCamel - if ((IsUpperOrLowerCase(ll->chars[numCharsInLine])) && - ((numCharsInLine == 0) || (!IsUpperOrLowerCase(ll->chars[numCharsInLine - 1])))) { - allSame = allSame && (ll->chars[numCharsInLine] == MakeUpperCase(chDoc)); - } else { - allSame = allSame && (ll->chars[numCharsInLine] == MakeLowerCase(chDoc)); - } - } + allSame = allSame && + (ll->chars[numCharsInLine] == CaseForce(vstyle.styles[styleByte].caseForce, chDoc, chPrevious)); + chPrevious = chDoc; numCharsInLine++; } allSame = allSame && (ll->styles[numCharsInLine] == styleByte); // For eolFilled @@ -428,20 +443,11 @@ void EditView::LayoutLine(const EditModel &model, Sci::Line line, Surface *surfa const int numCharsInLine = (vstyle.viewEOL) ? lineLength : numCharsBeforeEOL; const unsigned char styleByteLast = (lineLength > 0) ? ll->styles[lineLength - 1] : 0; if (vstyle.someStylesForceCase) { + char chPrevious = 0; for (int charInLine = 0; charInLine<lineLength; charInLine++) { const char chDoc = ll->chars[charInLine]; - if (vstyle.styles[ll->styles[charInLine]].caseForce == Style::caseUpper) - ll->chars[charInLine] = MakeUpperCase(chDoc); - else if (vstyle.styles[ll->styles[charInLine]].caseForce == Style::caseLower) - ll->chars[charInLine] = MakeLowerCase(chDoc); - else if (vstyle.styles[ll->styles[charInLine]].caseForce == Style::caseCamel) { - if ((IsUpperOrLowerCase(ll->chars[charInLine])) && - ((charInLine == 0) || (!IsUpperOrLowerCase(ll->chars[charInLine - 1])))) { - ll->chars[charInLine] = MakeUpperCase(chDoc); - } else { - ll->chars[charInLine] = MakeLowerCase(chDoc); - } - } + ll->chars[charInLine] = CaseForce(vstyle.styles[ll->styles[charInLine]].caseForce, chDoc, chPrevious); + chPrevious = chDoc; } } ll->xHighlightGuide = 0; |