diff options
Diffstat (limited to 'include')
-rw-r--r-- | include/cru/common/String.h | 17 | ||||
-rw-r--r-- | include/cru/common/StringToNumberConverter.h | 28 |
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. |