diff options
-rw-r--r-- | src/LexLua.cxx | 27 | ||||
-rw-r--r-- | src/LexPOV.cxx | 17 |
2 files changed, 28 insertions, 16 deletions
diff --git a/src/LexLua.cxx b/src/LexLua.cxx index 18612c9ee..926557750 100644 --- a/src/LexLua.cxx +++ b/src/LexLua.cxx @@ -27,21 +27,31 @@ static inline bool IsAWordChar(const int ch) { return (ch < 0x80) && (isalnum(ch) || ch == '_' || ch == '.'); } -inline bool IsAWordStart(const int ch) { +static inline bool IsAWordStart(const int ch) { return (ch < 0x80) && (isalnum(ch) || ch == '_'); } -inline bool isLuaOperator(char ch) { - if (isalnum(ch)) +static inline bool IsANumberChar(const int ch) { + // Not exactly following number definition (several dots are seen as OK, etc.) + // but probably enough in most cases. + return (ch < 0x80) && + (isdigit(ch) || toupper(ch) == 'E' || + ch == '.' || ch == '-' || ch == '+'); +} + +static inline bool IsLuaOperator(char ch) { + if (ch >= 0x80 || 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; } @@ -124,11 +134,8 @@ static void ColouriseLuaDoc( sc.SetState(SCE_LUA_DEFAULT); } else if (sc.state == SCE_LUA_NUMBER) { // We stop the number definition on non-numerical non-dot non-eE non-sign char - if (!(isdigit(sc.ch) || sc.ch == '.' || - toupper(sc.ch) == 'E' || sc.ch == '-' || sc.ch == '+')) { - // Not exactly following number definition (several dots are seen as OK, etc.) - // but probably enough in most cases. - sc.SetState(SCE_LUA_DEFAULT); + if (!IsANumberChar(sc.ch)) { + sc.SetState(SCE_LUA_DEFAULT); } } else if (sc.state == SCE_LUA_IDENTIFIER) { if (!IsAWordChar(sc.ch)) { @@ -233,7 +240,7 @@ static void ColouriseLuaDoc( sc.Forward(); } else if (sc.atLineStart && sc.Match('$')) { sc.SetState(SCE_LUA_PREPROCESSOR); // Obsolete since Lua 4.0, but still in old code - } else if (isLuaOperator(static_cast<char>(sc.ch))) { + } else if (IsLuaOperator(static_cast<char>(sc.ch))) { sc.SetState(SCE_LUA_OPERATOR); } } diff --git a/src/LexPOV.cxx b/src/LexPOV.cxx index 33ba6a490..0c1a21ab4 100644 --- a/src/LexPOV.cxx +++ b/src/LexPOV.cxx @@ -33,10 +33,18 @@ static inline bool IsAWordChar(const int ch) { return ch < 0x80 && (isalnum(ch) || ch == '_'); } -inline bool IsAWordStart(const int ch) { +static inline bool IsAWordStart(const int ch) { return ch < 0x80 && isalpha(ch); } +static inline bool IsANumberChar(const int ch) { + // Not exactly following number definition (several dots are seen as OK, etc.) + // but probably enough in most cases. + return (ch < 0x80) && + (isdigit(ch) || toupper(ch) == 'E' || + ch == '.' || ch == '-' || ch == '+'); +} + static void ColourisePovDoc( unsigned int startPos, int length, @@ -91,11 +99,8 @@ static void ColourisePovDoc( sc.SetState(SCE_POV_DEFAULT); } else if (sc.state == SCE_POV_NUMBER) { // We stop the number definition on non-numerical non-dot non-eE non-sign char - if (!(isdigit(sc.ch) || sc.ch == '.' || - toupper(sc.ch) == 'E' || sc.ch == '-' || sc.ch == '+')) { - // Not exactly following number definition (several dots are seen as OK, etc.) - // but probably enough in most cases. - sc.SetState(SCE_POV_DEFAULT); + if (!IsANumberChar(sc.ch)) { + sc.SetState(SCE_POV_DEFAULT); } } else if (sc.state == SCE_POV_IDENTIFIER) { if (!IsAWordChar(sc.ch)) { |