mirror of
https://github.com/yanyiwu/cppjieba.git
synced 2025-07-18 00:00:12 +08:00
删除一些无必要的错误检查
This commit is contained in:
parent
954100dc3d
commit
aed1c8f4a6
@ -47,12 +47,6 @@ class FullSegment: public SegmentBase {
|
||||
|
||||
using SegmentBase::cut;
|
||||
bool cut(Unicode::const_iterator begin, Unicode::const_iterator end, vector<Unicode>& res) const {
|
||||
assert(dictTrie_);
|
||||
if (begin >= end) {
|
||||
LogError("begin >= end");
|
||||
return false;
|
||||
}
|
||||
|
||||
//resut of searching in trie tree
|
||||
DagType tRes;
|
||||
|
||||
@ -64,6 +58,7 @@ class FullSegment: public SegmentBase {
|
||||
|
||||
//tmp variables
|
||||
int wordLen = 0;
|
||||
assert(dictTrie_);
|
||||
for (Unicode::const_iterator uItr = begin; uItr != end; uItr++) {
|
||||
//find word start from uItr
|
||||
if (dictTrie_->find(uItr, end, tRes, 0)) {
|
||||
@ -93,12 +88,6 @@ class FullSegment: public SegmentBase {
|
||||
}
|
||||
|
||||
bool cut(Unicode::const_iterator begin, Unicode::const_iterator end, vector<string>& res) const {
|
||||
assert(dictTrie_);
|
||||
if (begin >= end) {
|
||||
LogError("begin >= end");
|
||||
return false;
|
||||
}
|
||||
|
||||
vector<Unicode> uRes;
|
||||
if (!cut(begin, end, uRes)) {
|
||||
LogError("get unicode cut result error.");
|
||||
@ -107,11 +96,8 @@ class FullSegment: public SegmentBase {
|
||||
|
||||
string tmp;
|
||||
for (vector<Unicode>::const_iterator uItr = uRes.begin(); uItr != uRes.end(); uItr++) {
|
||||
if (TransCode::encode(*uItr, tmp)) {
|
||||
res.push_back(tmp);
|
||||
} else {
|
||||
LogError("encode failed.");
|
||||
}
|
||||
TransCode::encode(*uItr, tmp);
|
||||
res.push_back(tmp);
|
||||
}
|
||||
|
||||
return true;
|
||||
|
@ -90,9 +90,7 @@ class HMMSegment: public SegmentBase {
|
||||
size_t offset = res.size();
|
||||
res.resize(res.size() + words.size());
|
||||
for(size_t i = 0; i < words.size(); i++) {
|
||||
if(!TransCode::encode(words[i], res[offset + i])) {
|
||||
LogError("encode failed.");
|
||||
}
|
||||
TransCode::encode(words[i], res[offset + i]);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -197,10 +197,7 @@ bool utf8ToUnicode(const string& str, Uint16Container& vec) {
|
||||
}
|
||||
|
||||
template <class Uint16ContainerConIter>
|
||||
bool unicodeToUtf8(Uint16ContainerConIter begin, Uint16ContainerConIter end, string& res) {
|
||||
if(begin >= end) {
|
||||
return false;
|
||||
}
|
||||
void unicodeToUtf8(Uint16ContainerConIter begin, Uint16ContainerConIter end, string& res) {
|
||||
res.clear();
|
||||
uint16_t ui;
|
||||
while(begin != end) {
|
||||
@ -217,7 +214,6 @@ bool unicodeToUtf8(Uint16ContainerConIter begin, Uint16ContainerConIter end, str
|
||||
}
|
||||
begin ++;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@ -225,7 +221,7 @@ template <class Uint16Container>
|
||||
bool gbkTrans(const char* const str, size_t len, Uint16Container& vec) {
|
||||
vec.clear();
|
||||
if(!str) {
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
size_t i = 0;
|
||||
while(i < len) {
|
||||
@ -251,10 +247,7 @@ bool gbkTrans(const string& str, Uint16Container& vec) {
|
||||
}
|
||||
|
||||
template <class Uint16ContainerConIter>
|
||||
bool gbkTrans(Uint16ContainerConIter begin, Uint16ContainerConIter end, string& res) {
|
||||
if(begin >= end) {
|
||||
return false;
|
||||
}
|
||||
void gbkTrans(Uint16ContainerConIter begin, Uint16ContainerConIter end, string& res) {
|
||||
res.clear();
|
||||
//pair<char, char> pa;
|
||||
char first, second;
|
||||
@ -270,7 +263,6 @@ bool gbkTrans(Uint16ContainerConIter begin, Uint16ContainerConIter end, string&
|
||||
}
|
||||
begin++;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -42,10 +42,7 @@ class MPSegment: public SegmentBase {
|
||||
size_t offset = res.size();
|
||||
res.resize(res.size() + words.size());
|
||||
for(size_t i = 0; i < words.size(); i++) {
|
||||
if(!TransCode::encode(words[i], res[i + offset])) {
|
||||
LogError("encode failed.");
|
||||
res[i + offset].clear();
|
||||
}
|
||||
TransCode::encode(words[i], res[i + offset]);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -83,9 +83,7 @@ class MixSegment: public SegmentBase {
|
||||
size_t offset = res.size();
|
||||
res.resize(res.size() + uRes.size());
|
||||
for(size_t i = 0; i < uRes.size(); i ++, offset++) {
|
||||
if(!TransCode::encode(uRes[i], res[offset])) {
|
||||
LogError("encode failed.");
|
||||
}
|
||||
TransCode::encode(uRes[i], res[offset]);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -29,11 +29,6 @@ class QuerySegment: public SegmentBase {
|
||||
}
|
||||
using SegmentBase::cut;
|
||||
bool cut(Unicode::const_iterator begin, Unicode::const_iterator end, vector<Unicode>& res) const {
|
||||
if (begin >= end) {
|
||||
LogError("begin >= end");
|
||||
return false;
|
||||
}
|
||||
|
||||
//use mix cut first
|
||||
vector<Unicode> mixRes;
|
||||
if (!mixSeg_.cut(begin, end, mixRes)) {
|
||||
@ -64,11 +59,6 @@ class QuerySegment: public SegmentBase {
|
||||
|
||||
|
||||
bool cut(Unicode::const_iterator begin, Unicode::const_iterator end, vector<string>& res) const {
|
||||
if (begin >= end) {
|
||||
LogError("begin >= end");
|
||||
return false;
|
||||
}
|
||||
|
||||
vector<Unicode> uRes;
|
||||
if (!cut(begin, end, uRes)) {
|
||||
LogError("get unicode cut result error.");
|
||||
@ -77,11 +67,8 @@ class QuerySegment: public SegmentBase {
|
||||
|
||||
string tmp;
|
||||
for (vector<Unicode>::const_iterator uItr = uRes.begin(); uItr != uRes.end(); uItr++) {
|
||||
if (TransCode::encode(*uItr, tmp)) {
|
||||
res.push_back(tmp);
|
||||
} else {
|
||||
LogError("encode failed.");
|
||||
}
|
||||
TransCode::encode(*uItr, tmp);
|
||||
res.push_back(tmp);
|
||||
}
|
||||
|
||||
return true;
|
||||
|
@ -23,16 +23,16 @@ inline bool decode(const string& str, Unicode& res) {
|
||||
#endif
|
||||
}
|
||||
|
||||
inline bool encode(Unicode::const_iterator begin, Unicode::const_iterator end, string& res) {
|
||||
inline void encode(Unicode::const_iterator begin, Unicode::const_iterator end, string& res) {
|
||||
#ifdef CPPJIEBA_GBK
|
||||
return gbkTrans(begin, end, res);
|
||||
gbkTrans(begin, end, res);
|
||||
#else
|
||||
return unicodeToUtf8(begin, end, res);
|
||||
unicodeToUtf8(begin, end, res);
|
||||
#endif
|
||||
}
|
||||
|
||||
inline bool encode(const Unicode& uni, string& res) {
|
||||
return encode(uni.begin(), uni.end(), res);
|
||||
inline void encode(const Unicode& uni, string& res) {
|
||||
encode(uni.begin(), uni.end(), res);
|
||||
}
|
||||
|
||||
// compiler is expected to optimized this function to avoid return value copy
|
||||
|
Loading…
x
Reference in New Issue
Block a user