Include :
- modifiche a FromString con double per uso libreria fast_float.
This commit is contained in:
+14
-19
@@ -15,6 +15,7 @@
|
||||
|
||||
#include "/EgtDev/Include/EgtStringBase.h"
|
||||
#include "/EgtDev/Include/EgtNumCollection.h"
|
||||
#include "/EgtDev/Extern/fast_float/fast_float.h"
|
||||
#include <algorithm>
|
||||
#include <array>
|
||||
|
||||
@@ -123,6 +124,7 @@ ValidateDxfName( std::string& sName, bool bAdvanced)
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
#define FAST_FLOAT_FMT fast_float::chars_format::general | fast_float::chars_format::allow_leading_plus | fast_float::chars_format::skip_white_space
|
||||
inline bool
|
||||
FromString( const std::string& sVal, int& nVal)
|
||||
{ const char* pStart = sVal.c_str() ;
|
||||
@@ -146,11 +148,8 @@ FromString( const std::string& sVal, bool& bVal)
|
||||
return true ; }
|
||||
inline bool
|
||||
FromString( const std::string& sVal, double& dVal)
|
||||
{ const char* pStart = sVal.c_str() ;
|
||||
char* pStop ;
|
||||
errno = 0 ;
|
||||
dVal = strtod( pStart, &pStop) ;
|
||||
return ( pStop != pStart && errno == 0) ; }
|
||||
{ auto answer = fast_float::from_chars( sVal.data(), sVal.data() + sVal.size(), dVal, FAST_FLOAT_FMT) ;
|
||||
return ( answer.ec == std::errc() && answer.ptr != sVal.data()) ; }
|
||||
template <size_t size>
|
||||
bool FromString( const std::string& sVal, int (&nVal)[size])
|
||||
{ const char* pStart = sVal.c_str() ;
|
||||
@@ -166,29 +165,25 @@ bool FromString( const std::string& sVal, int (&nVal)[size])
|
||||
}
|
||||
template <size_t size>
|
||||
bool FromString( const std::string& sVal, double (&dVal)[size])
|
||||
{ const char* pStart = sVal.c_str() ;
|
||||
char* pStop ;
|
||||
errno = 0 ;
|
||||
{ const char* pFirst = sVal.data() ;
|
||||
for ( int i = 0 ; i < size ; ++ i) {
|
||||
dVal[i] = strtod( pStart, &pStop) ;
|
||||
if ( ( i < size - 1 && *pStop != ',') || errno != 0)
|
||||
auto answer = fast_float::from_chars( pFirst, sVal.data() + sVal.size(), dVal[i], FAST_FLOAT_FMT) ;
|
||||
if ( answer.ec != std::errc() || ( i < size - 1 && answer.ptr[0] != ','))
|
||||
return false ;
|
||||
pStart = pStop + 1 ;
|
||||
pFirst = answer.ptr + 1 ;
|
||||
}
|
||||
return ( errno == 0) ;
|
||||
return true ;
|
||||
}
|
||||
template <size_t size>
|
||||
bool FromString( const std::string& sVal, std::array<double,size>& dVal)
|
||||
{ const char* pStart = sVal.c_str() ;
|
||||
char* pStop ;
|
||||
errno = 0 ;
|
||||
{ const char* pFirst = sVal.data() ;
|
||||
for ( int i = 0 ; i < size ; ++ i) {
|
||||
dVal[i] = strtod( pStart, &pStop) ;
|
||||
if ( ( i < size - 1 && *pStop != ',') || errno != 0)
|
||||
auto answer = fast_float::from_chars( pFirst, sVal.data() + sVal.size(), dVal[i], FAST_FLOAT_FMT) ;
|
||||
if ( answer.ec != std::errc() || ( i < size - 1 && answer.ptr[0] != ','))
|
||||
return false ;
|
||||
pStart = pStop + 1 ;
|
||||
pFirst = answer.ptr + 1 ;
|
||||
}
|
||||
return ( errno == 0) ;
|
||||
return true ;
|
||||
}
|
||||
EGN_EXPORT bool FromString( const std::string& sVal, INTVECTOR& vnVal) ;
|
||||
EGN_EXPORT bool FromString( const std::string& sVal, DBLVECTOR& vdVal) ;
|
||||
|
||||
Reference in New Issue
Block a user