Files
Include/EGnStringEncoder.h
T
Dario Sassi 6f64c155c8 Include :
- aggiunto encode di stringhe da code a UTF-8
- modifica interfaccia Text.
2014-06-09 08:28:52 +00:00

50 lines
1.4 KiB
C++

//----------------------------------------------------------------------------
// EgalTech 2014-2014
//----------------------------------------------------------------------------
// File : EgnStringEncoder.h Data : 08.06.14 Versione : 1.5f3
// Contenuto : Insieme di funzioni per codificare stringhe UTF-8.
//
//
//
// Modifiche : 08.06.14 DS Creazione modulo.
//
//
//----------------------------------------------------------------------------
#pragma once
#include "/EgtDev/Include/EGnStringConverter.h"
#include "/EgtDev/Include/EGtNumCollection.h"
//-----------------------------------------------------------------------------
bool inline
SetCodePoint( unsigned int nCode, std::string& sString)
{
const unsigned int MAX_UNICODE = 1114111 ;
if ( nCode > MAX_UNICODE)
return false ;
wchar_t wsVal [2] ;
wsVal[0] = nCode ;
wsVal[1] = L'\0' ;
sString = LPSTR( WtoA(( wsVal))) ;
return true ;
}
//-----------------------------------------------------------------------------
bool inline
SetCodePoints( UINTVECTOR& vCode, std::string& sString)
{
sString.clear() ;
sString.reserve( vCode.size()) ;
bool bOk = true ;
for ( size_t i = 0 ; i < vCode.size() ; ++ i) {
std::string sTemp ;
if ( SetCodePoint( vCode[i], sTemp)) {
sString += sTemp ;
}
else
bOk = false ;
}
return bOk ;
}