diff options
author | Vlad Yaroslavlev <vladon@vladon.com> | 2022-02-10 16:46:23 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:46:23 +0300 |
commit | 706b83ed7de5a473436620367af31fc0ceecde07 (patch) | |
tree | 103305d30dec77e8f6367753367f59b3cd68f9f1 /util/string/cast.h | |
parent | 918e8a1574070d0ec733f0b76cfad8f8892ad2e5 (diff) | |
download | ydb-706b83ed7de5a473436620367af31fc0ceecde07.tar.gz |
Restoring authorship annotation for Vlad Yaroslavlev <vladon@vladon.com>. Commit 1 of 2.
Diffstat (limited to 'util/string/cast.h')
-rw-r--r-- | util/string/cast.h | 72 |
1 files changed, 36 insertions, 36 deletions
diff --git a/util/string/cast.h b/util/string/cast.h index 90e925c194..b6c78b5f48 100644 --- a/util/string/cast.h +++ b/util/string/cast.h @@ -2,7 +2,7 @@ #include <util/system/defaults.h> #include <util/stream/str.h> -#include <util/generic/string.h> +#include <util/generic/string.h> #include <util/generic/strbuf.h> #include <util/generic/typetraits.h> #include <util/generic/yexception.h> @@ -40,35 +40,35 @@ enum EFloatToStringMode { /** "%f" mode, writes the given number of digits after decimal point: * 0.1f -> "0.100000", 1.2e-06f -> "0.000001" for ndigits=6 */ PREC_POINT_DIGITS = 3, - - /** same as PREC_POINT_DIGITS, but stripping trailing zeroes: - * 0.1f for ndgigits=6 -> "0.1" */ - PREC_POINT_DIGITS_STRIP_ZEROES = 4 + + /** same as PREC_POINT_DIGITS, but stripping trailing zeroes: + * 0.1f for ndgigits=6 -> "0.1" */ + PREC_POINT_DIGITS_STRIP_ZEROES = 4 }; size_t FloatToString(float t, char* buf, size_t len, EFloatToStringMode mode = PREC_AUTO, int ndigits = 0); size_t FloatToString(double t, char* buf, size_t len, EFloatToStringMode mode = PREC_AUTO, int ndigits = 0); template <typename T> -inline TString FloatToString(const T& t, EFloatToStringMode mode = PREC_AUTO, int ndigits = 0) { +inline TString FloatToString(const T& t, EFloatToStringMode mode = PREC_AUTO, int ndigits = 0) { char buf[512]; // Max<double>() with mode = PREC_POINT_DIGITS has 309 digits before the decimal point size_t count = FloatToString(t, buf, sizeof(buf), mode, ndigits); - return TString(buf, count); + return TString(buf, count); } namespace NPrivate { template <class T, bool isSimple> struct TToString { - static inline TString Cvt(const T& t) { + static inline TString Cvt(const T& t) { char buf[512]; - return TString(buf, ToString<T>(t, buf, sizeof(buf))); + return TString(buf, ToString<T>(t, buf, sizeof(buf))); } }; template <class T> struct TToString<T, false> { - static inline TString Cvt(const T& t) { + static inline TString Cvt(const T& t) { TString s; TStringOutput o(s); o << t; @@ -81,25 +81,25 @@ namespace NPrivate { * some clever implementations... */ template <class T> -inline TString ToString(const T& t) { +inline TString ToString(const T& t) { using TR = std::remove_cv_t<T>; return ::NPrivate::TToString<TR, std::is_arithmetic<TR>::value>::Cvt((const TR&)t); } -inline const TString& ToString(const TString& s) noexcept { +inline const TString& ToString(const TString& s) noexcept { return s; } -inline const TString& ToString(TString& s) noexcept { +inline const TString& ToString(TString& s) noexcept { return s; } -inline TString ToString(const char* s) { +inline TString ToString(const char* s) { return s; } -inline TString ToString(char* s) { +inline TString ToString(char* s) { return s; } @@ -107,15 +107,15 @@ inline TString ToString(char* s) { * Wrapper for wide strings. */ template <class T> -inline TUtf16String ToWtring(const T& t) { - return TUtf16String::FromAscii(ToString(t)); +inline TUtf16String ToWtring(const T& t) { + return TUtf16String::FromAscii(ToString(t)); } -inline const TUtf16String& ToWtring(const TUtf16String& w) { +inline const TUtf16String& ToWtring(const TUtf16String& w) { return w; } -inline const TUtf16String& ToWtring(TUtf16String& w) { +inline const TUtf16String& ToWtring(TUtf16String& w) { return w; } @@ -156,7 +156,7 @@ inline T FromString(const TStringBuf& s) { } template <class T> -inline T FromString(const TString& s) { +inline T FromString(const TString& s) { return ::FromString<T>(s.data(), s.size()); } @@ -166,7 +166,7 @@ inline T FromString(const std::string& s) { } template <> -inline TString FromString<TString>(const TString& s) { +inline TString FromString<TString>(const TString& s) { return s; } @@ -176,7 +176,7 @@ inline T FromString(const TWtringBuf& s) { } template <class T> -inline T FromString(const TUtf16String& s) { +inline T FromString(const TUtf16String& s) { return ::FromString<T, wchar16>(s.data(), s.size()); } @@ -251,7 +251,7 @@ inline bool TryFromString(const TStringBuf& s, T& result) { } template <class T> -inline bool TryFromString(const TString& s, T& result) { +inline bool TryFromString(const TString& s, T& result) { return TryFromString<T>(s.data(), s.size(), result); } @@ -266,12 +266,12 @@ inline bool TryFromString(const TWtringBuf& s, T& result) { } template <class T> -inline bool TryFromString(const TUtf16String& s, T& result) { +inline bool TryFromString(const TUtf16String& s, T& result) { return TryFromString<T>(s.data(), s.size(), result); } -template <class T, class TStringType> -inline bool TryFromStringWithDefault(const TStringType& s, T& result, const T& def) { +template <class T, class TStringType> +inline bool TryFromStringWithDefault(const TStringType& s, T& result, const T& def) { return TryFromString<T>(s.data(), s.size(), result, def); } @@ -280,8 +280,8 @@ inline bool TryFromStringWithDefault(const char* s, T& result, const T& def) { return TryFromStringWithDefault<T>(TStringBuf(s), result, def); } -template <class T, class TStringType> -inline bool TryFromStringWithDefault(const TStringType& s, T& result) { +template <class T, class TStringType> +inline bool TryFromStringWithDefault(const TStringType& s, T& result) { return TryFromStringWithDefault<T>(s, result, T()); } @@ -293,8 +293,8 @@ inline T FromString(const TChar* data, const size_t len, const T& def) { return result; } -template <class T, class TStringType> -inline T FromStringWithDefault(const TStringType& s, const T& def) { +template <class T, class TStringType> +inline T FromStringWithDefault(const TStringType& s, const T& def) { return FromString<T>(s.data(), s.size(), def); } @@ -303,8 +303,8 @@ inline T FromStringWithDefault(const char* s, const T& def) { return FromStringWithDefault<T>(TStringBuf(s), def); } -template <class T, class TStringType> -inline T FromStringWithDefault(const TStringType& s) { +template <class T, class TStringType> +inline T FromStringWithDefault(const TStringType& s) { return FromStringWithDefault<T>(s, T()); } @@ -315,19 +315,19 @@ template <int base, class T> size_t IntToString(T t, char* buf, size_t len); template <int base, class T> -inline TString IntToString(T t) { +inline TString IntToString(T t) { static_assert(std::is_arithmetic<std::remove_cv_t<T>>::value, "expect std::is_arithmetic<std::remove_cv_t<T>>::value"); char buf[256]; - return TString(buf, IntToString<base>(t, buf, sizeof(buf))); + return TString(buf, IntToString<base>(t, buf, sizeof(buf))); } template <int base, class TInt, class TChar> bool TryIntFromString(const TChar* data, size_t len, TInt& result); -template <int base, class TInt, class TStringType> -inline bool TryIntFromString(const TStringType& s, TInt& result) { +template <int base, class TInt, class TStringType> +inline bool TryIntFromString(const TStringType& s, TInt& result) { return TryIntFromString<base>(s.data(), s.size(), result); } |