mirror of
https://github.com/yanyiwu/cppjieba.git
synced 2025-07-18 00:00:12 +08:00
use InitOnOff
This commit is contained in:
parent
259b296b71
commit
d5bb4e48ec
@ -1 +1,3 @@
|
|||||||
INSTALL(FILES ArgvContext.hpp io_functs.hpp macro_def.hpp MysqlClient.hpp str_functs.hpp cast_functs.hpp Config.hpp logger.hpp map_functs.hpp std_outbound.hpp DESTINATION include/CppJieba/Limonp)
|
INSTALL(FILES ArgvContext.hpp io_functs.hpp macro_def.hpp MysqlClient.hpp
|
||||||
|
str_functs.hpp cast_functs.hpp Config.hpp logger.hpp map_functs.hpp
|
||||||
|
std_outbound.hpp InitOnOff.hpp DESTINATION include/CppJieba/Limonp)
|
||||||
|
21
src/Limonp/InitOnOff.hpp
Normal file
21
src/Limonp/InitOnOff.hpp
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
#ifndef LIMONP_INITONOFF_H
|
||||||
|
#define LIMONP_INITONOFF_H
|
||||||
|
|
||||||
|
namespace Limonp
|
||||||
|
{
|
||||||
|
class InitOnOff
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
InitOnOff(){_setInitFlag(false);};
|
||||||
|
~InitOnOff(){};
|
||||||
|
protected:
|
||||||
|
bool _isInited;
|
||||||
|
bool _getInitFlag()const{return _isInited;};
|
||||||
|
bool _setInitFlag(bool flag){return _isInited = flag;};
|
||||||
|
public:
|
||||||
|
operator bool(){return _getInitFlag();};
|
||||||
|
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
@ -100,7 +100,7 @@ namespace Limonp
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
inline bool split(const string& src, vector<string>& res, const string& pattern)
|
inline bool split(const string& src, vector<string>& res, const string& pattern, size_t offset = 0, size_t len = string::npos)
|
||||||
{
|
{
|
||||||
if(src.empty())
|
if(src.empty())
|
||||||
{
|
{
|
||||||
@ -110,20 +110,28 @@ namespace Limonp
|
|||||||
|
|
||||||
size_t start = 0;
|
size_t start = 0;
|
||||||
size_t end = 0;
|
size_t end = 0;
|
||||||
while(start < src.size())
|
size_t cnt = 0;
|
||||||
|
while(start < src.size() && res.size() < len)
|
||||||
{
|
{
|
||||||
end = src.find_first_of(pattern, start);
|
end = src.find_first_of(pattern, start);
|
||||||
if(string::npos == end)
|
if(string::npos == end)
|
||||||
{
|
{
|
||||||
res.push_back(src.substr(start));
|
if(cnt >= offset)
|
||||||
|
{
|
||||||
|
res.push_back(src.substr(start));
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
res.push_back(src.substr(start, end - start));
|
//if(end == src.size() - 1)
|
||||||
if(end == src.size() - 1)
|
//{
|
||||||
|
// res.push_back("");
|
||||||
|
// return true;
|
||||||
|
//}
|
||||||
|
if(cnt >= offset)
|
||||||
{
|
{
|
||||||
res.push_back("");
|
res.push_back(src.substr(start, end - start));
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
cnt ++;
|
||||||
start = end + 1;
|
start = end + 1;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
@ -158,12 +166,8 @@ namespace Limonp
|
|||||||
return ltrim(rtrim(s));
|
return ltrim(rtrim(s));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
inline bool startsWith(const string& str, const string& prefix)
|
inline bool startsWith(const string& str, const string& prefix)
|
||||||
{
|
{
|
||||||
//return str.substr(0, prefix.size()) == prefix;
|
|
||||||
if(prefix.length() > str.length())
|
if(prefix.length() > str.length())
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
#include "TransCode.hpp"
|
#include "TransCode.hpp"
|
||||||
#include "Limonp/logger.hpp"
|
#include "Limonp/logger.hpp"
|
||||||
|
#include "Limonp/InitOnOff.hpp"
|
||||||
#include "ISegment.hpp"
|
#include "ISegment.hpp"
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
|
|
||||||
@ -10,17 +11,11 @@
|
|||||||
namespace CppJieba
|
namespace CppJieba
|
||||||
{
|
{
|
||||||
using namespace Limonp;
|
using namespace Limonp;
|
||||||
class SegmentBase: public ISegment
|
class SegmentBase: public ISegment, public InitOnOff
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
SegmentBase(){_setInitFlag(false);};
|
SegmentBase(){};
|
||||||
virtual ~SegmentBase(){};
|
virtual ~SegmentBase(){};
|
||||||
protected:
|
|
||||||
bool _isInited;
|
|
||||||
bool _getInitFlag()const{return _isInited;};
|
|
||||||
bool _setInitFlag(bool flag){return _isInited = flag;};
|
|
||||||
public:
|
|
||||||
operator bool(){return _getInitFlag();};
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
virtual bool cut(Unicode::const_iterator begin, Unicode::const_iterator end, vector<string>& res)const = 0;
|
virtual bool cut(Unicode::const_iterator begin, Unicode::const_iterator end, vector<string>& res)const = 0;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user