From 9e06aef78c343476ee39698c0f17aa49b7e49999 Mon Sep 17 00:00:00 2001 From: Neil Date: Tue, 5 Oct 2021 14:38:47 +1100 Subject: Feature [feature-requests:#1417] Consolidate character classification functions in CharacterType.h, merging duplicate functions, removing unused functions and stadardizing names. --- src/CharacterType.h | 73 +++++++++++++++++++++++++++++++++-------------------- 1 file changed, 46 insertions(+), 27 deletions(-) (limited to 'src/CharacterType.h') diff --git a/src/CharacterType.h b/src/CharacterType.h index 70f4cbd05..b014f1050 100644 --- a/src/CharacterType.h +++ b/src/CharacterType.h @@ -12,11 +12,15 @@ namespace Scintilla::Internal { // Functions for classifying characters +/** + * Check if a character is a space. + * This is ASCII specific but is safe with chars >= 0x80. + */ constexpr bool IsASpace(int ch) noexcept { return (ch == ' ') || ((ch >= 0x09) && (ch <= 0x0d)); } -constexpr bool IsASpaceOrTab(int ch) noexcept { +constexpr bool IsSpaceOrTab(int ch) noexcept { return (ch == ' ') || (ch == '\t'); } @@ -24,6 +28,10 @@ constexpr bool IsControl(int ch) noexcept { return ((ch >= 0) && (ch <= 0x1F)) || (ch == 0x7F); } +constexpr bool IsEOLCharacter(int ch) noexcept { + return ch == '\r' || ch == '\n'; +} + constexpr bool IsADigit(int ch) noexcept { return (ch >= '0') && (ch <= '9'); } @@ -61,33 +69,44 @@ constexpr bool IsAlphaNumeric(int ch) noexcept { ((ch >= 'A') && (ch <= 'Z')); } -/** - * Check if a character is a space. - * This is ASCII specific but is safe with chars >= 0x80. - */ -constexpr bool isspacechar(int ch) noexcept { - return (ch == ' ') || ((ch >= 0x09) && (ch <= 0x0d)); -} - -constexpr bool iswordchar(int ch) noexcept { - return IsAlphaNumeric(ch) || ch == '.' || ch == '_'; -} - -constexpr bool iswordstart(int ch) noexcept { - return IsAlphaNumeric(ch) || ch == '_'; -} - -constexpr bool isoperator(int ch) noexcept { - if (IsAlphaNumeric(ch)) - return false; - 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 == '~') +constexpr bool IsPunctuation(int ch) noexcept { + switch (ch) { + case '!': + case '"': + case '#': + case '$': + case '%': + case '&': + case '\'': + case '(': + case ')': + case '*': + case '+': + case ',': + case '-': + case '.': + case '/': + case ':': + case ';': + case '<': + case '=': + case '>': + case '?': + case '@': + case '[': + case '\\': + case ']': + case '^': + case '_': + case '`': + case '{': + case '|': + case '}': + case '~': return true; - return false; + default: + return false; + } } // Simple case functions for ASCII supersets. -- cgit v1.2.3