From c95b3937fef3e2c63768f1b3b1dc2c898f23d91d Mon Sep 17 00:00:00 2001 From: B Stack Date: Wed, 22 Jul 2020 11:37:03 -0400 Subject: add upstream 11.0 --- zen/string_tools.h | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'zen/string_tools.h') diff --git a/zen/string_tools.h b/zen/string_tools.h index eaf1a700..cfdb27bd 100644 --- a/zen/string_tools.h +++ b/zen/string_tools.h @@ -26,6 +26,7 @@ template bool isWhiteSpace(Char c); template bool isLineBreak (Char c); template bool isDigit (Char c); //not exactly the same as "std::isdigit" -> we consider '0'-'9' only! template bool isHexDigit (Char c); +template bool isAsciiChar (Char c); template bool isAsciiAlpha(Char c); template bool isAsciiString(const S& str); template Char asciiToLower(Char c); @@ -142,6 +143,13 @@ bool isHexDigit(Char c) } +template inline +bool isAsciiChar(Char c) +{ + return makeUnsigned(c) < 128; +} + + template inline bool isAsciiAlpha(Char c) { @@ -155,7 +163,7 @@ template inline bool isAsciiString(const S& str) { const auto* const first = strBegin(str); - return std::all_of(first, first + strLength(str), [](auto c) { return makeUnsigned(c) < 128; }); + return std::all_of(first, first + strLength(str), [](auto c) { return isAsciiChar(c); }); } @@ -255,7 +263,7 @@ int compareString(const S& lhs, const T& rhs) const size_t lhsLen = strLength(lhs); const size_t rhsLen = strLength(rhs); - //length check *after* strcmpWithNulls(): we do care about natural ordering: e.g. for "compareString(makeUpperCopy(lhs), makeUpperCopy(rhs))" + //length check *after* strcmpWithNulls(): we do care about natural ordering: e.g. for "compareString(getUpperCase(lhs), getUpperCase(rhs))" if (const int rv = impl::strcmpWithNulls(strBegin(lhs), strBegin(rhs), std::min(lhsLen, rhsLen)); rv != 0) return rv; -- cgit