From 13b6f88d9b4710e1c51b36a97c3b45a6441a7820 Mon Sep 17 00:00:00 2001 From: Neil Date: Tue, 27 Apr 2021 10:04:57 +1000 Subject: Rename CharacterSet and CharacterCategory modules in Scintilla to CharacterType and CharacterCategoryMap to avoid clashes with Lexilla when building an executable that includes both. --- src/CharacterType.h | 112 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 112 insertions(+) create mode 100644 src/CharacterType.h (limited to 'src/CharacterType.h') diff --git a/src/CharacterType.h b/src/CharacterType.h new file mode 100644 index 000000000..1a478cbe4 --- /dev/null +++ b/src/CharacterType.h @@ -0,0 +1,112 @@ +// Scintilla source code edit control +/** @file CharacterType.h + ** Tests for character type and case-insensitive comparisons. + **/ +// Copyright 2007 by Neil Hodgson +// The License.txt file describes the conditions under which this software may be distributed. + +#ifndef CHARACTERTYPE_H +#define CHARACTERTYPE_H + +namespace Scintilla { + +// Functions for classifying characters + +constexpr bool IsASpace(int ch) noexcept { + return (ch == ' ') || ((ch >= 0x09) && (ch <= 0x0d)); +} + +constexpr bool IsASpaceOrTab(int ch) noexcept { + return (ch == ' ') || (ch == '\t'); +} + +constexpr bool IsADigit(int ch) noexcept { + return (ch >= '0') && (ch <= '9'); +} + +constexpr bool IsADigit(int ch, int base) noexcept { + if (base <= 10) { + return (ch >= '0') && (ch < '0' + base); + } else { + return ((ch >= '0') && (ch <= '9')) || + ((ch >= 'A') && (ch < 'A' + base - 10)) || + ((ch >= 'a') && (ch < 'a' + base - 10)); + } +} + +constexpr bool IsASCII(int ch) noexcept { + return (ch >= 0) && (ch < 0x80); +} + +constexpr bool IsLowerCase(int ch) noexcept { + return (ch >= 'a') && (ch <= 'z'); +} + +constexpr bool IsUpperCase(int ch) noexcept { + return (ch >= 'A') && (ch <= 'Z'); +} + +constexpr bool IsUpperOrLowerCase(int ch) noexcept { + return IsUpperCase(ch) || IsLowerCase(ch); +} + +constexpr bool IsAlphaNumeric(int ch) noexcept { + return + ((ch >= '0') && (ch <= '9')) || + ((ch >= 'a') && (ch <= 'z')) || + ((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 == '~') + return true; + return false; +} + +// Simple case functions for ASCII supersets. + +template +constexpr T MakeUpperCase(T ch) noexcept { + if (ch < 'a' || ch > 'z') + return ch; + else + return ch - 'a' + 'A'; +} + +template +constexpr T MakeLowerCase(T ch) noexcept { + if (ch < 'A' || ch > 'Z') + return ch; + else + return ch - 'A' + 'a'; +} + +int CompareCaseInsensitive(const char *a, const char *b) noexcept; +int CompareNCaseInsensitive(const char *a, const char *b, size_t len) noexcept; + +} + +#endif -- cgit v1.2.3