refactor(string): refactor string conversion and turning off default parsing options such as auto detect base
This commit is contained in:
parent
1c0c93ee25
commit
f6f696d5a7
@ -458,6 +458,7 @@ void TestStringConversion()
|
|||||||
{
|
{
|
||||||
auto Test = []<typename T>(TInPlaceType<T>)
|
auto Test = []<typename T>(TInPlaceType<T>)
|
||||||
{
|
{
|
||||||
|
|
||||||
always_check(TString<T>::Format(LITERAL(T, "#{}#"), true ) == LITERAL(T, "#True#" ));
|
always_check(TString<T>::Format(LITERAL(T, "#{}#"), true ) == LITERAL(T, "#True#" ));
|
||||||
always_check(TString<T>::Format(LITERAL(T, "#{}#"), false) == LITERAL(T, "#False#"));
|
always_check(TString<T>::Format(LITERAL(T, "#{}#"), false) == LITERAL(T, "#False#"));
|
||||||
|
|
||||||
@ -467,11 +468,11 @@ void TestStringConversion()
|
|||||||
|
|
||||||
always_check(TString<T>::Format(LITERAL(T, "#{}#"), 42) == LITERAL(T, "#42#"));
|
always_check(TString<T>::Format(LITERAL(T, "#{}#"), 42) == LITERAL(T, "#42#"));
|
||||||
|
|
||||||
always_check(TString<T>::Format(LITERAL(T, "#{}#"), +0.0) == LITERAL(T, "#0.000000#"));
|
always_check(TString<T>::Format(LITERAL(T, "#{}#"), +0.0) == LITERAL(T, "#0#"));
|
||||||
always_check(TString<T>::Format(LITERAL(T, "#{}#"), 0.0) == LITERAL(T, "#0.000000#"));
|
always_check(TString<T>::Format(LITERAL(T, "#{}#"), 0.0) == LITERAL(T, "#0#"));
|
||||||
always_check(TString<T>::Format(LITERAL(T, "#{}#"), -0.0) == LITERAL(T, "#-0.000000#"));
|
always_check(TString<T>::Format(LITERAL(T, "#{}#"), -0.0) == LITERAL(T, "#-0#"));
|
||||||
|
|
||||||
always_check(TString<T>::Format(LITERAL(T, "#{}#"), 3.140000) == LITERAL(T, "#3.140000#"));
|
always_check(TString<T>::Format(LITERAL(T, "#{}#"), 3.14) == LITERAL(T, "#3.14#"));
|
||||||
|
|
||||||
always_check(TString<T>::Format(LITERAL(T, "#{}#"), +NAMESPACE_STD::numeric_limits<float>::infinity()) == LITERAL(T, "#Infinity#"));
|
always_check(TString<T>::Format(LITERAL(T, "#{}#"), +NAMESPACE_STD::numeric_limits<float>::infinity()) == LITERAL(T, "#Infinity#"));
|
||||||
always_check(TString<T>::Format(LITERAL(T, "#{}#"), -NAMESPACE_STD::numeric_limits<float>::infinity()) == LITERAL(T, "#-Infinity#"));
|
always_check(TString<T>::Format(LITERAL(T, "#{}#"), -NAMESPACE_STD::numeric_limits<float>::infinity()) == LITERAL(T, "#-Infinity#"));
|
||||||
@ -505,62 +506,62 @@ void TestStringConversion()
|
|||||||
|
|
||||||
auto CheckParseInt = [&]<typename U>(TInPlaceType<U>)
|
auto CheckParseInt = [&]<typename U>(TInPlaceType<U>)
|
||||||
{
|
{
|
||||||
CheckParseArithmetic(LITERAL(T, "+0"), static_cast<U>(+0.0));
|
// CheckParseArithmetic(LITERAL(T, "+0"), static_cast<U>(+0.0));
|
||||||
CheckParseArithmetic(LITERAL(T, " 0"), static_cast<U>( 0.0));
|
CheckParseArithmetic(LITERAL(T, " 0"), static_cast<U>( 0.0));
|
||||||
CheckParseArithmetic(LITERAL(T, "-0"), static_cast<U>(-0.0));
|
CheckParseArithmetic(LITERAL(T, "-0"), static_cast<U>(-0.0));
|
||||||
|
|
||||||
CheckParseArithmetic(LITERAL(T, "+42"), static_cast<U>( +42));
|
// CheckParseArithmetic(LITERAL(T, "+42"), static_cast<U>( +42));
|
||||||
CheckParseArithmetic(LITERAL(T, "+052"), static_cast<U>( +052));
|
// CheckParseArithmetic(LITERAL(T, "+052"), static_cast<U>( +052));
|
||||||
CheckParseArithmetic(LITERAL(T, "+0x2A"), static_cast<U>( +0x2A));
|
// CheckParseArithmetic(LITERAL(T, "+0x2A"), static_cast<U>( +0x2A));
|
||||||
CheckParseArithmetic(LITERAL(T, "+0b101010"), static_cast<U>(+0b101010));
|
// CheckParseArithmetic(LITERAL(T, "+0b101010"), static_cast<U>(+0b101010));
|
||||||
|
|
||||||
CheckParseArithmetic(LITERAL(T, "42"), static_cast<U>( 42));
|
CheckParseArithmetic(LITERAL(T, "42"), static_cast<U>( 42));
|
||||||
CheckParseArithmetic(LITERAL(T, "052"), static_cast<U>( 052));
|
// CheckParseArithmetic(LITERAL(T, "052"), static_cast<U>( 052));
|
||||||
CheckParseArithmetic(LITERAL(T, "0x2A"), static_cast<U>( 0x2A));
|
// CheckParseArithmetic(LITERAL(T, "0x2A"), static_cast<U>( 0x2A));
|
||||||
CheckParseArithmetic(LITERAL(T, "0b101010"), static_cast<U>(0b101010));
|
// CheckParseArithmetic(LITERAL(T, "0b101010"), static_cast<U>(0b101010));
|
||||||
|
|
||||||
CheckParseArithmetic(LITERAL(T, "-42"), static_cast<U>( -42));
|
CheckParseArithmetic(LITERAL(T, "-42"), static_cast<U>( -42));
|
||||||
CheckParseArithmetic(LITERAL(T, "-052"), static_cast<U>( -052));
|
// CheckParseArithmetic(LITERAL(T, "-052"), static_cast<U>( -052));
|
||||||
CheckParseArithmetic(LITERAL(T, "-0x2A"), static_cast<U>( -0x2A));
|
// CheckParseArithmetic(LITERAL(T, "-0x2A"), static_cast<U>( -0x2A));
|
||||||
CheckParseArithmetic(LITERAL(T, "-0b101010"), static_cast<U>(-0b101010));
|
// CheckParseArithmetic(LITERAL(T, "-0b101010"), static_cast<U>(-0b101010));
|
||||||
};
|
};
|
||||||
|
|
||||||
CheckParseInt(InPlaceType<bool>);
|
// CheckParseInt(InPlaceType<bool>);
|
||||||
|
|
||||||
CheckParseInt(InPlaceType<int8>);
|
CheckParseInt(InPlaceType<int8>);
|
||||||
CheckParseInt(InPlaceType<int16>);
|
CheckParseInt(InPlaceType<int16>);
|
||||||
CheckParseInt(InPlaceType<int32>);
|
CheckParseInt(InPlaceType<int32>);
|
||||||
CheckParseInt(InPlaceType<int64>);
|
CheckParseInt(InPlaceType<int64>);
|
||||||
|
|
||||||
CheckParseInt(InPlaceType<uint8>);
|
// CheckParseInt(InPlaceType<uint8>);
|
||||||
CheckParseInt(InPlaceType<uint16>);
|
// CheckParseInt(InPlaceType<uint16>);
|
||||||
CheckParseInt(InPlaceType<uint32>);
|
// CheckParseInt(InPlaceType<uint32>);
|
||||||
CheckParseInt(InPlaceType<uint64>);
|
// CheckParseInt(InPlaceType<uint64>);
|
||||||
|
|
||||||
auto CheckParseFloat = [&]<typename U>(TInPlaceType<U>)
|
auto CheckParseFloat = [&]<typename U>(TInPlaceType<U>)
|
||||||
{
|
{
|
||||||
CheckParseInt(InPlaceType<U>);
|
CheckParseInt(InPlaceType<U>);
|
||||||
|
|
||||||
CheckParseArithmetic(LITERAL(T, "+3.14"), static_cast<U>( +3.14));
|
// CheckParseArithmetic(LITERAL(T, "+3.14"), static_cast<U>( +3.14));
|
||||||
CheckParseArithmetic(LITERAL(T, "+3.14e2"), static_cast<U>( +3.14e2));
|
// CheckParseArithmetic(LITERAL(T, "+3.14e2"), static_cast<U>( +3.14e2));
|
||||||
CheckParseArithmetic(LITERAL(T, "+3.14e-2"), static_cast<U>( +3.14e-2));
|
// CheckParseArithmetic(LITERAL(T, "+3.14e-2"), static_cast<U>( +3.14e-2));
|
||||||
CheckParseArithmetic(LITERAL(T, "+0x1.91eb86p1"), static_cast<U>(+0x1.91eb86p1));
|
// CheckParseArithmetic(LITERAL(T, "+0x1.91eb86p1"), static_cast<U>(+0x1.91eb86p1));
|
||||||
|
|
||||||
CheckParseArithmetic(LITERAL(T, "3.14"), static_cast<U>( 3.14));
|
CheckParseArithmetic(LITERAL(T, "3.14"), static_cast<U>( 3.14));
|
||||||
CheckParseArithmetic(LITERAL(T, "3.14e2"), static_cast<U>( 3.14e2));
|
CheckParseArithmetic(LITERAL(T, "3.14e2"), static_cast<U>( 3.14e2));
|
||||||
CheckParseArithmetic(LITERAL(T, "3.14e-2"), static_cast<U>( 3.14e-2));
|
CheckParseArithmetic(LITERAL(T, "3.14e-2"), static_cast<U>( 3.14e-2));
|
||||||
CheckParseArithmetic(LITERAL(T, "0x1.91eb86p1"), static_cast<U>(0x1.91eb86p1));
|
// CheckParseArithmetic(LITERAL(T, "0x1.91eb86p1"), static_cast<U>(0x1.91eb86p1));
|
||||||
|
|
||||||
CheckParseArithmetic(LITERAL(T, "-3.14"), static_cast<U>( -3.14));
|
CheckParseArithmetic(LITERAL(T, "-3.14"), static_cast<U>( -3.14));
|
||||||
CheckParseArithmetic(LITERAL(T, "-3.14e2"), static_cast<U>( -3.14e2));
|
CheckParseArithmetic(LITERAL(T, "-3.14e2"), static_cast<U>( -3.14e2));
|
||||||
CheckParseArithmetic(LITERAL(T, "-3.14e-2"), static_cast<U>( -3.14e-2));
|
CheckParseArithmetic(LITERAL(T, "-3.14e-2"), static_cast<U>( -3.14e-2));
|
||||||
CheckParseArithmetic(LITERAL(T, "-0x1.91eb86p1"), static_cast<U>(-0x1.91eb86p1));
|
// CheckParseArithmetic(LITERAL(T, "-0x1.91eb86p1"), static_cast<U>(-0x1.91eb86p1));
|
||||||
|
|
||||||
CheckParseArithmetic(LITERAL(T, "+Infinity"), +NAMESPACE_STD::numeric_limits<U>::infinity());
|
// CheckParseArithmetic(LITERAL(T, "+Infinity"), +NAMESPACE_STD::numeric_limits<U>::infinity());
|
||||||
CheckParseArithmetic(LITERAL(T, " Infinity"), +NAMESPACE_STD::numeric_limits<U>::infinity());
|
CheckParseArithmetic(LITERAL(T, " Infinity"), +NAMESPACE_STD::numeric_limits<U>::infinity());
|
||||||
CheckParseArithmetic(LITERAL(T, "-Infinity"), -NAMESPACE_STD::numeric_limits<U>::infinity());
|
CheckParseArithmetic(LITERAL(T, "-Infinity"), -NAMESPACE_STD::numeric_limits<U>::infinity());
|
||||||
|
|
||||||
CheckParseArithmetic(LITERAL(T, "+NaN"), +NAMESPACE_STD::numeric_limits<U>::quiet_NaN());
|
// CheckParseArithmetic(LITERAL(T, "+NaN"), +NAMESPACE_STD::numeric_limits<U>::quiet_NaN());
|
||||||
CheckParseArithmetic(LITERAL(T, " NaN"), +NAMESPACE_STD::numeric_limits<U>::quiet_NaN());
|
CheckParseArithmetic(LITERAL(T, " NaN"), +NAMESPACE_STD::numeric_limits<U>::quiet_NaN());
|
||||||
CheckParseArithmetic(LITERAL(T, "-NaN"), -NAMESPACE_STD::numeric_limits<U>::quiet_NaN());
|
CheckParseArithmetic(LITERAL(T, "-NaN"), -NAMESPACE_STD::numeric_limits<U>::quiet_NaN());
|
||||||
};
|
};
|
||||||
@ -610,8 +611,8 @@ void TestStringConversion()
|
|||||||
always_check(LITERAL_VIEW(T, "0" ).ToInt() == 0 );
|
always_check(LITERAL_VIEW(T, "0" ).ToInt() == 0 );
|
||||||
always_check(LITERAL_VIEW(T, "Invalid").ToInt() == 0 );
|
always_check(LITERAL_VIEW(T, "Invalid").ToInt() == 0 );
|
||||||
|
|
||||||
always_check(LITERAL_VIEW(T, "999999999999999999999999999999").ToInt() == NAMESPACE_STD::numeric_limits<int>::max());
|
always_check(LITERAL_VIEW(T, "999999999999999999999999999999").ToInt() == 0);
|
||||||
always_check(LITERAL_VIEW(T, "-999999999999999999999999999999").ToInt() == NAMESPACE_STD::numeric_limits<int>::min());
|
always_check(LITERAL_VIEW(T, "-999999999999999999999999999999").ToInt() == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
@ -620,17 +621,10 @@ void TestStringConversion()
|
|||||||
always_check(LITERAL_VIEW(T, "-3.14" ).ToFloat() == -3.14f);
|
always_check(LITERAL_VIEW(T, "-3.14" ).ToFloat() == -3.14f);
|
||||||
always_check(LITERAL_VIEW(T, "0.0" ).ToFloat() == 0.0f );
|
always_check(LITERAL_VIEW(T, "0.0" ).ToFloat() == 0.0f );
|
||||||
|
|
||||||
always_check(LITERAL_VIEW(T, "1e+308").ToFloat() == NAMESPACE_STD::numeric_limits<float>::infinity());
|
always_check(NAMESPACE_STD::isnan(LITERAL_VIEW(T, "1e+308").ToFloat()));
|
||||||
always_check(LITERAL_VIEW(T, "-1e+308").ToFloat() == -NAMESPACE_STD::numeric_limits<float>::infinity());
|
always_check(NAMESPACE_STD::isnan(LITERAL_VIEW(T, "-1e+308").ToFloat()));
|
||||||
always_check(LITERAL_VIEW(T, "1e-308").ToFloat() == 0.0f);
|
always_check(NAMESPACE_STD::isnan(LITERAL_VIEW(T, "1e-308").ToFloat()));
|
||||||
always_check(LITERAL_VIEW(T, "-1e-308").ToFloat() == -0.0f);
|
always_check(NAMESPACE_STD::isnan(LITERAL_VIEW(T, "-1e-308").ToFloat()));
|
||||||
|
|
||||||
always_check(LITERAL_VIEW(T, "100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.e-4").ToFloat() == NAMESPACE_STD::numeric_limits<float>::infinity());
|
|
||||||
always_check(LITERAL_VIEW(T, "-100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.e-4").ToFloat() == -NAMESPACE_STD::numeric_limits<float>::infinity());
|
|
||||||
always_check(LITERAL_VIEW(T, "1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000e-4").ToFloat() == NAMESPACE_STD::numeric_limits<float>::infinity());
|
|
||||||
always_check(LITERAL_VIEW(T, "-1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000e-4").ToFloat() == -NAMESPACE_STD::numeric_limits<float>::infinity());
|
|
||||||
always_check(LITERAL_VIEW(T, "0.00000000000000000000000000000000000000000000000000000000000000000000000000000000000000001e+4").ToFloat() == 0.0f);
|
|
||||||
always_check(LITERAL_VIEW(T, "-0.00000000000000000000000000000000000000000000000000000000000000000000000000000000000000001e+4").ToFloat() == -0.0f);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -1239,8 +1239,8 @@ public:
|
|||||||
/**
|
/**
|
||||||
* Converts a string into a boolean value.
|
* Converts a string into a boolean value.
|
||||||
*
|
*
|
||||||
* - 1, "true", "True", "TRUE" and non-zero integers become true.
|
* - "True" and non-zero integers become true.
|
||||||
* - 0, "false", "False", "FALSE" and unparsable values become false.
|
* - "False" and unparsable values become false.
|
||||||
*
|
*
|
||||||
* @return The boolean value.
|
* @return The boolean value.
|
||||||
*/
|
*/
|
||||||
|
Loading…
Reference in New Issue
Block a user