mirror of
https://github.com/yanyiwu/cppjieba.git
synced 2025-07-18 00:00:12 +08:00
update cppcommon
This commit is contained in:
parent
46ecb1382a
commit
7aadcb2990
@ -293,11 +293,6 @@ namespace CPPCOMMON
|
|||||||
{
|
{
|
||||||
for(uint i = 0; i < uniLen; i++)
|
for(uint i = 0; i < uniLen; i++)
|
||||||
{
|
{
|
||||||
//char c = 0;
|
|
||||||
//c = ((pUni[i]>>8) & 0x00ff);
|
|
||||||
//res += c;
|
|
||||||
//c = (pUni[i] & 0x00ff);
|
|
||||||
//res += c;
|
|
||||||
pair<char, char> char2= uint16ToChar2(pUni[i]);
|
pair<char, char> char2= uint16ToChar2(pUni[i]);
|
||||||
res += char2.first;
|
res += char2.first;
|
||||||
res += char2.second;
|
res += char2.second;
|
||||||
@ -368,6 +363,19 @@ namespace CPPCOMMON
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
size_t getUtf8WordLen(const string& utf)
|
||||||
|
{
|
||||||
|
string uni = utf8ToUnicode(utf);
|
||||||
|
if(uni.empty()||uni.size()%2)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return uni.size()/2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef TEST_STR_FUNCTS
|
#ifdef TEST_STR_FUNCTS
|
||||||
@ -434,6 +442,7 @@ int main()
|
|||||||
{
|
{
|
||||||
cout<<line<<endl;
|
cout<<line<<endl;
|
||||||
string s = gbkToUtf8(line);
|
string s = gbkToUtf8(line);
|
||||||
|
cout<<getUtf8WordLen(s)<<endl;
|
||||||
s = utf8ToGbk(s);
|
s = utf8ToGbk(s);
|
||||||
cout<<s<<endl;
|
cout<<s<<endl;
|
||||||
}
|
}
|
||||||
|
@ -41,6 +41,8 @@ namespace CPPCOMMON
|
|||||||
string gbkToUtf8(const string& gbk);
|
string gbkToUtf8(const string& gbk);
|
||||||
string utf8ToGbk(const string& utf);
|
string utf8ToGbk(const string& utf);
|
||||||
|
|
||||||
|
size_t getUtf8WordLen(const string& utf);
|
||||||
|
|
||||||
inline uint16_t twocharToUint16(char high, char low)
|
inline uint16_t twocharToUint16(char high, char low)
|
||||||
{
|
{
|
||||||
return (((uint16_t(high) & 0x00ff ) << 8) | (uint16_t(low) & 0x00ff));
|
return (((uint16_t(high) & 0x00ff ) << 8) | (uint16_t(low) & 0x00ff));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user