util/CharUtil: add noexcept

This commit is contained in:
Max Kellermann 2019-07-05 18:05:04 +02:00
parent d6660bad03
commit 9d3d4fc734
2 changed files with 25 additions and 25 deletions

View File

@ -35,25 +35,25 @@
#endif #endif
constexpr bool constexpr bool
IsASCII(const unsigned char ch) IsASCII(const unsigned char ch) noexcept
{ {
return ch < 0x80; return ch < 0x80;
} }
constexpr bool constexpr bool
IsASCII(const char ch) IsASCII(const char ch) noexcept
{ {
return IsASCII((unsigned char)ch); return IsASCII((unsigned char)ch);
} }
constexpr bool constexpr bool
IsWhitespaceOrNull(const char ch) IsWhitespaceOrNull(const char ch) noexcept
{ {
return (unsigned char)ch <= 0x20; return (unsigned char)ch <= 0x20;
} }
constexpr bool constexpr bool
IsWhitespaceNotNull(const char ch) IsWhitespaceNotNull(const char ch) noexcept
{ {
return ch > 0 && ch <= 0x20; return ch > 0 && ch <= 0x20;
} }
@ -65,43 +65,43 @@ IsWhitespaceNotNull(const char ch)
* matches. * matches.
*/ */
constexpr bool constexpr bool
IsWhitespaceFast(const char ch) IsWhitespaceFast(const char ch) noexcept
{ {
return IsWhitespaceOrNull(ch); return IsWhitespaceOrNull(ch);
} }
constexpr bool constexpr bool
IsPrintableASCII(char ch) IsPrintableASCII(char ch) noexcept
{ {
return (signed char)ch >= 0x20; return (signed char)ch >= 0x20;
} }
constexpr bool constexpr bool
IsDigitASCII(char ch) IsDigitASCII(char ch) noexcept
{ {
return ch >= '0' && ch <= '9'; return ch >= '0' && ch <= '9';
} }
constexpr bool constexpr bool
IsUpperAlphaASCII(char ch) IsUpperAlphaASCII(char ch) noexcept
{ {
return ch >= 'A' && ch <= 'Z'; return ch >= 'A' && ch <= 'Z';
} }
constexpr bool constexpr bool
IsLowerAlphaASCII(char ch) IsLowerAlphaASCII(char ch) noexcept
{ {
return ch >= 'a' && ch <= 'z'; return ch >= 'a' && ch <= 'z';
} }
constexpr bool constexpr bool
IsAlphaASCII(char ch) IsAlphaASCII(char ch) noexcept
{ {
return IsUpperAlphaASCII(ch) || IsLowerAlphaASCII(ch); return IsUpperAlphaASCII(ch) || IsLowerAlphaASCII(ch);
} }
constexpr bool constexpr bool
IsAlphaNumericASCII(char ch) IsAlphaNumericASCII(char ch) noexcept
{ {
return IsAlphaASCII(ch) || IsDigitASCII(ch); return IsAlphaASCII(ch) || IsDigitASCII(ch);
} }
@ -111,7 +111,7 @@ IsAlphaNumericASCII(char ch)
* Unlike toupper(), it ignores the system locale. * Unlike toupper(), it ignores the system locale.
*/ */
constexpr char constexpr char
ToUpperASCII(char ch) ToUpperASCII(char ch) noexcept
{ {
return ch >= 'a' && ch <= 'z' return ch >= 'a' && ch <= 'z'
? (ch - ('a' - 'A')) ? (ch - ('a' - 'A'))
@ -123,7 +123,7 @@ ToUpperASCII(char ch)
* Unlike tolower(), it ignores the system locale. * Unlike tolower(), it ignores the system locale.
*/ */
constexpr char constexpr char
ToLowerASCII(char ch) ToLowerASCII(char ch) noexcept
{ {
return ch >= 'A' && ch <= 'Z' return ch >= 'A' && ch <= 'Z'
? (ch + ('a' - 'A')) ? (ch + ('a' - 'A'))

View File

@ -33,19 +33,19 @@
#include <wchar.h> #include <wchar.h>
constexpr bool constexpr bool
IsASCII(const wchar_t ch) IsASCII(const wchar_t ch) noexcept
{ {
return (ch & ~0x7f) == 0; return (ch & ~0x7f) == 0;
} }
constexpr bool constexpr bool
IsWhitespaceOrNull(const wchar_t ch) IsWhitespaceOrNull(const wchar_t ch) noexcept
{ {
return (unsigned)ch <= 0x20; return (unsigned)ch <= 0x20;
} }
constexpr bool constexpr bool
IsWhitespaceNotNull(const wchar_t ch) IsWhitespaceNotNull(const wchar_t ch) noexcept
{ {
return ch > 0 && ch <= 0x20; return ch > 0 && ch <= 0x20;
} }
@ -57,43 +57,43 @@ IsWhitespaceNotNull(const wchar_t ch)
* matches. * matches.
*/ */
constexpr bool constexpr bool
IsWhitespaceFast(const wchar_t ch) IsWhitespaceFast(const wchar_t ch) noexcept
{ {
return IsWhitespaceOrNull(ch); return IsWhitespaceOrNull(ch);
} }
constexpr bool constexpr bool
IsPrintableASCII(wchar_t ch) IsPrintableASCII(wchar_t ch) noexcept
{ {
return IsASCII(ch) && ch >= 0x20; return IsASCII(ch) && ch >= 0x20;
} }
constexpr bool constexpr bool
IsDigitASCII(wchar_t ch) IsDigitASCII(wchar_t ch) noexcept
{ {
return ch >= '0' && ch <= '9'; return ch >= '0' && ch <= '9';
} }
constexpr bool constexpr bool
IsUpperAlphaASCII(wchar_t ch) IsUpperAlphaASCII(wchar_t ch) noexcept
{ {
return ch >= 'A' && ch <= 'Z'; return ch >= 'A' && ch <= 'Z';
} }
constexpr bool constexpr bool
IsLowerAlphaASCII(wchar_t ch) IsLowerAlphaASCII(wchar_t ch) noexcept
{ {
return ch >= 'a' && ch <= 'z'; return ch >= 'a' && ch <= 'z';
} }
constexpr bool constexpr bool
IsAlphaASCII(wchar_t ch) IsAlphaASCII(wchar_t ch) noexcept
{ {
return IsUpperAlphaASCII(ch) || IsLowerAlphaASCII(ch); return IsUpperAlphaASCII(ch) || IsLowerAlphaASCII(ch);
} }
constexpr bool constexpr bool
IsAlphaNumericASCII(wchar_t ch) IsAlphaNumericASCII(wchar_t ch) noexcept
{ {
return IsAlphaASCII(ch) || IsDigitASCII(ch); return IsAlphaASCII(ch) || IsDigitASCII(ch);
} }
@ -103,7 +103,7 @@ IsAlphaNumericASCII(wchar_t ch)
* Unlike toupper(), it ignores the system locale. * Unlike toupper(), it ignores the system locale.
*/ */
constexpr wchar_t constexpr wchar_t
ToUpperASCII(wchar_t ch) ToUpperASCII(wchar_t ch) noexcept
{ {
return ch >= 'a' && ch <= 'z' return ch >= 'a' && ch <= 'z'
? (ch - ('a' - 'A')) ? (ch - ('a' - 'A'))
@ -115,7 +115,7 @@ ToUpperASCII(wchar_t ch)
* Unlike tolower(), it ignores the system locale. * Unlike tolower(), it ignores the system locale.
*/ */
constexpr wchar_t constexpr wchar_t
ToLowerASCII(wchar_t ch) ToLowerASCII(wchar_t ch) noexcept
{ {
return ch >= 'A' && ch <= 'Z' return ch >= 'A' && ch <= 'Z'
? (ch + ('a' - 'A')) ? (ch + ('a' - 'A'))