aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/LexHTML.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'src/LexHTML.cxx')
-rw-r--r--src/LexHTML.cxx106
1 files changed, 60 insertions, 46 deletions
diff --git a/src/LexHTML.cxx b/src/LexHTML.cxx
index 97be5f08f..c9ef389de 100644
--- a/src/LexHTML.cxx
+++ b/src/LexHTML.cxx
@@ -40,6 +40,20 @@ static inline bool IsAWordStart(const int ch) {
return (ch < 0x80) && (isalnum(ch) || ch == '_');
}
+inline bool IsOperator(int ch) {
+ if (isascii(ch) && isalnum(ch))
+ return false;
+ // '.' left out as it is used to make up numbers
+ if (ch == '%' || ch == '^' || ch == '&' || ch == '*' ||
+ ch == '(' || ch == ')' || ch == '-' || ch == '+' ||
+ ch == '=' || ch == '|' || ch == '{' || ch == '}' ||
+ ch == '[' || ch == ']' || ch == ':' || ch == ';' ||
+ ch == '<' || ch == '>' || ch == ',' || ch == '/' ||
+ ch == '?' || ch == '!' || ch == '.' || ch == '~')
+ return true;
+ return false;
+}
+
static inline int MakeLowerCase(int ch) {
if (ch < 'A' || ch > 'Z')
return ch;
@@ -404,21 +418,21 @@ static int StateForScript(script_type scriptLanguage) {
return Result;
}
-static inline bool ishtmlwordchar(char ch) {
+static inline bool ishtmlwordchar(int ch) {
return !isascii(ch) ||
(isalnum(ch) || ch == '.' || ch == '-' || ch == '_' || ch == ':' || ch == '!' || ch == '#');
}
-static inline bool issgmlwordchar(char ch) {
+static inline bool issgmlwordchar(int ch) {
return !isascii(ch) ||
(isalnum(ch) || ch == '.' || ch == '_' || ch == ':' || ch == '!' || ch == '#' || ch == '[');
}
-static inline bool IsPhpWordStart(const unsigned char ch) {
+static inline bool IsPhpWordStart(int ch) {
return (isascii(ch) && (isalpha(ch) || (ch == '_'))) || (ch >= 0x7f);
}
-static inline bool IsPhpWordChar(char ch) {
+static inline bool IsPhpWordChar(int ch) {
return IsADigit(ch) || IsPhpWordStart(ch);
}
@@ -439,11 +453,11 @@ static bool IsScriptCommentState(const int state) {
state == SCE_HJA_COMMENTLINE || state == SCE_HB_COMMENTLINE || state == SCE_HBA_COMMENTLINE;
}
-static bool isLineEnd(char ch) {
+static bool isLineEnd(int ch) {
return ch == '\r' || ch == '\n';
}
-static bool isOKBeforeRE(char ch) {
+static bool isOKBeforeRE(int ch) {
return (ch == '(') || (ch == '=') || (ch == ',');
}
@@ -537,9 +551,9 @@ static void ColouriseHyperTextDoc(unsigned int startPos, int length, int initSty
int levelCurrent = levelPrev;
int visibleChars = 0;
- char chPrev = ' ';
- char ch = ' ';
- char chPrevNonWhite = ' ';
+ int chPrev = ' ';
+ int ch = ' ';
+ int chPrevNonWhite = ' ';
// look back to set chPrevNonWhite properly for better regex colouring
if (scriptLanguage == eScriptJS && startPos > 0) {
int back = startPos;
@@ -558,23 +572,23 @@ static void ColouriseHyperTextDoc(unsigned int startPos, int length, int initSty
styler.StartSegment(startPos);
const int lengthDoc = startPos + length;
for (int i = startPos; i < lengthDoc; i++) {
- const char chPrev2 = chPrev;
+ const int chPrev2 = chPrev;
chPrev = ch;
- if (!isspacechar(ch) && state != SCE_HJ_COMMENT &&
+ if (!IsASpace(ch) && state != SCE_HJ_COMMENT &&
state != SCE_HJ_COMMENTLINE && state != SCE_HJ_COMMENTDOC)
chPrevNonWhite = ch;
- ch = styler[i];
- char chNext = styler.SafeGetCharAt(i + 1);
- const char chNext2 = styler.SafeGetCharAt(i + 2);
+ ch = static_cast<unsigned char>(styler[i]);
+ int chNext = static_cast<unsigned char>(styler.SafeGetCharAt(i + 1));
+ const int chNext2 = static_cast<unsigned char>(styler.SafeGetCharAt(i + 2));
// Handle DBCS codepages
- if (styler.IsLeadByte(ch)) {
+ if (styler.IsLeadByte(static_cast<char>(ch))) {
chPrev = ' ';
i += 1;
continue;
}
- if ((!isspacechar(ch) || !foldCompact) && fold)
+ if ((!IsASpace(ch) || !foldCompact) && fold)
visibleChars++;
// decide what is the current state to print (depending of the script tag)
@@ -677,7 +691,7 @@ static void ColouriseHyperTextDoc(unsigned int startPos, int length, int initSty
char chr; // current char
int j=0;
chr = styler.SafeGetCharAt(i+2);
- while (j < 6 && !isspacechar(chr)) {
+ while (j < 6 && !IsASpace(chr)) {
tag[j++] = static_cast<char>(MakeLowerCase(chr));
chr = styler.SafeGetCharAt(i+2+j);
}
@@ -1218,7 +1232,7 @@ static void ColouriseHyperTextDoc(unsigned int startPos, int length, int initSty
case SCE_HJ_DEFAULT:
case SCE_HJ_START:
case SCE_HJ_SYMBOLS:
- if (iswordstart(ch)) {
+ if (IsAWordStart(ch)) {
styler.ColourTo(i - 1, StateToPrint);
state = SCE_HJ_WORD;
} else if (ch == '/' && chNext == '*') {
@@ -1247,7 +1261,7 @@ static void ColouriseHyperTextDoc(unsigned int startPos, int length, int initSty
styler.ColourTo(i - 1, StateToPrint);
state = SCE_HJ_COMMENTLINE;
i += 2;
- } else if (isoperator(ch)) {
+ } else if (IsOperator(ch)) {
styler.ColourTo(i - 1, StateToPrint);
styler.ColourTo(i, statePrintForState(SCE_HJ_SYMBOLS, inScriptType));
state = SCE_HJ_DEFAULT;
@@ -1259,7 +1273,7 @@ static void ColouriseHyperTextDoc(unsigned int startPos, int length, int initSty
}
break;
case SCE_HJ_WORD:
- if (!iswordchar(ch)) {
+ if (!IsAWordChar(ch)) {
classifyWordHTJS(styler.GetStartSegment(), i - 1, keywords2, styler, inScriptType);
//styler.ColourTo(i - 1, eHTJSKeyword);
state = SCE_HJ_DEFAULT;
@@ -1278,7 +1292,7 @@ static void ColouriseHyperTextDoc(unsigned int startPos, int length, int initSty
styler.ColourTo(i - 1, StateToPrint);
state = SCE_HJ_COMMENTLINE;
i += 2;
- } else if (isoperator(ch)) {
+ } else if (IsOperator(ch)) {
styler.ColourTo(i, statePrintForState(SCE_HJ_SYMBOLS, inScriptType));
state = SCE_HJ_DEFAULT;
}
@@ -1364,7 +1378,7 @@ static void ColouriseHyperTextDoc(unsigned int startPos, int length, int initSty
break;
case SCE_HB_DEFAULT:
case SCE_HB_START:
- if (iswordstart(ch)) {
+ if (IsAWordStart(ch)) {
styler.ColourTo(i - 1, StateToPrint);
state = SCE_HB_WORD;
} else if (ch == '\'') {
@@ -1377,7 +1391,7 @@ static void ColouriseHyperTextDoc(unsigned int startPos, int length, int initSty
styler.SafeGetCharAt(i + 3) == '-') {
styler.ColourTo(i - 1, StateToPrint);
state = SCE_HB_COMMENTLINE;
- } else if (isoperator(ch)) {
+ } else if (IsOperator(ch)) {
styler.ColourTo(i - 1, StateToPrint);
styler.ColourTo(i, statePrintForState(SCE_HB_DEFAULT, inScriptType));
state = SCE_HB_DEFAULT;
@@ -1389,14 +1403,14 @@ static void ColouriseHyperTextDoc(unsigned int startPos, int length, int initSty
}
break;
case SCE_HB_WORD:
- if (!iswordchar(ch)) {
+ if (!IsAWordChar(ch)) {
state = classifyWordHTVB(styler.GetStartSegment(), i - 1, keywords3, styler, inScriptType);
if (state == SCE_HB_DEFAULT) {
if (ch == '\"') {
state = SCE_HB_STRING;
} else if (ch == '\'') {
state = SCE_HB_COMMENTLINE;
- } else if (isoperator(ch)) {
+ } else if (IsOperator(ch)) {
styler.ColourTo(i, statePrintForState(SCE_HB_DEFAULT, inScriptType));
state = SCE_HB_DEFAULT;
}
@@ -1429,7 +1443,7 @@ static void ColouriseHyperTextDoc(unsigned int startPos, int length, int initSty
break;
case SCE_HP_DEFAULT:
case SCE_HP_START:
- if (iswordstart(ch)) {
+ if (IsAWordStart(ch)) {
styler.ColourTo(i - 1, StateToPrint);
state = SCE_HP_WORD;
} else if ((ch == '<') && (chNext == '!') && (chNext2 == '-') &&
@@ -1462,7 +1476,7 @@ static void ColouriseHyperTextDoc(unsigned int startPos, int length, int initSty
} else {
state = SCE_HP_CHARACTER;
}
- } else if (isoperator(ch)) {
+ } else if (IsOperator(ch)) {
styler.ColourTo(i - 1, StateToPrint);
styler.ColourTo(i, statePrintForState(SCE_HP_OPERATOR, inScriptType));
} else if ((ch == ' ') || (ch == '\t')) {
@@ -1473,7 +1487,7 @@ static void ColouriseHyperTextDoc(unsigned int startPos, int length, int initSty
}
break;
case SCE_HP_WORD:
- if (!iswordchar(ch)) {
+ if (!IsAWordChar(ch)) {
classifyWordHTPy(styler.GetStartSegment(), i - 1, keywords4, styler, prevWord, inScriptType);
state = SCE_HP_DEFAULT;
if (ch == '#') {
@@ -1498,7 +1512,7 @@ static void ColouriseHyperTextDoc(unsigned int startPos, int length, int initSty
} else {
state = SCE_HP_CHARACTER;
}
- } else if (isoperator(ch)) {
+ } else if (IsOperator(ch)) {
styler.ColourTo(i, statePrintForState(SCE_HP_OPERATOR, inScriptType));
}
}
@@ -1547,7 +1561,7 @@ static void ColouriseHyperTextDoc(unsigned int startPos, int length, int initSty
break;
///////////// start - PHP state handling
case SCE_HPHP_WORD:
- if (!iswordchar(ch)) {
+ if (!IsAWordChar(ch)) {
classifyWordHTPHP(styler.GetStartSegment(), i - 1, keywords5, styler);
if (ch == '/' && chNext == '*') {
i++;
@@ -1567,7 +1581,7 @@ static void ColouriseHyperTextDoc(unsigned int startPos, int length, int initSty
state = SCE_HPHP_SIMPLESTRING;
} else if (ch == '$' && IsPhpWordStart(chNext)) {
state = SCE_HPHP_VARIABLE;
- } else if (isoperator(ch)) {
+ } else if (IsOperator(ch)) {
state = SCE_HPHP_OPERATOR;
} else {
state = SCE_HPHP_DEFAULT;
@@ -1580,7 +1594,7 @@ static void ColouriseHyperTextDoc(unsigned int startPos, int length, int initSty
&& strchr(".xXabcdefABCDEF", ch) == NULL
&& ((ch != '-' && ch != '+') || (chPrev != 'e' && chPrev != 'E'))) {
styler.ColourTo(i - 1, SCE_HPHP_NUMBER);
- if (isoperator(ch))
+ if (IsOperator(ch))
state = SCE_HPHP_OPERATOR;
else
state = SCE_HPHP_DEFAULT;
@@ -1589,7 +1603,7 @@ static void ColouriseHyperTextDoc(unsigned int startPos, int length, int initSty
case SCE_HPHP_VARIABLE:
if (!IsPhpWordChar(ch)) {
styler.ColourTo(i - 1, SCE_HPHP_VARIABLE);
- if (isoperator(ch))
+ if (IsOperator(ch))
state = SCE_HPHP_OPERATOR;
else
state = SCE_HPHP_DEFAULT;
@@ -1653,7 +1667,7 @@ static void ColouriseHyperTextDoc(unsigned int startPos, int length, int initSty
styler.ColourTo(i - 1, StateToPrint);
if (IsADigit(ch) || (ch == '.' && IsADigit(chNext))) {
state = SCE_HPHP_NUMBER;
- } else if (iswordstart(ch)) {
+ } else if (IsAWordStart(ch)) {
state = SCE_HPHP_WORD;
} else if (ch == '/' && chNext == '*') {
i++;
@@ -1673,9 +1687,9 @@ static void ColouriseHyperTextDoc(unsigned int startPos, int length, int initSty
state = SCE_HPHP_SIMPLESTRING;
} else if (ch == '$' && IsPhpWordStart(chNext)) {
state = SCE_HPHP_VARIABLE;
- } else if (isoperator(ch)) {
+ } else if (IsOperator(ch)) {
state = SCE_HPHP_OPERATOR;
- } else if ((state == SCE_HPHP_OPERATOR) && (isspacechar(ch))) {
+ } else if ((state == SCE_HPHP_OPERATOR) && (IsASpace(ch))) {
state = SCE_HPHP_DEFAULT;
}
break;
@@ -1691,9 +1705,9 @@ static void ColouriseHyperTextDoc(unsigned int startPos, int length, int initSty
state = SCE_HB_STRING;
} else if (ch == '\'') {
state = SCE_HB_COMMENTLINE;
- } else if (iswordstart(ch)) {
+ } else if (IsAWordStart(ch)) {
state = SCE_HB_WORD;
- } else if (isoperator(ch)) {
+ } else if (IsOperator(ch)) {
styler.ColourTo(i, SCE_HB_DEFAULT);
}
} else if (state == SCE_HBA_DEFAULT) { // One of the above succeeded
@@ -1701,9 +1715,9 @@ static void ColouriseHyperTextDoc(unsigned int startPos, int length, int initSty
state = SCE_HBA_STRING;
} else if (ch == '\'') {
state = SCE_HBA_COMMENTLINE;
- } else if (iswordstart(ch)) {
+ } else if (IsAWordStart(ch)) {
state = SCE_HBA_WORD;
- } else if (isoperator(ch)) {
+ } else if (IsOperator(ch)) {
styler.ColourTo(i, SCE_HBA_DEFAULT);
}
} else if (state == SCE_HJ_DEFAULT) { // One of the above succeeded
@@ -1718,9 +1732,9 @@ static void ColouriseHyperTextDoc(unsigned int startPos, int length, int initSty
state = SCE_HJ_DOUBLESTRING;
} else if ((ch == '\'') && (nonEmptySegment)) {
state = SCE_HJ_SINGLESTRING;
- } else if (iswordstart(ch)) {
+ } else if (IsAWordStart(ch)) {
state = SCE_HJ_WORD;
- } else if (isoperator(ch)) {
+ } else if (IsOperator(ch)) {
styler.ColourTo(i, statePrintForState(SCE_HJ_SYMBOLS, inScriptType));
}
}
@@ -1822,7 +1836,7 @@ static void ColouriseHTMLPiece(StyleContext &sc, WordList *keywordlists[]) {
sc.SetState(SCE_H_DEFAULT);
}
} else if (sc.state == SCE_H_TAGUNKNOWN) {
- if (!ishtmlwordchar(static_cast<char>(sc.ch)) && !((sc.ch == '/') && (sc.chPrev == '<')) && sc.ch != '[') {
+ if (!ishtmlwordchar(sc.ch) && !((sc.ch == '/') && (sc.chPrev == '<')) && sc.ch != '[') {
char s[100];
sc.GetCurrentLowered(s, sizeof(s));
if (s[1] == '/') {
@@ -1845,7 +1859,7 @@ static void ColouriseHTMLPiece(StyleContext &sc, WordList *keywordlists[]) {
}
}
} else if (sc.state == SCE_H_ATTRIBUTE) {
- if (!ishtmlwordchar(static_cast<char>(sc.ch))) {
+ if (!ishtmlwordchar(sc.ch)) {
char s[100];
sc.GetCurrentLowered(s, sizeof(s));
if (!keywordsTags.InList(s)) {
@@ -1897,7 +1911,7 @@ static void ColouriseHTMLPiece(StyleContext &sc, WordList *keywordlists[]) {
} else if (sc.ch == '>') {
sc.SetState(SCE_H_TAG);
sc.ForwardSetState(SCE_H_DEFAULT);
- } else if (ishtmlwordchar(static_cast<char>(sc.ch))) {
+ } else if (ishtmlwordchar(sc.ch)) {
sc.SetState(SCE_H_ATTRIBUTE);
}
}
@@ -2025,7 +2039,7 @@ static void ColourisePHPPiece(StyleContext &sc, WordList *keywordlists[]) {
sc.SetState(SCE_HPHP_SIMPLESTRING);
} else if (sc.ch == '$' && IsPhpWordStart(static_cast<char>(sc.chNext))) {
sc.SetState(SCE_HPHP_VARIABLE);
- } else if (isoperator(static_cast<char>(sc.ch))) {
+ } else if (IsOperator(static_cast<char>(sc.ch))) {
sc.SetState(SCE_HPHP_OPERATOR);
}
}