diff options
Diffstat (limited to 'src/corelib/tools/qtools_p.h')
-rw-r--r-- | src/corelib/tools/qtools_p.h | 66 |
1 files changed, 57 insertions, 9 deletions
diff --git a/src/corelib/tools/qtools_p.h b/src/corelib/tools/qtools_p.h index 338f89d633..105aa40c02 100644 --- a/src/corelib/tools/qtools_p.h +++ b/src/corelib/tools/qtools_p.h @@ -16,22 +16,32 @@ // #include "QtCore/private/qglobal_p.h" + +#include <chrono> #include <limits.h> +#include <time.h> QT_BEGIN_NAMESPACE namespace QtMiscUtils { -constexpr inline char toHexUpper(uint value) noexcept +constexpr inline char toHexUpper(char32_t value) noexcept { return "0123456789ABCDEF"[value & 0xF]; } -constexpr inline char toHexLower(uint value) noexcept +constexpr inline char toHexLower(char32_t value) noexcept { return "0123456789abcdef"[value & 0xF]; } -constexpr inline int fromHex(uint c) noexcept +[[nodiscard]] constexpr inline bool isHexDigit(char32_t c) noexcept +{ + return (c >= '0' && c <= '9') + || (c >= 'A' && c <= 'F') + || (c >= 'a' && c <= 'f'); +} + +constexpr inline int fromHex(char32_t c) noexcept { return ((c >= '0') && (c <= '9')) ? int(c - '0') : ((c >= 'A') && (c <= 'F')) ? int(c - 'A' + 10) : @@ -39,19 +49,49 @@ constexpr inline int fromHex(uint c) noexcept /* otherwise */ -1; } -constexpr inline char toOct(uint value) noexcept +constexpr inline char toOct(char32_t value) noexcept { return char('0' + (value & 0x7)); } -constexpr inline int fromOct(uint c) noexcept +[[nodiscard]] constexpr inline bool isOctalDigit(char32_t c) noexcept +{ + return c >= '0' && c <= '7'; +} + +constexpr inline int fromOct(char32_t c) noexcept +{ + return isOctalDigit(c) ? int(c - '0') : -1; +} + +[[nodiscard]] constexpr inline bool isAsciiDigit(char32_t c) noexcept +{ + return c >= '0' && c <= '9'; +} + +constexpr inline bool isAsciiUpper(char32_t c) noexcept { - return ((c >= '0') && (c <= '7')) ? int(c - '0') : -1; + return c >= 'A' && c <= 'Z'; +} + +constexpr inline bool isAsciiLower(char32_t c) noexcept +{ + return c >= 'a' && c <= 'z'; +} + +constexpr inline bool isAsciiLetterOrNumber(char32_t c) noexcept +{ + return isAsciiDigit(c) || isAsciiLower(c) || isAsciiUpper(c); } constexpr inline char toAsciiLower(char ch) noexcept { - return (ch >= 'A' && ch <= 'Z') ? ch - 'A' + 'a' : ch; + return isAsciiUpper(ch) ? ch - 'A' + 'a' : ch; +} + +constexpr inline char toAsciiUpper(char ch) noexcept +{ + return isAsciiLower(ch) ? ch - 'a' + 'A' : ch; } constexpr inline int caseCompareAscii(char lhs, char rhs) noexcept @@ -61,11 +101,19 @@ constexpr inline int caseCompareAscii(char lhs, char rhs) noexcept return int(uchar(lhsLower)) - int(uchar(rhsLower)); } +constexpr inline int isAsciiPrintable(char32_t ch) noexcept +{ + return ch >= ' ' && ch < 0x7f; +} +constexpr inline int qt_lencmp(qsizetype lhs, qsizetype rhs) noexcept +{ + return lhs == rhs ? 0 : + lhs > rhs ? 1 : + /* else */ -1 ; } -// We typically need an extra bit for qNextPowerOfTwo when determining the next allocation size. -constexpr qsizetype MaxAllocSize = (std::numeric_limits<qsizetype>::max)(); +} // namespace QtMiscUtils struct CalculateGrowingBlockSizeResult { |