EgtGeneral :
- aggiunte funzioni ToStringAdv per interi.
This commit is contained in:
@@ -100,6 +100,58 @@ FromString( const string& sVal, STRVECTOR& vsVal)
|
||||
return Tokenize( sVal, ",", vsVal) ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
const string
|
||||
ToStringAdv( int nVal, int nPrec, int nRadix, int* pnErr)
|
||||
{
|
||||
// eseguo conversione
|
||||
const int nBuffSize = 36 ;
|
||||
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 ;
|
||||
// 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 ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
const string
|
||||
ToStringAdv( unsigned int nVal, int nPrec, int nRadix, int* pnErr)
|
||||
{
|
||||
// eseguo conversione
|
||||
const int nBuffSize = 36 ;
|
||||
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 ;
|
||||
// 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 ;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
const string
|
||||
ToString( double dVal, int nPrec, int* pnErr)
|
||||
|
||||
Reference in New Issue
Block a user