EgtGeneral :

- aggiunte funzioni ToStringAdv per interi.
This commit is contained in:
Dario Sassi
2025-01-10 16:25:49 +01:00
parent 70a503c15a
commit 5a7a4c2b6d
+52
View File
@@ -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)