mirror of
https://github.com/yanyiwu/cppjieba.git
synced 2025-07-18 00:00:12 +08:00
modify some gbk enc for more robust
This commit is contained in:
parent
7106a4475f
commit
8e8a68352b
@ -112,7 +112,7 @@ namespace CppJieba
|
||||
}
|
||||
char x = 0x80;
|
||||
int resFlag = (str[0] & x ? 1 : 0);
|
||||
resLen = 1;
|
||||
resLen = 0;
|
||||
if(!resFlag)
|
||||
{
|
||||
while(resLen < len && !(str[resLen] & x))
|
||||
@ -124,9 +124,17 @@ namespace CppJieba
|
||||
{
|
||||
while(resLen < len && (str[resLen] & x))
|
||||
{
|
||||
#ifdef CPPJIEBA_GBK
|
||||
resLen += 2;
|
||||
#else
|
||||
resLen ++;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
if(resLen > len)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
return resFlag;
|
||||
}
|
||||
}
|
||||
|
@ -31,7 +31,7 @@ namespace CppJieba
|
||||
LogError("not inited.");
|
||||
return false;
|
||||
}
|
||||
const char * cstr = str.c_str();
|
||||
const char * const cstr = str.c_str();
|
||||
uint size = str.size();
|
||||
uint offset = 0;
|
||||
string subs;
|
||||
@ -60,6 +60,11 @@ namespace CppJieba
|
||||
}
|
||||
cut(unico.begin(), unico.end(), res);
|
||||
}
|
||||
if(len == 0)
|
||||
{
|
||||
LogFatal("str[%s] illegal.", cstr);
|
||||
return false;
|
||||
}
|
||||
offset += len;
|
||||
}
|
||||
return true;
|
||||
|
Loading…
x
Reference in New Issue
Block a user