summaryrefslogtreecommitdiff
path: root/zen/string_tools.h
diff options
context:
space:
mode:
authorDaniel Wilhelm <shieldwed@outlook.com>2020-02-23 22:12:27 +0000
committerDaniel Wilhelm <shieldwed@outlook.com>2020-02-23 22:12:27 +0000
commit450f803dd75f831f8ee14072fe0eb664bbe518df (patch)
treeb3e831d44df50348a20f3541b6062f7fbab6ff3d /zen/string_tools.h
parentMerge branch '10.19' into 'master' (diff)
parentremove upstream deleted files (diff)
downloadFreeFileSync-450f803dd75f831f8ee14072fe0eb664bbe518df.tar.gz
FreeFileSync-450f803dd75f831f8ee14072fe0eb664bbe518df.tar.bz2
FreeFileSync-450f803dd75f831f8ee14072fe0eb664bbe518df.zip
Merge branch '10.20' into 'master'10.20
add upstream 10.20 See merge request opensource-tracking/FreeFileSync!17
Diffstat (limited to 'zen/string_tools.h')
-rw-r--r--zen/string_tools.h23
1 files changed, 10 insertions, 13 deletions
diff --git a/zen/string_tools.h b/zen/string_tools.h
index 47271bc7..5c444830 100644
--- a/zen/string_tools.h
+++ b/zen/string_tools.h
@@ -27,7 +27,7 @@ template <class Char> bool isLineBreak (Char c);
template <class Char> bool isDigit (Char c); //not exactly the same as "std::isdigit" -> we consider '0'-'9' only!
template <class Char> bool isHexDigit (Char c);
template <class Char> bool isAsciiAlpha(Char c);
-template <class Char> bool isAsciiString(const Char* str);
+template <class S > bool isAsciiString(const S& str);
template <class Char> Char asciiToLower(Char c);
template <class Char> Char asciiToUpper(Char c);
@@ -150,14 +150,11 @@ bool isAsciiAlpha(Char c)
}
-template <class Char> inline
-bool isAsciiString(const Char* str)
+template <class S> inline
+bool isAsciiString(const S& str)
{
- static_assert(std::is_same_v<Char, char> || std::is_same_v<Char, wchar_t>);
- for (Char c = *str; c != 0; c = *++str)
- if (zen::makeUnsigned(c) >= 128)
- return false;
- return true;
+ const auto* const first = strBegin(str);
+ return std::all_of(first, first + strLength(str), [](auto c) { return makeUnsigned(c) < 128; });
}
@@ -170,8 +167,8 @@ Char asciiToLower(Char c)
}
- template <class Char> inline
- Char asciiToUpper(Char c)
+template <class Char> inline
+Char asciiToUpper(Char c)
{
if (static_cast<Char>('a') <= c && c <= static_cast<Char>('z'))
return static_cast<Char>(c - static_cast<Char>('a') + static_cast<Char>('A'));
@@ -604,7 +601,7 @@ S numberTo(const Num& number, std::integral_constant<NumberType, NumberType::FLO
char buffer[128]; //zero-initialize?
//let's give some leeway, but 24 chars should suffice: https://www.reddit.com/r/cpp/comments/dgj89g/cppcon_2019_stephan_t_lavavej_floatingpoint/f3j7d3q/
- const char* strEnd = zen::to_chars(std::begin(buffer), std::end(buffer), number);
+ const char* strEnd = to_chars(std::begin(buffer), std::end(buffer), number);
S output;
std::for_each(static_cast<const char*>(buffer), strEnd,
@@ -703,7 +700,7 @@ inline
double stringToFloat(const char* first, const char* last)
{
//don't use std::strtod(): 1. requires null-terminated string 2. SLOWER than std::from_chars()
- return zen::from_chars(first, last);
+ return from_chars(first, last);
}
@@ -713,7 +710,7 @@ double stringToFloat(const wchar_t* first, const wchar_t* last)
std::string buf(last - first, '\0');
std::transform(first, last, buf.begin(), [](wchar_t c) { return static_cast<char>(c); });
- return zen::from_chars(buf.c_str(), buf.c_str() + buf.size());
+ return from_chars(buf.c_str(), buf.c_str() + buf.size());
}
bgstack15