Include :
- aggiunto encode di stringhe da code a UTF-8 - modifica interfaccia Text.
This commit is contained in:
+29
-18
@@ -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 ;
|
||||
|
||||
Reference in New Issue
Block a user