Include :
- tutte le funzioni ToStringAdv sono diventate inline nell'header.
This commit is contained in:
+74
-3
@@ -189,7 +189,30 @@ EGN_EXPORT bool FromString( const std::string& sVal, DBLVECTOR& vdVal) ;
|
||||
EGN_EXPORT bool FromString( const std::string& sVal, STRVECTOR& vsVal) ;
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
EGN_EXPORT const std::string ToStringAdv( int nVal, int nPrec = 1, int nRadix = 10, int* pnErr = nullptr) ;
|
||||
inline const std::string
|
||||
ToStringAdv( int nVal, int nPrec = 1, int nRadix = 10, int* pnErr = nullptr)
|
||||
{
|
||||
// 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 ;
|
||||
}
|
||||
inline const std::string
|
||||
ToString( int nVal, int nPrec = 1, int nRadix = 10, int* pnErr = nullptr)
|
||||
{
|
||||
@@ -210,7 +233,31 @@ ToString( int nVal, int nPrec = 1, int nRadix = 10, int* pnErr = nullptr)
|
||||
*pnErr = 0 ;
|
||||
return szBuff ;
|
||||
}
|
||||
EGN_EXPORT const std::string ToStringAdv( unsigned int nVal, int nPrec = 1, int nRadix = 10, int* pnErr = nullptr) ;
|
||||
|
||||
inline const std::string
|
||||
ToStringAdv( unsigned int nVal, int nPrec = 1, int nRadix = 10, int* pnErr = nullptr)
|
||||
{
|
||||
// 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 ;
|
||||
}
|
||||
inline const std::string
|
||||
ToString( unsigned int nVal, int nPrec = 1, int nRadix = 10, int* pnErr = nullptr)
|
||||
{
|
||||
@@ -231,7 +278,31 @@ 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
|
||||
ToStringAdv( long long nVal, int nPrec = 1, int nRadix = 10, int* pnErr = nullptr)
|
||||
{
|
||||
// eseguo conversione
|
||||
const int nBuffSize = 68 ;
|
||||
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 ;
|
||||
}
|
||||
inline const std::string
|
||||
ToString( long long nVal, int nPrec = 1, int nRadix = 10, int* pnErr = nullptr)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user