added: size_t UTF8ToInt(const char * utf8, int & res, bool & correct)
git-svn-id: svn://ttmath.org/publicrep/ezc/trunk@359 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
parent
542587e5e8
commit
b4f7d4b8de
47
src/utf8.cpp
47
src/utf8.cpp
|
@ -143,6 +143,51 @@ return len;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*!
|
||||||
|
this function converts one UTF-8 character into one wide-character
|
||||||
|
|
||||||
|
input:
|
||||||
|
utf8 - an input UTF-8 string (null terminated)
|
||||||
|
|
||||||
|
output:
|
||||||
|
res - an output character
|
||||||
|
correct - true if it is a correct character
|
||||||
|
|
||||||
|
the function returns how many characters have been used from the input string
|
||||||
|
(returns zero only if the string has '\0' at the first character)
|
||||||
|
even if there are errors the functions returns a different from zero value
|
||||||
|
*/
|
||||||
|
size_t UTF8ToInt(const char * utf8, int & res, bool & correct)
|
||||||
|
{
|
||||||
|
size_t i, len;
|
||||||
|
|
||||||
|
res = 0;
|
||||||
|
correct = false;
|
||||||
|
|
||||||
|
if( *utf8 == 0 )
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
if( !UTF8ToInt_FirstOctet(utf8[0], len, res) )
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
for(i=1 ; i<len ; ++i)
|
||||||
|
{
|
||||||
|
if( utf8[i] == 0 )
|
||||||
|
return i;
|
||||||
|
|
||||||
|
if( !UTF8ToInt_AddNextOctet(utf8[i], res) )
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
|
||||||
|
if( UTF8_CheckRange(res) )
|
||||||
|
correct = true;
|
||||||
|
|
||||||
|
return len;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
this function converts one UTF-8 character into one wide-character
|
this function converts one UTF-8 character into one wide-character
|
||||||
|
|
||||||
|
@ -522,7 +567,7 @@ static size_t WideToInt(const wchar_t * wide_string, size_t string_len, int & z,
|
||||||
|
|
||||||
if( z2>=0xDC00 && z2<=0xDFFF )
|
if( z2>=0xDC00 && z2<=0xDFFF )
|
||||||
{
|
{
|
||||||
z = 0x10000 + ((z & 0x3FF) << 10) | (z2 & 0x3FF);
|
z = 0x10000 + (((z & 0x3FF) << 10) | (z2 & 0x3FF));
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
|
@ -69,6 +69,7 @@ bool UTF8_CheckRange(int c);
|
||||||
converting one character from UTF-8 to an int
|
converting one character from UTF-8 to an int
|
||||||
*/
|
*/
|
||||||
size_t UTF8ToInt(const char * utf8, size_t utf8_len, int & res, bool & correct);
|
size_t UTF8ToInt(const char * utf8, size_t utf8_len, int & res, bool & correct);
|
||||||
|
size_t UTF8ToInt(const char * utf8, int & res, bool & correct);
|
||||||
size_t UTF8ToInt(const std::string & utf8, int & res, bool & correct);
|
size_t UTF8ToInt(const std::string & utf8, int & res, bool & correct);
|
||||||
size_t UTF8ToInt(std::istream & utf8, int & res, bool & correct);
|
size_t UTF8ToInt(std::istream & utf8, int & res, bool & correct);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue