From 0b5c16f6b35f7144b34996d8c77f370bcbcf150c Mon Sep 17 00:00:00 2001 From: crupest Date: Thu, 10 Mar 2022 16:01:56 +0800 Subject: ... --- include/cru/common/StringToNumberConverter.h | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'include/cru/common/StringToNumberConverter.h') 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 + 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 + 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. -- cgit v1.2.3