From 7456409ead73fa38cb9bdb3f52640def732d4a7b Mon Sep 17 00:00:00 2001 From: Dario Sassi Date: Mon, 5 Jun 2017 07:21:25 +0000 Subject: [PATCH] Include : - aggiunte ToString/FromString con unsigned int. --- EGnStringUtils.h | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/EGnStringUtils.h b/EGnStringUtils.h index 3d56ce9..78e31c1 100644 --- a/EGnStringUtils.h +++ b/EGnStringUtils.h @@ -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 const std::string ToString( const int (&nVal)[size], int nPrec = 1) { std::string sDest ; sDest.reserve( 8 * size) ;