Include :
- aggiunte FromString e ToString per long long.
This commit is contained in:
+28
-2
@@ -1,13 +1,14 @@
|
||||
//----------------------------------------------------------------------------
|
||||
// EgalTech 2013-2014
|
||||
// EgalTech 2013-2025
|
||||
//----------------------------------------------------------------------------
|
||||
// File : EGnStringUtils.h Data : 17.03.14 Versione : 1.5c2
|
||||
// File : EGnStringUtils.h Data : 18.09.25 Versione : 2.7i1
|
||||
// Contenuto : Dichiarazione delle funzioni di utilità per le stringhe.
|
||||
//
|
||||
//
|
||||
//
|
||||
// Modifiche : 20.11.13 DS Creazione modulo.
|
||||
// 20.10.15 DS Agg. FromString e ToString per std::array<double,N>.
|
||||
// 18.09.25 DS Agg. FromString e ToString per long long.
|
||||
//
|
||||
//----------------------------------------------------------------------------
|
||||
|
||||
@@ -136,6 +137,10 @@ FromString( const std::string& sVal, unsigned int& nVal)
|
||||
{ auto answer = fast_float::from_chars_advanced( sVal.data(), sVal.data() + sVal.size(), nVal, FAST_FLOAT_OPTS) ;
|
||||
return ( answer.ec == std::errc() && answer.ptr != sVal.data()) ; }
|
||||
inline bool
|
||||
FromString( const std::string& sVal, long long& nVal)
|
||||
{ auto answer = fast_float::from_chars_advanced( sVal.data(), sVal.data() + sVal.size(), nVal, FAST_FLOAT_OPTS) ;
|
||||
return ( answer.ec == std::errc() && answer.ptr != sVal.data()) ; }
|
||||
inline bool
|
||||
FromString( const std::string& sVal, bool& bVal)
|
||||
{ int nTmp ;
|
||||
if ( ! FromString( sVal, nTmp))
|
||||
@@ -226,6 +231,27 @@ ToString( unsigned int nVal, int nPrec = 1, int nRadix = 10, int* pnErr = nullpt
|
||||
*pnErr = 0 ;
|
||||
return szBuff ;
|
||||
}
|
||||
EGN_EXPORT const std::string ToStringAdv( long long nVal, int nPrec = 1, int nRadix = 10, int* pnErr = nullptr) ;
|
||||
inline const std::string
|
||||
ToString( long long nVal, int nPrec = 1, int nRadix = 10, int* pnErr = nullptr)
|
||||
{
|
||||
// se necessario processing avanzato
|
||||
if ( nPrec > 1 || nRadix < 6)
|
||||
return ToStringAdv( nVal, nPrec, nRadix, pnErr) ;
|
||||
// eseguo conversione
|
||||
const int nBuffSize = 16 ;
|
||||
char szBuff[nBuffSize]{} ;
|
||||
auto Res = std::to_chars( szBuff, szBuff + nBuffSize - 1, nVal, nRadix) ;
|
||||
if ( Res.ec != std::errc()) {
|
||||
if ( pnErr != nullptr)
|
||||
*pnErr = int( Res.ec) ;
|
||||
return "#Error" ;
|
||||
}
|
||||
// gestione codice di errore
|
||||
if ( pnErr != nullptr)
|
||||
*pnErr = 0 ;
|
||||
return szBuff ;
|
||||
}
|
||||
template <size_t size>
|
||||
const std::string ToString( const int (&nVal)[size], int nPrec = 1)
|
||||
{ std::string sDest ; sDest.reserve( 8 * size) ;
|
||||
|
||||
Reference in New Issue
Block a user