From b3c9933350e5c6b9d06a72034e681cecae52dc4b Mon Sep 17 00:00:00 2001 From: Neil Date: Thu, 16 Jul 2020 19:55:15 +1000 Subject: Add constexpr, const, noexcept and make other small improvements to lexlib. --- lexlib/CharacterSet.h | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) (limited to 'lexlib/CharacterSet.h') diff --git a/lexlib/CharacterSet.h b/lexlib/CharacterSet.h index f71dbc964..a518c27fc 100644 --- a/lexlib/CharacterSet.h +++ b/lexlib/CharacterSet.h @@ -94,12 +94,12 @@ public: bset[uch] = true; } } - bool Contains(int val) const { + bool Contains(int val) const noexcept { assert(val >= 0); if (val < 0) return false; return (val < size) ? bset[val] : valueAfter; } - bool Contains(char ch) const { + bool Contains(char ch) const noexcept { // Overload char as char may be signed const unsigned char uch = ch; return Contains(uch); @@ -108,19 +108,19 @@ public: // Functions for classifying characters -inline bool IsASpace(int ch) { +constexpr bool IsASpace(int ch) noexcept { return (ch == ' ') || ((ch >= 0x09) && (ch <= 0x0d)); } -inline bool IsASpaceOrTab(int ch) { +constexpr bool IsASpaceOrTab(int ch) noexcept { return (ch == ' ') || (ch == '\t'); } -inline bool IsADigit(int ch) { +constexpr bool IsADigit(int ch) noexcept { return (ch >= '0') && (ch <= '9'); } -inline bool IsADigit(int ch, int base) { +constexpr bool IsADigit(int ch, int base) noexcept { if (base <= 10) { return (ch >= '0') && (ch < '0' + base); } else { @@ -130,23 +130,23 @@ inline bool IsADigit(int ch, int base) { } } -inline bool IsASCII(int ch) { +constexpr bool IsASCII(int ch) noexcept { return (ch >= 0) && (ch < 0x80); } -inline bool IsLowerCase(int ch) { +constexpr bool IsLowerCase(int ch) noexcept { return (ch >= 'a') && (ch <= 'z'); } -inline bool IsUpperCase(int ch) { +constexpr bool IsUpperCase(int ch) noexcept { return (ch >= 'A') && (ch <= 'Z'); } -inline bool IsUpperOrLowerCase(int ch) { +constexpr bool IsUpperOrLowerCase(int ch) noexcept { return IsUpperCase(ch) || IsLowerCase(ch); } -inline bool IsAlphaNumeric(int ch) { +constexpr bool IsAlphaNumeric(int ch) noexcept { return ((ch >= '0') && (ch <= '9')) || ((ch >= 'a') && (ch <= 'z')) || @@ -157,19 +157,19 @@ inline bool IsAlphaNumeric(int ch) { * Check if a character is a space. * This is ASCII specific but is safe with chars >= 0x80. */ -inline bool isspacechar(int ch) { +constexpr bool isspacechar(int ch) noexcept { return (ch == ' ') || ((ch >= 0x09) && (ch <= 0x0d)); } -inline bool iswordchar(int ch) { +constexpr bool iswordchar(int ch) noexcept { return IsAlphaNumeric(ch) || ch == '.' || ch == '_'; } -inline bool iswordstart(int ch) { +constexpr bool iswordstart(int ch) noexcept { return IsAlphaNumeric(ch) || ch == '_'; } -inline bool isoperator(int ch) { +constexpr bool isoperator(int ch) noexcept { if (IsAlphaNumeric(ch)) return false; if (ch == '%' || ch == '^' || ch == '&' || ch == '*' || @@ -185,7 +185,7 @@ inline bool isoperator(int ch) { // Simple case functions for ASCII supersets. template -inline T MakeUpperCase(T ch) { +constexpr T MakeUpperCase(T ch) noexcept { if (ch < 'a' || ch > 'z') return ch; else @@ -193,15 +193,15 @@ inline T MakeUpperCase(T ch) { } template -inline T MakeLowerCase(T ch) { +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); -int CompareNCaseInsensitive(const char *a, const char *b, size_t len); +int CompareCaseInsensitive(const char *a, const char *b) noexcept; +int CompareNCaseInsensitive(const char *a, const char *b, size_t len) noexcept; } -- cgit v1.2.3