diff --git a/src/FullSegment.hpp b/src/FullSegment.hpp index 65e482a..624383e 100644 --- a/src/FullSegment.hpp +++ b/src/FullSegment.hpp @@ -47,12 +47,6 @@ class FullSegment: public SegmentBase { using SegmentBase::cut; bool cut(Unicode::const_iterator begin, Unicode::const_iterator end, vector& 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& res) const { - assert(dictTrie_); - if (begin >= end) { - LogError("begin >= end"); - return false; - } - vector uRes; if (!cut(begin, end, uRes)) { LogError("get unicode cut result error."); @@ -107,11 +96,8 @@ class FullSegment: public SegmentBase { string tmp; for (vector::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; diff --git a/src/HMMSegment.hpp b/src/HMMSegment.hpp index f384eb2..5cf0bf6 100644 --- a/src/HMMSegment.hpp +++ b/src/HMMSegment.hpp @@ -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; } diff --git a/src/Limonp/StringUtil.hpp b/src/Limonp/StringUtil.hpp index 61ebd60..0efab05 100644 --- a/src/Limonp/StringUtil.hpp +++ b/src/Limonp/StringUtil.hpp @@ -197,10 +197,7 @@ bool utf8ToUnicode(const string& str, Uint16Container& vec) { } template -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 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 -bool gbkTrans(Uint16ContainerConIter begin, Uint16ContainerConIter end, string& res) { - if(begin >= end) { - return false; - } +void gbkTrans(Uint16ContainerConIter begin, Uint16ContainerConIter end, string& res) { res.clear(); //pair pa; char first, second; @@ -270,7 +263,6 @@ bool gbkTrans(Uint16ContainerConIter begin, Uint16ContainerConIter end, string& } begin++; } - return true; } /* diff --git a/src/MPSegment.hpp b/src/MPSegment.hpp index 05f8954..a0d3a57 100644 --- a/src/MPSegment.hpp +++ b/src/MPSegment.hpp @@ -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; } diff --git a/src/MixSegment.hpp b/src/MixSegment.hpp index 18b0b84..aace901 100644 --- a/src/MixSegment.hpp +++ b/src/MixSegment.hpp @@ -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; } diff --git a/src/QuerySegment.hpp b/src/QuerySegment.hpp index 4655d30..1e8ba13 100644 --- a/src/QuerySegment.hpp +++ b/src/QuerySegment.hpp @@ -29,11 +29,6 @@ class QuerySegment: public SegmentBase { } using SegmentBase::cut; bool cut(Unicode::const_iterator begin, Unicode::const_iterator end, vector& res) const { - if (begin >= end) { - LogError("begin >= end"); - return false; - } - //use mix cut first vector 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& res) const { - if (begin >= end) { - LogError("begin >= end"); - return false; - } - vector uRes; if (!cut(begin, end, uRes)) { LogError("get unicode cut result error."); @@ -77,11 +67,8 @@ class QuerySegment: public SegmentBase { string tmp; for (vector::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; diff --git a/src/TransCode.hpp b/src/TransCode.hpp index d46bfbb..ba1bfdd 100644 --- a/src/TransCode.hpp +++ b/src/TransCode.hpp @@ -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