rename functions for converting strings to integers to snake case
while here: - add some functions taking std::string/std::wstring
This commit is contained in:
@@ -5,7 +5,7 @@
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2017-2021, Tomasz Sowa
|
||||
* Copyright (c) 2017-2022, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -44,10 +44,8 @@ namespace pt
|
||||
{
|
||||
|
||||
|
||||
|
||||
|
||||
template<typename CharType>
|
||||
unsigned long long Toull(const CharType * str, int base = 10, const CharType ** after_str = 0, bool * was_overflow = 0, bool allow_skip_whitechars = true)
|
||||
unsigned long long to_ull(const CharType * str, int base = 10, const CharType ** after_str = 0, bool * was_overflow = 0, bool allow_skip_whitechars = true)
|
||||
{
|
||||
unsigned long long res = 0;
|
||||
bool carry = false;
|
||||
@@ -96,8 +94,16 @@ unsigned long long Toull(const CharType * str, int base = 10, const CharType **
|
||||
}
|
||||
|
||||
|
||||
template<class StringType>
|
||||
unsigned long long to_ull(const StringType & str, int base = 10, const typename StringType::value_type ** after_str = 0, bool * was_overflow = 0, bool allow_skip_whitechars = true)
|
||||
{
|
||||
return to_ull(str.c_str(), base, after_str, was_overflow, allow_skip_whitechars);
|
||||
}
|
||||
|
||||
|
||||
|
||||
template<typename CharType>
|
||||
long long Toll(const CharType * str, int base = 10, const CharType ** after_str = 0, bool * was_overflow = 0, bool allow_skip_whitechars = true)
|
||||
long long to_ll(const CharType * str, int base = 10, const CharType ** after_str = 0, bool * was_overflow = 0, bool allow_skip_whitechars = true)
|
||||
{
|
||||
bool was_sign = false;
|
||||
bool was_overflow_u = false;
|
||||
@@ -113,7 +119,7 @@ long long Toll(const CharType * str, int base = 10, const CharType ** after_str
|
||||
str += 1;
|
||||
}
|
||||
|
||||
unsigned long long uval = Toull(str, base, after_str, &was_overflow_u, false);
|
||||
unsigned long long uval = to_ull(str, base, after_str, &was_overflow_u, false);
|
||||
unsigned long long sign_add = ( was_sign ) ? 1 : 0;
|
||||
|
||||
if( was_overflow_u )
|
||||
@@ -138,14 +144,21 @@ long long Toll(const CharType * str, int base = 10, const CharType ** after_str
|
||||
|
||||
|
||||
|
||||
template<class StringType>
|
||||
long long to_ll(const StringType & str, int base = 10, const typename StringType::value_type ** after_str = 0, bool * was_overflow = 0, bool allow_skip_whitechars = true)
|
||||
{
|
||||
return to_ll(str.c_str(), base, after_str, was_overflow, allow_skip_whitechars);
|
||||
}
|
||||
|
||||
|
||||
|
||||
template<typename CharType, typename IntegerType>
|
||||
IntegerType ToUnsignedIntegerType(const CharType * str, int base = 10, const CharType ** after_str = 0, bool * was_overflow = 0, bool allow_skip_whitechars = true)
|
||||
IntegerType to_unsigned_integer_type(const CharType * str, int base = 10, const CharType ** after_str = 0, bool * was_overflow = 0, bool allow_skip_whitechars = true)
|
||||
{
|
||||
bool was_overflow_ll = false;
|
||||
|
||||
SetOverflow(was_overflow, false);
|
||||
unsigned long long val = Toull(str, base, after_str, &was_overflow_ll, allow_skip_whitechars);
|
||||
unsigned long long val = to_ull(str, base, after_str, &was_overflow_ll, allow_skip_whitechars);
|
||||
|
||||
if( was_overflow_ll || val > static_cast<unsigned long long>(std::numeric_limits<IntegerType>::max()) )
|
||||
{
|
||||
@@ -158,28 +171,39 @@ IntegerType ToUnsignedIntegerType(const CharType * str, int base = 10, const Cha
|
||||
|
||||
|
||||
template<class CharType>
|
||||
unsigned long Toul(const CharType * str, int base = 10, const CharType ** after_str = 0, bool * was_overflow = 0, bool allow_skip_whitechars = true)
|
||||
unsigned long to_ul(const CharType * str, int base = 10, const CharType ** after_str = 0, bool * was_overflow = 0, bool allow_skip_whitechars = true)
|
||||
{
|
||||
return ToUnsignedIntegerType<CharType, unsigned long>(str, base, after_str, was_overflow, allow_skip_whitechars);
|
||||
return to_unsigned_integer_type<CharType, unsigned long>(str, base, after_str, was_overflow, allow_skip_whitechars);
|
||||
}
|
||||
|
||||
template<class StringType>
|
||||
unsigned long to_ul(const StringType & str, int base = 10, const typename StringType::value_type ** after_str = 0, bool * was_overflow = 0, bool allow_skip_whitechars = true)
|
||||
{
|
||||
return to_unsigned_integer_type<typename StringType::value_type, unsigned long>(str.c_str(), base, after_str, was_overflow, allow_skip_whitechars);
|
||||
}
|
||||
|
||||
template<class CharType>
|
||||
unsigned int Toui(const CharType * str, int base = 10, const CharType ** after_str = 0, bool * was_overflow = 0, bool allow_skip_whitechars = true)
|
||||
unsigned int to_ui(const CharType * str, int base = 10, const CharType ** after_str = 0, bool * was_overflow = 0, bool allow_skip_whitechars = true)
|
||||
{
|
||||
return ToUnsignedIntegerType<CharType, unsigned int>(str, base, after_str, was_overflow, allow_skip_whitechars);
|
||||
return to_unsigned_integer_type<CharType, unsigned int>(str, base, after_str, was_overflow, allow_skip_whitechars);
|
||||
}
|
||||
|
||||
template<class StringType>
|
||||
unsigned int to_ui(const StringType & str, int base = 10, const typename StringType::value_type ** after_str = 0, bool * was_overflow = 0, bool allow_skip_whitechars = true)
|
||||
{
|
||||
return to_unsigned_integer_type<typename StringType::value_type, unsigned int>(str.c_str(), base, after_str, was_overflow, allow_skip_whitechars);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
template<typename CharType, typename IntegerType>
|
||||
IntegerType ToIntegerType(const CharType * str, int base = 10, const CharType ** after_str = 0, bool * was_overflow = 0, bool allow_skip_whitechars = true)
|
||||
IntegerType to_integer_type(const CharType * str, int base = 10, const CharType ** after_str = 0, bool * was_overflow = 0, bool allow_skip_whitechars = true)
|
||||
{
|
||||
bool was_overflow_ll = false;
|
||||
|
||||
SetOverflow(was_overflow, false);
|
||||
long long val = Toll(str, base, after_str, &was_overflow_ll, allow_skip_whitechars);
|
||||
long long val = to_ll(str, base, after_str, &was_overflow_ll, allow_skip_whitechars);
|
||||
|
||||
if( was_overflow_ll ||
|
||||
val < static_cast<long long>(std::numeric_limits<IntegerType>::min()) ||
|
||||
@@ -195,22 +219,28 @@ IntegerType ToIntegerType(const CharType * str, int base = 10, const CharType **
|
||||
|
||||
|
||||
template<class CharType>
|
||||
long Tol(const CharType * str, int base = 10, const CharType ** after_str = 0, bool * was_overflow = 0, bool allow_skip_whitechars = true)
|
||||
long to_l(const CharType * str, int base = 10, const CharType ** after_str = 0, bool * was_overflow = 0, bool allow_skip_whitechars = true)
|
||||
{
|
||||
return ToIntegerType<CharType, long>(str, base, after_str, was_overflow, allow_skip_whitechars);
|
||||
return to_integer_type<CharType, long>(str, base, after_str, was_overflow, allow_skip_whitechars);
|
||||
}
|
||||
|
||||
template<class StringType>
|
||||
long to_l(const StringType & str, int base = 10, const typename StringType::value_type ** after_str = 0, bool * was_overflow = 0, bool allow_skip_whitechars = true)
|
||||
{
|
||||
return to_integer_type<typename StringType::value_type, long>(str.c_str(), base, after_str, was_overflow, allow_skip_whitechars);
|
||||
}
|
||||
|
||||
template<class CharType>
|
||||
int Toi(const CharType * str, int base = 10, const CharType ** after_str = 0, bool * was_overflow = 0, bool allow_skip_whitechars = true)
|
||||
int to_i(const CharType * str, int base = 10, const CharType ** after_str = 0, bool * was_overflow = 0, bool allow_skip_whitechars = true)
|
||||
{
|
||||
return ToIntegerType<CharType, int>(str, base, after_str, was_overflow, allow_skip_whitechars);
|
||||
return to_integer_type<CharType, int>(str, base, after_str, was_overflow, allow_skip_whitechars);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
template<class StringType>
|
||||
int to_i(const StringType & str, int base = 10, const typename StringType::value_type ** after_str = 0, bool * was_overflow = 0, bool allow_skip_whitechars = true)
|
||||
{
|
||||
return to_integer_type<typename StringType::value_type, int>(str.c_str(), base, after_str, was_overflow, allow_skip_whitechars);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
@@ -224,7 +254,7 @@ int Toi(const CharType * str, int base = 10, const CharType ** after_str = 0, bo
|
||||
*
|
||||
*/
|
||||
template<typename CharType>
|
||||
unsigned long long Toull_b(const CharType * str, const CharType ** after_str = 0, bool * was_overflow = 0, bool allow_skip_whitechars = true)
|
||||
unsigned long long to_ull_b(const CharType * str, const CharType ** after_str = 0, bool * was_overflow = 0, bool allow_skip_whitechars = true)
|
||||
{
|
||||
if( allow_skip_whitechars )
|
||||
str = skip_white(str);
|
||||
@@ -249,13 +279,13 @@ unsigned long long Toull_b(const CharType * str, const CharType ** after_str = 0
|
||||
str += 1;
|
||||
}
|
||||
|
||||
return Toull(str, base, after_str, was_overflow, false);
|
||||
return to_ull(str, base, after_str, was_overflow, false);
|
||||
}
|
||||
|
||||
|
||||
|
||||
template<typename CharType>
|
||||
long long Toll_b(const CharType * str, const CharType ** after_str = 0, bool * was_overflow = 0, bool allow_skip_whitechars = true)
|
||||
long long to_ll_b(const CharType * str, const CharType ** after_str = 0, bool * was_overflow = 0, bool allow_skip_whitechars = true)
|
||||
{
|
||||
bool was_sign = false;
|
||||
bool was_overflow_u = false;
|
||||
@@ -271,7 +301,7 @@ long long Toll_b(const CharType * str, const CharType ** after_str = 0, bool * w
|
||||
str += 1;
|
||||
}
|
||||
|
||||
unsigned long long uval = Toull_b(str, after_str, &was_overflow_u, false);
|
||||
unsigned long long uval = to_ull_b(str, after_str, &was_overflow_u, false);
|
||||
unsigned long long sign_add = ( was_sign ) ? 1 : 0;
|
||||
|
||||
if( was_overflow_u )
|
||||
@@ -302,12 +332,12 @@ long long Toll_b(const CharType * str, const CharType ** after_str = 0, bool * w
|
||||
|
||||
|
||||
template<typename CharType, typename IntegerType>
|
||||
IntegerType ToUnsignedIntegerType_b(const CharType * str, const CharType ** after_str = 0, bool * was_overflow = 0, bool allow_skip_whitechars = true)
|
||||
IntegerType to_unsigned_integer_type_b(const CharType * str, const CharType ** after_str = 0, bool * was_overflow = 0, bool allow_skip_whitechars = true)
|
||||
{
|
||||
bool was_overflow_ll = false;
|
||||
|
||||
SetOverflow(was_overflow, false);
|
||||
unsigned long long val = Toull_b(str, after_str, &was_overflow_ll, allow_skip_whitechars);
|
||||
unsigned long long val = to_ull_b(str, after_str, &was_overflow_ll, allow_skip_whitechars);
|
||||
|
||||
if( was_overflow_ll || val > static_cast<unsigned long long>(std::numeric_limits<IntegerType>::max()) )
|
||||
{
|
||||
@@ -320,15 +350,15 @@ IntegerType ToUnsignedIntegerType_b(const CharType * str, const CharType ** afte
|
||||
|
||||
|
||||
template<class CharType>
|
||||
unsigned long Toul_b(const CharType * str, const CharType ** after_str = 0, bool * was_overflow = 0, bool allow_skip_whitechars = true)
|
||||
unsigned long to_ul_b(const CharType * str, const CharType ** after_str = 0, bool * was_overflow = 0, bool allow_skip_whitechars = true)
|
||||
{
|
||||
return ToUnsignedIntegerType_b<CharType, unsigned long>(str, after_str, was_overflow, allow_skip_whitechars);
|
||||
return to_unsigned_integer_type_b<CharType, unsigned long>(str, after_str, was_overflow, allow_skip_whitechars);
|
||||
}
|
||||
|
||||
template<class CharType>
|
||||
unsigned int Toui_b(const CharType * str, const CharType ** after_str = 0, bool * was_overflow = 0, bool allow_skip_whitechars = true)
|
||||
unsigned int to_ui_b(const CharType * str, const CharType ** after_str = 0, bool * was_overflow = 0, bool allow_skip_whitechars = true)
|
||||
{
|
||||
return ToUnsignedIntegerType_b<CharType, unsigned int>(str, after_str, was_overflow, allow_skip_whitechars);
|
||||
return to_unsigned_integer_type_b<CharType, unsigned int>(str, after_str, was_overflow, allow_skip_whitechars);
|
||||
}
|
||||
|
||||
|
||||
@@ -336,12 +366,12 @@ unsigned int Toui_b(const CharType * str, const CharType ** after_str = 0, bool
|
||||
|
||||
|
||||
template<typename CharType, typename IntegerType>
|
||||
IntegerType ToIntegerType_b(const CharType * str, const CharType ** after_str = 0, bool * was_overflow = 0, bool allow_skip_whitechars = true)
|
||||
IntegerType to_integer_type_b(const CharType * str, const CharType ** after_str = 0, bool * was_overflow = 0, bool allow_skip_whitechars = true)
|
||||
{
|
||||
bool was_overflow_ll = false;
|
||||
|
||||
SetOverflow(was_overflow, false);
|
||||
long long val = Toll_b(str, after_str, &was_overflow_ll, allow_skip_whitechars);
|
||||
long long val = to_ll_b(str, after_str, &was_overflow_ll, allow_skip_whitechars);
|
||||
|
||||
if( was_overflow_ll ||
|
||||
val < static_cast<long long>(std::numeric_limits<IntegerType>::min()) ||
|
||||
@@ -357,15 +387,15 @@ IntegerType ToIntegerType_b(const CharType * str, const CharType ** after_str =
|
||||
|
||||
|
||||
template<class CharType>
|
||||
long Tol_b(const CharType * str, const CharType ** after_str = 0, bool * was_overflow = 0, bool allow_skip_whitechars = true)
|
||||
long to_l_b(const CharType * str, const CharType ** after_str = 0, bool * was_overflow = 0, bool allow_skip_whitechars = true)
|
||||
{
|
||||
return ToIntegerType_b<CharType, long>(str, after_str, was_overflow, allow_skip_whitechars);
|
||||
return to_integer_type_b<CharType, long>(str, after_str, was_overflow, allow_skip_whitechars);
|
||||
}
|
||||
|
||||
template<class CharType>
|
||||
int Toi_b(const CharType * str, const CharType ** after_str = 0, bool * was_overflow = 0, bool allow_skip_whitechars = true)
|
||||
int to_i_b(const CharType * str, const CharType ** after_str = 0, bool * was_overflow = 0, bool allow_skip_whitechars = true)
|
||||
{
|
||||
return ToIntegerType_b<CharType, int>(str, after_str, was_overflow, allow_skip_whitechars);
|
||||
return to_integer_type_b<CharType, int>(str, after_str, was_overflow, allow_skip_whitechars);
|
||||
}
|
||||
|
||||
|
||||
|
@@ -1072,7 +1072,7 @@ long long Space::convert_string_to_long_long() const
|
||||
{
|
||||
bool was_overflow = false;
|
||||
const char * after_str;
|
||||
long long val = Toll(value.value_string.c_str(), 10, &after_str, &was_overflow, true);
|
||||
long long val = to_ll(value.value_string.c_str(), 10, &after_str, &was_overflow, true);
|
||||
|
||||
return was_overflow ? 0 : val;
|
||||
}
|
||||
@@ -1082,7 +1082,7 @@ long long Space::convert_wstring_to_long_long() const
|
||||
{
|
||||
bool was_overflow = false;
|
||||
const wchar_t * after_str;
|
||||
long long val = Toll(value.value_wstring.c_str(), 10, &after_str, &was_overflow, true);
|
||||
long long val = to_ll(value.value_wstring.c_str(), 10, &after_str, &was_overflow, true);
|
||||
|
||||
return was_overflow ? 0 : val;
|
||||
}
|
||||
@@ -1092,7 +1092,7 @@ unsigned long long Space::convert_string_to_ulong_long() const
|
||||
{
|
||||
bool was_overflow = false;
|
||||
const char * after_str;
|
||||
unsigned long long val = Toull(value.value_string.c_str(), 10, &after_str, &was_overflow, true);
|
||||
unsigned long long val = to_ull(value.value_string.c_str(), 10, &after_str, &was_overflow, true);
|
||||
|
||||
return was_overflow ? 0 : val;
|
||||
}
|
||||
@@ -1102,7 +1102,7 @@ unsigned long long Space::convert_wstring_to_ulong_long() const
|
||||
{
|
||||
bool was_overflow = false;
|
||||
const wchar_t * after_str;
|
||||
unsigned long long val = Toull(value.value_wstring.c_str(), 10, &after_str, &was_overflow, true);
|
||||
unsigned long long val = to_ull(value.value_wstring.c_str(), 10, &after_str, &was_overflow, true);
|
||||
|
||||
return was_overflow ? 0 : val;
|
||||
}
|
||||
|
@@ -572,7 +572,7 @@ void SpaceParser::parse_integer_value(Space * space)
|
||||
base = 8;
|
||||
}
|
||||
|
||||
long long val = Toll(token.c_str(), base, &after_str, &was_overflow, false);
|
||||
long long val = to_ll(token.c_str(), base, &after_str, &was_overflow, false);
|
||||
|
||||
if( was_overflow )
|
||||
{
|
||||
|
Reference in New Issue
Block a user