27 const size_t signLength = ( !aText.empty() && ( aText[0] ==
'-' || aText[0] ==
'+' ) ) ? 1 : 0;
28 const size_t point = aText.find(
'.' );
30 if( point == std::string::npos )
33 const std::string whole = aText.substr( signLength, point - signLength );
34 std::string fraction = aText.substr( point + 1 );
36 if( whole.empty() && fraction.empty() )
39 if( whole.find_first_not_of(
"0123456789" ) != std::string::npos
40 || fraction.find_first_not_of(
"0123456789" ) != std::string::npos )
45 fraction.erase( fraction.find_last_not_of(
'0' ) + 1 );
47 if( fraction.empty() && whole.find_first_not_of(
'0' ) == std::string::npos )
50 std::string
result = aText.substr( 0, signLength ) + ( whole.empty() ?
"0" : whole );
52 if( !fraction.empty() )
63 std::string operator()( std::monostate )
const {
return std::string(); }
64 std::string operator()(
const std::string& aString )
const {
return aString; }
65 std::string operator()( int64_t aInt )
const {
return std::to_string( aInt ); }
66 std::string operator()(
bool aBool )
const {
return aBool ?
"1" :
"0"; }
68 std::string operator()(
double aDouble )
const
71 return aDouble == 0.0 ? std::string(
"0" ) : fmt::format(
"{}", aDouble );
75 return std::visit( VISITOR(), aValue );
std::variant< std::monostate, std::string, int64_t, double, bool > DB_VALUE
A single database cell, where monostate is SQL NULL.
wxString result
Test unit parsing edge cases and error handling.