aboutsummaryrefslogtreecommitdiffstats
path: root/util/string/cast.cpp
diff options
context:
space:
mode:
authortobo <tobo@yandex-team.ru>2022-02-10 16:47:27 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:47:27 +0300
commit55a7f90e4cd31e9481cace8ee5dfd682c27e810e (patch)
tree9814fbd1c3effac9b8377c5d604b367b14e2db55 /util/string/cast.cpp
parent7fe839092527589b38f014d854c51565b3c1adfa (diff)
downloadydb-55a7f90e4cd31e9481cace8ee5dfd682c27e810e.tar.gz
Restoring authorship annotation for <tobo@yandex-team.ru>. Commit 2 of 2.
Diffstat (limited to 'util/string/cast.cpp')
-rw-r--r--util/string/cast.cpp86
1 files changed, 43 insertions, 43 deletions
diff --git a/util/string/cast.cpp b/util/string/cast.cpp
index 2a4f697042..aa1e65a8e9 100644
--- a/util/string/cast.cpp
+++ b/util/string/cast.cpp
@@ -6,7 +6,7 @@
#include <cstdio>
#include <string>
-#include <cmath>
+#include <cmath>
#include <util/string/type.h>
#include <util/string/cast.h>
@@ -31,12 +31,12 @@ using double_conversion::StringToDoubleConverter;
*/
namespace {
- constexpr char IntToChar[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};
+ constexpr char IntToChar[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};
static_assert(Y_ARRAY_SIZE(IntToChar) == 16, "expect Y_ARRAY_SIZE(IntToChar) == 16");
// clang-format off
- constexpr int LetterToIntMap[] = {
+ constexpr int LetterToIntMap[] = {
20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
@@ -52,17 +52,17 @@ namespace {
// clang-format on
template <class T>
- std::enable_if_t<std::is_signed<T>::value, std::make_unsigned_t<T>> NegateNegativeSigned(T value) noexcept {
+ std::enable_if_t<std::is_signed<T>::value, std::make_unsigned_t<T>> NegateNegativeSigned(T value) noexcept {
return std::make_unsigned_t<T>(-(value + 1)) + std::make_unsigned_t<T>(1);
}
template <class T>
- std::enable_if_t<std::is_unsigned<T>::value, std::make_unsigned_t<T>> NegateNegativeSigned(T) noexcept {
+ std::enable_if_t<std::is_unsigned<T>::value, std::make_unsigned_t<T>> NegateNegativeSigned(T) noexcept {
Y_UNREACHABLE();
}
template <class T>
- std::make_signed_t<T> NegatePositiveSigned(T value) noexcept {
+ std::make_signed_t<T> NegatePositiveSigned(T value) noexcept {
return value > 0 ? (-std::make_signed_t<T>(value - 1) - 1) : 0;
}
@@ -72,18 +72,18 @@ namespace {
static_assert(std::is_unsigned<T>::value, "TBasicIntFormatter can only handle unsigned integers.");
static inline size_t Format(T value, TChar* buf, size_t len) {
- Y_ENSURE(len, TStringBuf("zero length"));
+ Y_ENSURE(len, TStringBuf("zero length"));
TChar* tmp = buf;
do {
- // divide only once, do not use mod
- const T nextVal = static_cast<T>(value / base);
- *tmp++ = IntToChar[base == 2 || base == 4 || base == 8 || base == 16 ? value & (base - 1) : value - base * nextVal];
- value = nextVal;
+ // divide only once, do not use mod
+ const T nextVal = static_cast<T>(value / base);
+ *tmp++ = IntToChar[base == 2 || base == 4 || base == 8 || base == 16 ? value & (base - 1) : value - base * nextVal];
+ value = nextVal;
} while (value && --len);
- Y_ENSURE(!value, TStringBuf("not enough room in buffer"));
+ Y_ENSURE(!value, TStringBuf("not enough room in buffer"));
const size_t result = tmp - buf;
@@ -111,7 +111,7 @@ namespace {
using TUFmt = TBasicIntFormatter<std::make_unsigned_t<T>, base, TChar>;
if (std::is_signed<T>::value && value < 0) {
- Y_ENSURE(len >= 2, TStringBuf("not enough room in buffer"));
+ Y_ENSURE(len >= 2, TStringBuf("not enough room in buffer"));
*buf = '-';
@@ -126,15 +126,15 @@ namespace {
struct TFltModifiers;
template <class T, int base, class TChar>
- Y_NO_INLINE size_t FormatInt(T value, TChar* buf, size_t len) {
+ Y_NO_INLINE size_t FormatInt(T value, TChar* buf, size_t len) {
return TIntFormatter<T, base, TChar>::Format(value, buf, len);
}
template <class T>
- inline size_t FormatFlt(T t, char* buf, size_t len) {
+ inline size_t FormatFlt(T t, char* buf, size_t len) {
const int ret = snprintf(buf, len, TFltModifiers<T>::ModifierWrite, t);
- Y_ENSURE(ret >= 0 && (size_t)ret <= len, TStringBuf("cannot format float"));
+ Y_ENSURE(ret >= 0 && (size_t)ret <= len, TStringBuf("cannot format float"));
return (size_t)ret;
}
@@ -148,7 +148,7 @@ namespace {
PS_OVERFLOW,
};
- constexpr ui8 SAFE_LENS[4][17] = {
+ constexpr ui8 SAFE_LENS[4][17] = {
{0, 0, 7, 5, 3, 3, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1},
{0, 0, 15, 10, 7, 6, 6, 5, 5, 5, 4, 4, 4, 4, 4, 4, 3},
{0, 0, 31, 20, 15, 13, 12, 11, 10, 10, 9, 9, 8, 8, 8, 8, 7},
@@ -160,7 +160,7 @@ namespace {
}
template <unsigned BASE, class TChar, class T>
- inline std::enable_if_t<(BASE > 10), bool> CharToDigit(TChar c, T* digit) noexcept {
+ inline std::enable_if_t<(BASE > 10), bool> CharToDigit(TChar c, T* digit) noexcept {
unsigned uc = c;
if (uc >= Y_ARRAY_SIZE(LetterToIntMap)) {
@@ -173,7 +173,7 @@ namespace {
}
template <unsigned BASE, class TChar, class T>
- inline std::enable_if_t<(BASE <= 10), bool> CharToDigit(TChar c, T* digit) noexcept {
+ inline std::enable_if_t<(BASE <= 10), bool> CharToDigit(TChar c, T* digit) noexcept {
return (c >= '0') && ((*digit = (c - '0')) < BASE);
}
@@ -284,7 +284,7 @@ namespace {
return PS_EMPTY_STRING;
}
- bool negative = false;
+ bool negative = false;
TUnsigned max;
if (*pos == '+') {
pos++;
@@ -329,22 +329,22 @@ namespace {
switch (status) {
case PS_EMPTY_STRING:
- ythrow TFromStringException() << TStringBuf("Cannot parse empty string as number. ");
+ ythrow TFromStringException() << TStringBuf("Cannot parse empty string as number. ");
case PS_PLUS_STRING:
- ythrow TFromStringException() << TStringBuf("Cannot parse string \"+\" as number. ");
+ ythrow TFromStringException() << TStringBuf("Cannot parse string \"+\" as number. ");
case PS_MINUS_STRING:
- ythrow TFromStringException() << TStringBuf("Cannot parse string \"-\" as number. ");
+ ythrow TFromStringException() << TStringBuf("Cannot parse string \"-\" as number. ");
case PS_BAD_SYMBOL:
- ythrow TFromStringException() << TStringBuf("Unexpected symbol \"") << EscapeC(*pos) << TStringBuf("\" at pos ") << (pos - data) << TStringBuf(" in string ") << TStringType(data, len).Quote() << TStringBuf(". ");
+ ythrow TFromStringException() << TStringBuf("Unexpected symbol \"") << EscapeC(*pos) << TStringBuf("\" at pos ") << (pos - data) << TStringBuf(" in string ") << TStringType(data, len).Quote() << TStringBuf(". ");
case PS_OVERFLOW:
- ythrow TFromStringException() << TStringBuf("Integer overflow in string ") << TStringType(data, len).Quote() << TStringBuf(". ");
+ ythrow TFromStringException() << TStringBuf("Integer overflow in string ") << TStringType(data, len).Quote() << TStringBuf(". ");
default:
- ythrow yexception() << TStringBuf("Unknown error code in string converter. ");
+ ythrow yexception() << TStringBuf("Unknown error code in string converter. ");
}
}
template <typename T, typename TUnsigned, int base, typename TChar>
- Y_NO_INLINE T ParseInt(const TChar* data, size_t len, const TBounds<TUnsigned>& bounds) {
+ Y_NO_INLINE T ParseInt(const TChar* data, size_t len, const TBounds<TUnsigned>& bounds) {
T result;
const TChar* pos = data;
EParseStatus status = TIntParser<T, base, TChar>::Parse(&pos, pos + len, bounds, &result);
@@ -357,12 +357,12 @@ namespace {
}
template <typename T, typename TUnsigned, int base, typename TChar>
- Y_NO_INLINE bool TryParseInt(const TChar* data, size_t len, const TBounds<TUnsigned>& bounds, T* result) {
+ Y_NO_INLINE bool TryParseInt(const TChar* data, size_t len, const TBounds<TUnsigned>& bounds, T* result) {
return TIntParser<T, base, TChar>::Parse(&data, data + len, bounds, result) == PS_OK;
}
template <class T>
- inline T ParseFlt(const char* data, size_t len) {
+ inline T ParseFlt(const char* data, size_t len) {
/*
* TODO
*/
@@ -384,7 +384,7 @@ namespace {
return ret;
}
- ythrow TFromStringException() << TStringBuf("cannot parse float(") << TStringBuf(data, len) << TStringBuf(")");
+ ythrow TFromStringException() << TStringBuf("cannot parse float(") << TStringBuf(data, len) << TStringBuf(")");
}
#define DEF_FLT_MOD(type, modifierWrite, modifierRead) \
@@ -405,16 +405,16 @@ namespace {
* sure they go into binary as actual values and there is no associated
* initialization code.
* */
- constexpr TBounds<ui64> bSBounds = {static_cast<ui64>(SCHAR_MAX), static_cast<ui64>(UCHAR_MAX - SCHAR_MAX)};
- constexpr TBounds<ui64> bUBounds = {static_cast<ui64>(UCHAR_MAX), 0};
- constexpr TBounds<ui64> sSBounds = {static_cast<ui64>(SHRT_MAX), static_cast<ui64>(USHRT_MAX - SHRT_MAX)};
- constexpr TBounds<ui64> sUBounds = {static_cast<ui64>(USHRT_MAX), 0};
- constexpr TBounds<ui64> iSBounds = {static_cast<ui64>(INT_MAX), static_cast<ui64>(UINT_MAX - INT_MAX)};
- constexpr TBounds<ui64> iUBounds = {static_cast<ui64>(UINT_MAX), 0};
- constexpr TBounds<ui64> lSBounds = {static_cast<ui64>(LONG_MAX), static_cast<ui64>(ULONG_MAX - LONG_MAX)};
- constexpr TBounds<ui64> lUBounds = {static_cast<ui64>(ULONG_MAX), 0};
- constexpr TBounds<ui64> llSBounds = {static_cast<ui64>(LLONG_MAX), static_cast<ui64>(ULLONG_MAX - LLONG_MAX)};
- constexpr TBounds<ui64> llUBounds = {static_cast<ui64>(ULLONG_MAX), 0};
+ constexpr TBounds<ui64> bSBounds = {static_cast<ui64>(SCHAR_MAX), static_cast<ui64>(UCHAR_MAX - SCHAR_MAX)};
+ constexpr TBounds<ui64> bUBounds = {static_cast<ui64>(UCHAR_MAX), 0};
+ constexpr TBounds<ui64> sSBounds = {static_cast<ui64>(SHRT_MAX), static_cast<ui64>(USHRT_MAX - SHRT_MAX)};
+ constexpr TBounds<ui64> sUBounds = {static_cast<ui64>(USHRT_MAX), 0};
+ constexpr TBounds<ui64> iSBounds = {static_cast<ui64>(INT_MAX), static_cast<ui64>(UINT_MAX - INT_MAX)};
+ constexpr TBounds<ui64> iUBounds = {static_cast<ui64>(UINT_MAX), 0};
+ constexpr TBounds<ui64> lSBounds = {static_cast<ui64>(LONG_MAX), static_cast<ui64>(ULONG_MAX - LONG_MAX)};
+ constexpr TBounds<ui64> lUBounds = {static_cast<ui64>(ULONG_MAX), 0};
+ constexpr TBounds<ui64> llSBounds = {static_cast<ui64>(LLONG_MAX), static_cast<ui64>(ULLONG_MAX - LLONG_MAX)};
+ constexpr TBounds<ui64> llUBounds = {static_cast<ui64>(ULLONG_MAX), 0};
}
#define DEF_INT_SPEC_II(TYPE, ITYPE, BASE) \
@@ -474,7 +474,7 @@ DEF_FLT_SPEC(long double)
template <>
size_t ToStringImpl<bool>(bool t, char* buf, size_t len) {
- Y_ENSURE(len, TStringBuf("zero length"));
+ Y_ENSURE(len, TStringBuf("zero length"));
*buf = t ? '1' : '0';
return 1;
}
@@ -510,7 +510,7 @@ bool FromStringImpl<bool>(const char* data, size_t len) {
bool result;
if (!TryFromStringImpl<bool>(data, len, result)) {
- ythrow TFromStringException() << TStringBuf("Cannot parse bool(") << TStringBuf(data, len) << TStringBuf("). ");
+ ythrow TFromStringException() << TStringBuf("Cannot parse bool(") << TStringBuf(data, len) << TStringBuf("). ");
}
return result;
@@ -683,7 +683,7 @@ template <>
double FromStringImpl<double>(const char* data, size_t len) {
double d = 0.0;
if (!TryFromStringImpl(data, len, d)) {
- ythrow TFromStringException() << TStringBuf("cannot parse float(") << TStringBuf(data, len) << TStringBuf(")");
+ ythrow TFromStringException() << TStringBuf("cannot parse float(") << TStringBuf(data, len) << TStringBuf(")");
}
return d;
}