modify some gbk enc for more robust

This commit is contained in:
wyy 2013-12-06 22:52:59 -08:00
parent 7106a4475f
commit 8e8a68352b
2 changed files with 15 additions and 2 deletions

View File

@ -112,7 +112,7 @@ namespace CppJieba
} }
char x = 0x80; char x = 0x80;
int resFlag = (str[0] & x ? 1 : 0); int resFlag = (str[0] & x ? 1 : 0);
resLen = 1; resLen = 0;
if(!resFlag) if(!resFlag)
{ {
while(resLen < len && !(str[resLen] & x)) while(resLen < len && !(str[resLen] & x))
@ -124,9 +124,17 @@ namespace CppJieba
{ {
while(resLen < len && (str[resLen] & x)) while(resLen < len && (str[resLen] & x))
{ {
#ifdef CPPJIEBA_GBK
resLen += 2;
#else
resLen ++; resLen ++;
#endif
} }
} }
if(resLen > len)
{
return -1;
}
return resFlag; return resFlag;
} }
} }

View File

@ -31,7 +31,7 @@ namespace CppJieba
LogError("not inited."); LogError("not inited.");
return false; return false;
} }
const char * cstr = str.c_str(); const char * const cstr = str.c_str();
uint size = str.size(); uint size = str.size();
uint offset = 0; uint offset = 0;
string subs; string subs;
@ -60,6 +60,11 @@ namespace CppJieba
} }
cut(unico.begin(), unico.end(), res); cut(unico.begin(), unico.end(), res);
} }
if(len == 0)
{
LogFatal("str[%s] illegal.", cstr);
return false;
}
offset += len; offset += len;
} }
return true; return true;