aboutsummaryrefslogtreecommitdiff
path: root/include/cru
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2022-03-10 16:01:56 +0800
committercrupest <crupest@outlook.com>2022-03-10 16:01:56 +0800
commit0b5c16f6b35f7144b34996d8c77f370bcbcf150c (patch)
treeda6039de16d0de9aa8c6ee1afdcec44133ce4133 /include/cru
parent268bec4cd0d562394c2c27d10a26be1264bc8648 (diff)
downloadcru-0b5c16f6b35f7144b34996d8c77f370bcbcf150c.tar.gz
cru-0b5c16f6b35f7144b34996d8c77f370bcbcf150c.tar.bz2
cru-0b5c16f6b35f7144b34996d8c77f370bcbcf150c.zip
...
Diffstat (limited to 'include/cru')
-rw-r--r--include/cru/common/String.h17
-rw-r--r--include/cru/common/StringToNumberConverter.h28
2 files changed, 44 insertions, 1 deletions
diff --git a/include/cru/common/String.h b/include/cru/common/String.h
index 9ec494c6..7bbbecfb 100644
--- a/include/cru/common/String.h
+++ b/include/cru/common/String.h
@@ -356,7 +356,22 @@ class CRU_BASE_API StringView {
CRU_DEFINE_COMPARE_OPERATORS(String)
inline String operator+(const String& left, const String& right) {
- String result(left);
+ String result;
+ result += left;
+ result += right;
+ return result;
+}
+
+inline String operator+(String::value_type left, const String& right) {
+ String result;
+ result += left;
+ result += right;
+ return result;
+}
+
+inline String operator+(const String& left, String::value_type right) {
+ String result;
+ result += left;
result += right;
return result;
}
diff --git a/include/cru/common/StringToNumberConverter.h b/include/cru/common/StringToNumberConverter.h
index e68d12a6..b5118de6 100644
--- a/include/cru/common/StringToNumberConverter.h
+++ b/include/cru/common/StringToNumberConverter.h
@@ -1,6 +1,8 @@
#pragma once
#include "Base.h"
+#include <ostream>
+
namespace cru {
struct StringToNumberFlags {
constexpr static unsigned kNoFlags = 0;
@@ -12,10 +14,30 @@ struct StringToNumberFlags {
};
struct StringToIntegerConverterImplResult {
+ StringToIntegerConverterImplResult() = default;
+ StringToIntegerConverterImplResult(bool negate, unsigned long long value)
+ : negate(negate), value(value) {}
+
bool negate;
unsigned long long value;
};
+inline bool operator==(const StringToIntegerConverterImplResult& left,
+ const StringToIntegerConverterImplResult& right) {
+ return left.negate == right.negate && left.value == right.value;
+}
+
+inline bool operator!=(const StringToIntegerConverterImplResult& left,
+ const StringToIntegerConverterImplResult& right) {
+ return !(left == right);
+}
+
+inline std::ostream& operator<<(
+ std::ostream& stream, const StringToIntegerConverterImplResult& result) {
+ return stream << "StringToIntegerConverterImplResult("
+ << (result.negate ? "-" : "") << result.value << ")";
+}
+
/**
* \brief A converter that convert number into long long.
*/
@@ -36,6 +58,12 @@ struct StringToIntegerConverterImpl {
StringToIntegerConverterImplResult Parse(
const char* str, Index size, Index* processed_characters_count) const;
+ template <std::size_t Size>
+ StringToIntegerConverterImplResult Parse(
+ const char (&str)[Size], Index* processed_characters_count) const {
+ return Parse(str, Size - 1, processed_characters_count);
+ }
+
unsigned flags;
/**
* \brief The base of the number used for parse or 0 for auto detect.