Include :

- aggiunto encode di stringhe da code a UTF-8
- modifica interfaccia Text.
This commit is contained in:
Dario Sassi
2014-06-09 08:28:52 +00:00
parent 04882c2326
commit 6f64c155c8
4 changed files with 81 additions and 22 deletions
+2
View File
@@ -50,6 +50,8 @@ class __declspec( novtable) IExtText : public IGeoObj
virtual bool ApproxWithLines( double dLinTol, double dAngTolDeg, POLYLINELIST& lstPL) const = 0 ;
virtual bool Flip( void) = 0 ;
virtual bool Mir( bool bOnLen) = 0 ;
virtual bool ModifyText( const std::string& sText) = 0 ;
virtual bool ChangeFont( const std::string& sFont) = 0 ;
} ;
//-----------------------------------------------------------------------------
+1 -4
View File
@@ -69,15 +69,12 @@ inline void SmartFreeMemory( _CharType* pBuff, _CharType* pszFixedBuffer, int nF
//-----------------------------------------------------------------------------
inline bool IsTextUtf8( const char* psz)
{
const unsigned char* p ;
// validità parametro
if ( psz == nullptr)
return false ;
// ciclo sulla stringa
p = ( const unsigned char*) psz ;
const unsigned char* p = ( const unsigned char*) psz ;
while ( *p != '\0') {
// caratteri ASCII
if ( 0x00 <= p[0] && p[0] <= 0x7F)
+29 -18
View File
@@ -71,14 +71,26 @@ CountCodePoints( const std::string& sString, int& nCount)
nCount = 0 ;
// ciclo sui byte della stringa UTF-8
bool bOk = true ;
uint32_t codepoint ;
uint32_t state = UTF8_ACCEPT ;
uint32_t stPrev = UTF8_ACCEPT ;
for ( unsigned int i = 0 ; i < sString.length() ; ++ i) {
if ( ! decode( &state, &codepoint, sString[i]))
switch ( decode( &state, &codepoint, sString[i])) {
case UTF8_ACCEPT :
++ nCount ;
break ;
case UTF8_REJECT :
bOk = false ;
state = UTF8_ACCEPT ;
if ( stPrev != UTF8_ACCEPT)
-- i ;
break ;
}
stPrev = state ;
}
return ( state == UTF8_ACCEPT) ;
return bOk ;
}
//-----------------------------------------------------------------------------
@@ -96,22 +108,21 @@ GetCodePoints( const std::string& sString, UINTVECTOR& vCode)
uint32_t stPrev = UTF8_ACCEPT ;
for ( unsigned int i = 0 ; i < sString.length() ; ++ i) {
switch ( decode( &state, &codepoint, sString[i])) {
case UTF8_ACCEPT :
// A properly encoded character has been found.
vCode.push_back( codepoint) ;
break ;
case UTF8_REJECT :
// The byte is invalid, replace it and restart.
vCode.push_back( 0xFFFD) ;
bOk = false ;
state = UTF8_ACCEPT ;
if ( stPrev != UTF8_ACCEPT)
-- i ;
break ;
}
stPrev = state ;
switch ( decode( &state, &codepoint, sString[i])) {
case UTF8_ACCEPT :
// A properly encoded character has been found.
vCode.push_back( codepoint) ;
break ;
case UTF8_REJECT :
// The byte is invalid, replace it and restart.
vCode.push_back( 0xFFFD) ;
bOk = false ;
state = UTF8_ACCEPT ;
if ( stPrev != UTF8_ACCEPT)
-- i ;
break ;
}
stPrev = state ;
}
return bOk ;
+49
View File
@@ -0,0 +1,49 @@
//----------------------------------------------------------------------------
// 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 ;
}