Include :
- aggiunte ToString/FromString con unsigned int.
This commit is contained in:
@@ -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) ;
|
||||
|
||||
Reference in New Issue
Block a user