EgtGeneral :
- modifiche a FromString con double per uso libreria fast_float
This commit is contained in:
+18
-17
@@ -71,25 +71,26 @@ FromString( const string& sVal, DBLVECTOR& vdVal)
|
||||
{
|
||||
// pulisco il vettore dei risultati
|
||||
vdVal.clear() ;
|
||||
// reset errori di conversione
|
||||
errno = 0 ;
|
||||
// ciclo sui caratteri della stringa
|
||||
const char* pStart = sVal.c_str() ;
|
||||
SkipSpaces( pStart) ;
|
||||
while ( ( *pStart >= '0' && *pStart <= '9') ||
|
||||
*pStart == '+' || *pStart == '-' || *pStart == '.') {
|
||||
char* pStop ;
|
||||
double dVal = strtod( pStart, &pStop) ;
|
||||
vdVal.push_back( dVal) ;
|
||||
SkipSpaces( pStop) ;
|
||||
if ( *pStop == '\0' && errno == 0)
|
||||
return true ;
|
||||
if ( *pStop != ',' || errno != 0)
|
||||
// ciclo sulla stringa
|
||||
const char* pFirst = sVal.data() ;
|
||||
while ( true) {
|
||||
double dVal ;
|
||||
auto answer = fast_float::from_chars( pFirst, sVal.data() + sVal.size(), dVal, FAST_FLOAT_FMT) ;
|
||||
if ( answer.ec != std::errc())
|
||||
return false ;
|
||||
pStart = pStop + 1 ;
|
||||
SkipSpaces( pStart) ;
|
||||
vdVal.push_back( dVal) ;
|
||||
const char* pLast = answer.ptr ;
|
||||
SkipSpaces( pLast) ;
|
||||
if ( pLast[0] == '\0')
|
||||
return true ;
|
||||
if ( pLast[0] != ',')
|
||||
return false ;
|
||||
pFirst = pLast + 1 ;
|
||||
SkipSpaces( pFirst) ;
|
||||
if ( pFirst[0] == '\0')
|
||||
return true ;
|
||||
}
|
||||
return ( *pStart == '\0' && errno == 0) ;
|
||||
return true ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user