Include :

- aggiunte ToString/FromString con unsigned int.
This commit is contained in:
Dario Sassi
2017-06-05 07:21:25 +00:00
parent c1145c547b
commit 7456409ead
+27
View File
@@ -125,6 +125,13 @@ FromString( const std::string& sVal, int& nVal)
nVal = strtol( pStart, &pStop, 10) ;
return ( pStop != pStart && errno == 0) ; }
inline bool
FromString( const std::string& sVal, unsigned int& nVal)
{ const char* pStart = sVal.c_str() ;
char* pStop ;
errno = 0 ;
nVal = strtoul( pStart, &pStop, 10) ;
return ( pStop != pStart && errno == 0) ; }
inline bool
FromString( const std::string& sVal, bool& bVal)
{ int nTmp ;
if ( ! FromString( sVal, nTmp))
@@ -202,6 +209,26 @@ ToString( int nVal, int nPrec = 1)
sBuff.insert( 0, ( nPrec - nLen), '0') ;
return sBuff ;
}
inline const std::string
ToString( unsigned int nVal, int nPrec = 1)
{
// eseguo conversione
char szBuff[24] ;
int nErr = _ui64toa_s( nVal, szBuff, 24, 10) ;
// se errore, ritorno stringa opportuna
if ( nErr != 0) {
_ASSERT( 0) ;
return "#Error" ;
}
// verifico lunghezza minima
int nLen = (int) strlen( szBuff) ;
if ( nLen >= nPrec)
return szBuff ;
// porto la stringa alla minima lunghezza
std::string sBuff( szBuff) ;
sBuff.insert( 0, ( nPrec - nLen), '0') ;
return sBuff ;
}
template <size_t size>
const std::string ToString( const int (&nVal)[size], int nPrec = 1)
{ std::string sDest ; sDest.reserve( 8 * size) ;