diff options
-rw-r--r-- | include/KeyWords.h | 11 | ||||
-rw-r--r-- | src/Document.cxx | 25 | ||||
-rw-r--r-- | src/LexCPP.cxx | 6 |
3 files changed, 26 insertions, 16 deletions
diff --git a/include/KeyWords.h b/include/KeyWords.h index 3159dcc1b..95337c107 100644 --- a/include/KeyWords.h +++ b/include/KeyWords.h @@ -17,16 +17,21 @@ public: int language, WordList *keywordlists[], Accessor &styler); }; +// This is ASCII specific but is safe with chars >= 0x80 +inline bool isspacechar(unsigned char ch) { + return (ch == ' ') || ((ch >= 0x09) && (ch <= 0x0d)); +} + inline bool iswordchar(char ch) { - return isalnum(ch) || ch == '.' || ch == '_'; + return isascii(ch) && (isalnum(ch) || ch == '.' || ch == '_'); } inline bool iswordstart(char ch) { - return isalnum(ch) || ch == '_'; + return isascii(ch) && (isalnum(ch) || ch == '_'); } inline bool isoperator(char ch) { - if (isalnum(ch)) + if (isascii(ch) && isalnum(ch)) return false; // '.' left out as it is used to make up numbers if (ch == '%' || ch == '^' || ch == '&' || ch == '*' || diff --git a/src/Document.cxx b/src/Document.cxx index 3e017e25e..e65f008e9 100644 --- a/src/Document.cxx +++ b/src/Document.cxx @@ -15,6 +15,11 @@ #include "CellBuffer.h" #include "Document.h" +// This is ASCII specific but is safe with chars >= 0x80 +inline bool isspacechar(unsigned char ch) { + return (ch == ' ') || ((ch >= 0x09) && (ch <= 0x0d)); +} + Document::Document() { refCount = 0; #ifdef unix @@ -697,19 +702,19 @@ int Document::NextWordStart(int pos, int delta) { if (delta < 0) { while (pos > 0 && (cb.CharAt(pos - 1) == ' ' || cb.CharAt(pos - 1) == '\t')) pos--; - if (isspace(cb.CharAt(pos - 1))) { // Back up to previous line - while (pos > 0 && isspace(cb.CharAt(pos - 1))) + if (isspacechar(cb.CharAt(pos - 1))) { // Back up to previous line + while (pos > 0 && isspacechar(cb.CharAt(pos - 1))) pos--; } else { bool startAtWordChar = IsWordChar(cb.CharAt(pos - 1)); - while (pos > 0 && !isspace(cb.CharAt(pos - 1)) && (startAtWordChar == IsWordChar(cb.CharAt(pos - 1)))) + while (pos > 0 && !isspacechar(cb.CharAt(pos - 1)) && (startAtWordChar == IsWordChar(cb.CharAt(pos - 1)))) pos--; } } else { bool startAtWordChar = IsWordChar(cb.CharAt(pos)); - while (pos < (Length()) && isspace(cb.CharAt(pos))) + while (pos < (Length()) && isspacechar(cb.CharAt(pos))) pos++; - while (pos < (Length()) && !isspace(cb.CharAt(pos)) && (startAtWordChar == IsWordChar(cb.CharAt(pos)))) + while (pos < (Length()) && !isspacechar(cb.CharAt(pos)) && (startAtWordChar == IsWordChar(cb.CharAt(pos)))) pos++; while (pos < (Length()) && (cb.CharAt(pos) == ' ' || cb.CharAt(pos) == '\t')) pos++; @@ -995,10 +1000,10 @@ int Document::WordPartLeft(int pos) { --pos; if (!ispunct(cb.CharAt(pos))) ++pos; - } else if (isspace(startChar)) { - while (pos > 0 && isspace(cb.CharAt(pos))) + } else if (isspacechar(startChar)) { + while (pos > 0 && isspacechar(cb.CharAt(pos))) --pos; - if (!isspace(cb.CharAt(pos))) + if (!isspacechar(cb.CharAt(pos))) ++pos; } } @@ -1034,8 +1039,8 @@ int Document::WordPartRight(int pos) { } else if (ispunct(startChar)) { while (pos < length && ispunct(cb.CharAt(pos))) ++pos; - } else if (isspace(startChar)) { - while (pos < length && isspace(cb.CharAt(pos))) + } else if (isspacechar(startChar)) { + while (pos < length && isspacechar(cb.CharAt(pos))) ++pos; } return pos; diff --git a/src/LexCPP.cxx b/src/LexCPP.cxx index 9064cd012..1a2728dc8 100644 --- a/src/LexCPP.cxx +++ b/src/LexCPP.cxx @@ -88,7 +88,7 @@ static void ColouriseCppDoc(unsigned int startPos, int length, int initStyle, Wo } visibleChars = 0; } - if (!isspace(ch)) + if (!isspacechar(ch)) visibleChars++; if (styler.IsLeadByte(ch)) { @@ -145,7 +145,7 @@ static void ColouriseCppDoc(unsigned int startPos, int length, int initStyle, Wo i++; ch = chNext; chNext = styler.SafeGetCharAt(i + 1); - } while (isspace(ch) && (i < lengthDoc)); + } while (isspacechar(ch) && (i < lengthDoc)); } else if (isoperator(ch)) { styler.ColourTo(i-1, state); styler.ColourTo(i, SCE_C_OPERATOR); @@ -178,7 +178,7 @@ static void ColouriseCppDoc(unsigned int startPos, int length, int initStyle, Wo } else { if (state == SCE_C_PREPROCESSOR) { if (stylingWithinPreprocessor) { - if (isspace(ch)) { + if (isspacechar(ch)) { styler.ColourTo(i-1, state); state = SCE_C_DEFAULT; } |