diff --git a/src/utf8.cpp b/src/utf8.cpp index fb8365a..b78d314 100755 --- a/src/utf8.cpp +++ b/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=0xDC00 && z2<=0xDFFF ) { - z = 0x10000 + ((z & 0x3FF) << 10) | (z2 & 0x3FF); + z = 0x10000 + (((z & 0x3FF) << 10) | (z2 & 0x3FF)); return 2; } else diff --git a/src/utf8.h b/src/utf8.h index 0331db3..73fe8d0 100755 --- a/src/utf8.h +++ b/src/utf8.h @@ -69,6 +69,7 @@ bool UTF8_CheckRange(int c); 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, 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);