mirror of
https://github.com/yanyiwu/cppjieba.git
synced 2025-07-18 00:00:12 +08:00
update cppjieba to adapter new limonp
This commit is contained in:
parent
3089e9bf95
commit
b0521c6d6e
@ -8,7 +8,6 @@
|
||||
|
||||
#include "globals.h"
|
||||
#include <str_functs.hpp>
|
||||
#include <vec_functs.hpp>
|
||||
|
||||
namespace CppJieba
|
||||
{
|
||||
|
@ -74,7 +74,7 @@ namespace CppJieba
|
||||
KeyWordInfo(const TrieNodeInfo& trieNodeInfo):TrieNodeInfo(trieNodeInfo)
|
||||
{
|
||||
}
|
||||
inline string toString() const
|
||||
string toString() const
|
||||
{
|
||||
string tmp;
|
||||
TransCode::encode(word, tmp);
|
||||
@ -89,16 +89,23 @@ namespace CppJieba
|
||||
return *this;
|
||||
}
|
||||
};
|
||||
|
||||
inline string joinWordInfos(const vector<KeyWordInfo>& vec)
|
||||
|
||||
inline ostream& operator << (ostream& os, const KeyWordInfo& info)
|
||||
{
|
||||
vector<string> tmp;
|
||||
for(uint i = 0; i < vec.size(); i++)
|
||||
{
|
||||
tmp.push_back(vec[i].toString());
|
||||
}
|
||||
return joinStr(tmp, ",");
|
||||
string tmp;
|
||||
TransCode::encode(info.word, tmp);
|
||||
return os << "{words:" << tmp << ", weight:" << info.weight << ", idf:" << info.idf << "}";
|
||||
}
|
||||
|
||||
//inline string joinWordInfos(const vector<KeyWordInfo>& vec)
|
||||
//{
|
||||
// vector<string> tmp;
|
||||
// for(uint i = 0; i < vec.size(); i++)
|
||||
// {
|
||||
// tmp.push_back(vec[i].toString());
|
||||
// }
|
||||
// return joinStr(tmp, ",");
|
||||
//}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -23,7 +23,7 @@ void testKeyWordExt(const char * dictPath, const char * filePath)
|
||||
if(!line.empty())
|
||||
{
|
||||
ext.extract(line, res, 20);
|
||||
cout<<line<<'\n'<<joinWordInfos(res)<<endl;
|
||||
cout<<line<<'\n'<<res<<endl;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -44,7 +44,7 @@ void cut(const ISegment * seg, const char * const filePath)
|
||||
{
|
||||
res.clear();
|
||||
seg->cut(line, res);
|
||||
cout<<line<<"\n"<<joinStr(res,"/")<<endl;
|
||||
cout<<line<<"\n"<<join(res.begin(), res.end(),"/")<<endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -31,7 +31,7 @@ class ServerDemo: public IRequestHandler
|
||||
httpReq.GET("key", tmp);
|
||||
URLDecode(tmp, sentence);
|
||||
_segment.cut(sentence, words);
|
||||
vecToString(words, strSnd);
|
||||
strSnd << words;
|
||||
return true;
|
||||
}
|
||||
private:
|
||||
|
@ -130,7 +130,8 @@ namespace Husky
|
||||
LogFatal("headerStr illegal.");
|
||||
return false;
|
||||
}
|
||||
_headerMap[upperStr(k)] = v;
|
||||
upper(k);
|
||||
_headerMap[k] = v;
|
||||
lpos = rpos + 1;
|
||||
}
|
||||
//message header end
|
||||
@ -173,17 +174,17 @@ namespace Husky
|
||||
}
|
||||
public:
|
||||
//string toString() const;// function for debug because of heavy time consuming
|
||||
string toString() const
|
||||
{
|
||||
string res("{");
|
||||
res += HashMapToString(_headerMap);
|
||||
res += ",";
|
||||
res += HashMapToString(_methodGetMap);
|
||||
res += ",";
|
||||
res += HashMapToString(_methodPostMap);
|
||||
res += "}";
|
||||
return res;
|
||||
}
|
||||
//string toString() const
|
||||
//{
|
||||
// string res("{");
|
||||
// res += HashMapToString(_headerMap);
|
||||
// res += ",";
|
||||
// res += HashMapToString(_methodGetMap);
|
||||
// res += ",";
|
||||
// res += HashMapToString(_methodPostMap);
|
||||
// res += "}";
|
||||
// return res;
|
||||
//}
|
||||
private:
|
||||
bool _parseUrl(const string& url, HashMap<string, string>& mp)
|
||||
{
|
||||
|
@ -140,7 +140,7 @@ namespace Husky
|
||||
|
||||
if(SOCKET_ERROR==nRetCode)
|
||||
{
|
||||
LogError("error [%s]", strerror(errno));
|
||||
LogDebug("error [%s]", strerror(errno));
|
||||
closesocket(hClientSock);
|
||||
continue;
|
||||
}
|
||||
|
@ -10,7 +10,6 @@
|
||||
#include <sstream>
|
||||
#include "str_functs.hpp"
|
||||
#include "map_functs.hpp"
|
||||
#include "vec_functs.hpp"
|
||||
|
||||
namespace Limonp
|
||||
{
|
||||
@ -43,12 +42,7 @@ namespace Limonp
|
||||
}
|
||||
~ArgvContext(){};
|
||||
public:
|
||||
string toString()
|
||||
{
|
||||
stringstream ss;
|
||||
ss<<vecToString<string>(_args)<<mapToString<string, string>(_mpss)<<setToString<string>(_sset);
|
||||
return ss.str();
|
||||
}
|
||||
friend ostream& operator << (ostream& os, const ArgvContext& args);
|
||||
string operator [](uint i)
|
||||
{
|
||||
if(i < _args.size())
|
||||
@ -81,6 +75,16 @@ namespace Limonp
|
||||
set<string> _sset;
|
||||
|
||||
};
|
||||
|
||||
inline ostream& operator << (ostream& os, const ArgvContext& args)
|
||||
{
|
||||
return os<<args._args<<args._mpss<<args._sset;
|
||||
}
|
||||
//string toString()
|
||||
//{
|
||||
// stringstream ss;
|
||||
// return ss.str();
|
||||
//}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -6,7 +6,6 @@
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include "logger.hpp"
|
||||
#include "vec_functs.hpp"
|
||||
|
||||
namespace Limonp
|
||||
{
|
||||
@ -21,8 +20,9 @@ namespace Limonp
|
||||
const char * const USER;
|
||||
const char * const PASSWD;
|
||||
const char * const DB;
|
||||
const char * const CHARSET;
|
||||
public:
|
||||
MysqlClient(const char* host, uint port, const char* user, const char* passwd, const char* db): HOST(host), PORT(port), USER(user), PASSWD(passwd), DB(db){ _conn = NULL;};
|
||||
MysqlClient(const char* host, uint port, const char* user, const char* passwd, const char* db, const char* charset = "utf8"): HOST(host), PORT(port), USER(user), PASSWD(passwd), DB(db), CHARSET(charset){ _conn = NULL;};
|
||||
~MysqlClient(){dispose();};
|
||||
public:
|
||||
bool init()
|
||||
@ -42,10 +42,17 @@ namespace Limonp
|
||||
return false;
|
||||
}
|
||||
|
||||
if(mysql_set_character_set(_conn, CHARSET))
|
||||
{
|
||||
LogError("mysql_set_character_set [%s] failed.", CHARSET);
|
||||
return false;
|
||||
}
|
||||
|
||||
//set reconenct
|
||||
char value = 1;
|
||||
mysql_options(_conn, MYSQL_OPT_RECONNECT, &value);
|
||||
|
||||
LogInfo("MysqlClient {host: %s, port:%d, database:%s, charset:%s}", HOST, PORT, DB, CHARSET);
|
||||
return true;
|
||||
}
|
||||
bool dispose()
|
||||
|
@ -13,7 +13,6 @@
|
||||
#include <stdarg.h>
|
||||
#include "io_functs.hpp"
|
||||
#include "str_functs.hpp"
|
||||
#include "typedefs.h"
|
||||
|
||||
#define LogDebug(fmt, ...) Logger::LoggingF(LL_DEBUG, __FILE__, __LINE__, fmt, ## __VA_ARGS__)
|
||||
#define LogInfo(fmt, ...) Logger::LoggingF(LL_INFO, __FILE__, __LINE__, fmt, ## __VA_ARGS__)
|
||||
|
@ -11,91 +11,84 @@
|
||||
#include <set>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include "typedefs.h"
|
||||
|
||||
#include <tr1/unordered_map>
|
||||
#define HashMap std::tr1::unordered_map
|
||||
|
||||
namespace Limonp
|
||||
{
|
||||
using namespace std;
|
||||
|
||||
|
||||
template <typename T>
|
||||
string setToString(const set<T>& st)
|
||||
{
|
||||
if(st.empty())
|
||||
{
|
||||
return "{}";
|
||||
}
|
||||
stringstream ss;
|
||||
ss<<'{';
|
||||
typename set<T>::const_iterator it = st.begin();
|
||||
ss<<*it;
|
||||
it++;
|
||||
while(it != st.end())
|
||||
{
|
||||
ss<<", "<<*it;
|
||||
it++;
|
||||
}
|
||||
ss<<'}';
|
||||
return ss.str();
|
||||
}
|
||||
//template <typename T>
|
||||
// string setToString(const set<T>& st)
|
||||
// {
|
||||
// if(st.empty())
|
||||
// {
|
||||
// return "{}";
|
||||
// }
|
||||
// stringstream ss;
|
||||
// ss<<'{';
|
||||
// typename set<T>::const_iterator it = st.begin();
|
||||
// ss<<*it;
|
||||
// it++;
|
||||
// while(it != st.end())
|
||||
// {
|
||||
// ss<<", "<<*it;
|
||||
// it++;
|
||||
// }
|
||||
// ss<<'}';
|
||||
// return ss.str();
|
||||
// }
|
||||
|
||||
template<typename T1, typename T2>
|
||||
string mapToString(const map<T1, T2>& mp)
|
||||
{
|
||||
if(mp.empty())
|
||||
{
|
||||
return "{}";
|
||||
}
|
||||
stringstream ss;
|
||||
ss<<'{';
|
||||
typename map<T1, T2>::const_iterator it = mp.begin();
|
||||
ss<<it->first<<": "<<it->second;
|
||||
it++;
|
||||
while(it != mp.end())
|
||||
{
|
||||
ss<<", "<<it->first<<": "<<it->second;
|
||||
it++;
|
||||
}
|
||||
ss<<'}';
|
||||
return ss.str();
|
||||
}
|
||||
//template<typename T1, typename T2>
|
||||
// string mapToString(const map<T1, T2>& mp)
|
||||
// {
|
||||
// if(mp.empty())
|
||||
// {
|
||||
// return "{}";
|
||||
// }
|
||||
// stringstream ss;
|
||||
// ss<<'{';
|
||||
// typename map<T1, T2>::const_iterator it = mp.begin();
|
||||
// ss<<it->first<<": "<<it->second;
|
||||
// it++;
|
||||
// while(it != mp.end())
|
||||
// {
|
||||
// ss<<", "<<it->first<<": "<<it->second;
|
||||
// it++;
|
||||
// }
|
||||
// ss<<'}';
|
||||
// return ss.str();
|
||||
// }
|
||||
|
||||
template<typename T1, typename T2>
|
||||
string HashMapToString(const HashMap<T1, T2>& mp)
|
||||
{
|
||||
if(mp.empty())
|
||||
{
|
||||
return "{}";
|
||||
}
|
||||
stringstream ss;
|
||||
ss<<'{';
|
||||
typename HashMap<T1, T2>::const_iterator it = mp.begin();
|
||||
ss<<it->first<<": "<<it->second;
|
||||
it++;
|
||||
while(it != mp.end())
|
||||
{
|
||||
ss<<", "<<it->first<<": "<<it->second;
|
||||
it++;
|
||||
}
|
||||
ss<<'}';
|
||||
return ss.str();
|
||||
}
|
||||
template<typename T1, typename T2>
|
||||
string pairToString(const pair<T1, T2>& p)
|
||||
{
|
||||
stringstream ss;
|
||||
ss<<p.first<<":"<<p.second;
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
template<class kT, class vT>
|
||||
void printMap(const map<kT, vT>& mp)
|
||||
{
|
||||
for(typename map<kT, vT>::const_iterator it = mp.begin(); it != mp.end(); it++)
|
||||
{
|
||||
cout<<it->first<<' '<<it->second<<endl;
|
||||
}
|
||||
}
|
||||
//template<typename T1, typename T2>
|
||||
// string HashMapToString(const HashMap<T1, T2>& mp)
|
||||
// {
|
||||
// if(mp.empty())
|
||||
// {
|
||||
// return "{}";
|
||||
// }
|
||||
// stringstream ss;
|
||||
// ss<<'{';
|
||||
// typename HashMap<T1, T2>::const_iterator it = mp.begin();
|
||||
// ss<<it->first<<": "<<it->second;
|
||||
// it++;
|
||||
// while(it != mp.end())
|
||||
// {
|
||||
// ss<<", "<<it->first<<": "<<it->second;
|
||||
// it++;
|
||||
// }
|
||||
// ss<<'}';
|
||||
// return ss.str();
|
||||
// }
|
||||
//template<typename T1, typename T2>
|
||||
// string pairToString(const pair<T1, T2>& p)
|
||||
// {
|
||||
// stringstream ss;
|
||||
// ss<<p.first<<":"<<p.second;
|
||||
// return ss.str();
|
||||
// }
|
||||
|
||||
template<class kT, class vT>
|
||||
vT getMap(const map<kT, vT>& mp, const kT & key, const vT & defaultVal)
|
||||
|
@ -15,9 +15,14 @@
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
#include <memory.h>
|
||||
#include "typedefs.h"
|
||||
#include <functional>
|
||||
#include <locale>
|
||||
#include <sstream>
|
||||
#include <sys/types.h>
|
||||
#include <map_functs.hpp>
|
||||
|
||||
#define print(x) cout<<(x)<<endl
|
||||
|
||||
namespace Limonp
|
||||
{
|
||||
using namespace std;
|
||||
@ -42,7 +47,7 @@ namespace Limonp
|
||||
}
|
||||
return str;
|
||||
}
|
||||
|
||||
|
||||
inline void string_format(string& res, const char* fmt, ...)
|
||||
{
|
||||
int size = 256;
|
||||
@ -63,27 +68,176 @@ namespace Limonp
|
||||
}
|
||||
}
|
||||
|
||||
inline bool joinStr(const vector<string>& src, string& dest, const string& connectorStr)
|
||||
{
|
||||
if(src.empty())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
for(uint i = 0; i < src.size() - 1; i++)
|
||||
{
|
||||
dest += src[i];
|
||||
dest += connectorStr;
|
||||
}
|
||||
dest += src[src.size() - 1];
|
||||
return true;
|
||||
}
|
||||
//inline bool joinStr(const vector<string>& src, string& dest, const string& connectorStr)
|
||||
//{
|
||||
// if(src.empty())
|
||||
// {
|
||||
// return false;
|
||||
// }
|
||||
// for(uint i = 0; i < src.size() - 1; i++)
|
||||
// {
|
||||
// dest += src[i];
|
||||
// dest += connectorStr;
|
||||
// }
|
||||
// dest += src[src.size() - 1];
|
||||
// return true;
|
||||
//}
|
||||
|
||||
inline string joinStr(const vector<string>& source, const string& connector)
|
||||
{
|
||||
string res;
|
||||
joinStr(source, res, connector);
|
||||
return res;
|
||||
}
|
||||
//inline string joinStr(const vector<string>& source, const string& connector)
|
||||
//{
|
||||
// string res;
|
||||
// joinStr(source, res, connector);
|
||||
// return res;
|
||||
//}
|
||||
|
||||
template<class T>
|
||||
void join(T begin, T end, string& res, const string& connector)
|
||||
{
|
||||
if(begin == end)
|
||||
{
|
||||
return;
|
||||
}
|
||||
stringstream ss;
|
||||
ss<<*begin;
|
||||
begin++;
|
||||
while(begin != end)
|
||||
{
|
||||
ss << connector << *begin;
|
||||
begin ++;
|
||||
}
|
||||
res = ss.str();
|
||||
}
|
||||
|
||||
template<class T>
|
||||
string join(T begin, T end, const string& connector)
|
||||
{
|
||||
string res;
|
||||
join(begin ,end, res, connector);
|
||||
return res;
|
||||
}
|
||||
|
||||
template<class T1, class T2>
|
||||
ostream& operator << (ostream& os, const pair<T1, T2>& pr)
|
||||
{
|
||||
os << pr.first << ":" << pr.second ;
|
||||
return os;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
ostream& operator << (ostream& os, const vector<T>& vec)
|
||||
{
|
||||
if(vec.empty())
|
||||
{
|
||||
return os << "[]";
|
||||
}
|
||||
os<<"[\""<<vec[0];
|
||||
for(uint i = 1; i < vec.size(); i++)
|
||||
{
|
||||
os<<"\", \""<<vec[i];
|
||||
}
|
||||
os<<"\"]";
|
||||
return os;
|
||||
}
|
||||
|
||||
template<class T>
|
||||
string& operator << (string& str, const T& obj)
|
||||
{
|
||||
stringstream ss;
|
||||
ss << obj; // call ostream& operator << (ostream& os,
|
||||
return str = ss.str();
|
||||
}
|
||||
|
||||
template<class T1, class T2>
|
||||
ostream& operator << (ostream& os, const map<T1, T2>& mp)
|
||||
{
|
||||
if(mp.empty())
|
||||
{
|
||||
os<<"{}";
|
||||
return os;
|
||||
}
|
||||
os<<'{';
|
||||
typename map<T1, T2>::const_iterator it = mp.begin();
|
||||
os<<*it;
|
||||
it++;
|
||||
while(it != mp.end())
|
||||
{
|
||||
os<<", "<<*it;
|
||||
it++;
|
||||
}
|
||||
os<<'}';
|
||||
return os;
|
||||
}
|
||||
|
||||
|
||||
//template<class T1, class T2>
|
||||
// string& operator << (string& str, const map<T1, T2>& mp)
|
||||
// {
|
||||
// if(mp.empty())
|
||||
// {
|
||||
// str = "{}";
|
||||
// return str;
|
||||
// }
|
||||
// stringstream ss;
|
||||
// ss<<'{';
|
||||
// typename map<T1, T2>::const_iterator it = mp.begin();
|
||||
// ss<<*it;
|
||||
// it++;
|
||||
// while(it != mp.end())
|
||||
// {
|
||||
// ss<<", "<<*it;
|
||||
// it++;
|
||||
// }
|
||||
// ss<<'}';
|
||||
// str = ss.str();
|
||||
// return str;
|
||||
// }
|
||||
|
||||
template<class T1, class T2>
|
||||
ostream& operator << (ostream& os, const HashMap<T1, T2>& mp)
|
||||
{
|
||||
if(mp.empty())
|
||||
{
|
||||
return os << "{}";
|
||||
}
|
||||
os<<'{';
|
||||
typename map<T1, T2>::const_iterator it = mp.begin();
|
||||
os<<*it;
|
||||
it++;
|
||||
while(it != mp.end())
|
||||
{
|
||||
os<<", "<<*it++;
|
||||
}
|
||||
return os<<'}';
|
||||
}
|
||||
|
||||
//template<class T>
|
||||
// string& operator << (string& str, const set<T>& st)
|
||||
// {
|
||||
// stringstream ss;
|
||||
// ss << st;
|
||||
// return str = ss.str();
|
||||
// }
|
||||
|
||||
template<class T>
|
||||
ostream& operator << (ostream& os, const set<T>& st)
|
||||
{
|
||||
if(st.empty())
|
||||
{
|
||||
os << "{}";
|
||||
return os;
|
||||
}
|
||||
os<<'{';
|
||||
typename set<T>::const_iterator it = st.begin();
|
||||
os<<*it;
|
||||
it++;
|
||||
while(it != st.end())
|
||||
{
|
||||
os<<", "<<*it;
|
||||
it++;
|
||||
}
|
||||
os<<'}';
|
||||
return os;
|
||||
}
|
||||
|
||||
inline bool splitStr(const string& src, vector<string>& res, const string& pattern)
|
||||
{
|
||||
@ -104,26 +258,24 @@ namespace Limonp
|
||||
return true;
|
||||
}
|
||||
res.push_back(src.substr(start, end - start));
|
||||
if(end == src.size() - 1)
|
||||
{
|
||||
res.push_back("");
|
||||
break;
|
||||
}
|
||||
if(end == src.size() - 1)
|
||||
{
|
||||
res.push_back("");
|
||||
break;
|
||||
}
|
||||
start = end + 1;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
inline string upperStr(const string& strIn)
|
||||
inline string& upper(string& str)
|
||||
{
|
||||
string str = strIn;
|
||||
transform(str.begin(), str.end(), str.begin(), (int (*)(int))toupper);
|
||||
return str;
|
||||
}
|
||||
|
||||
inline string lowerStr(const string& strIn)
|
||||
inline string& lower(string& str)
|
||||
{
|
||||
string str = strIn;
|
||||
transform(str.begin(), str.end(), str.begin(), (int (*)(int))tolower);
|
||||
return str;
|
||||
}
|
||||
@ -183,40 +335,40 @@ namespace Limonp
|
||||
return str.find(ch) != string::npos;
|
||||
}
|
||||
|
||||
inline void extractWords(const string& sentence, vector<string>& words)
|
||||
{
|
||||
bool flag = false;
|
||||
uint lhs = 0, len = 0;
|
||||
for(uint i = 0; i < sentence.size(); i++)
|
||||
{
|
||||
char x = sentence[i];
|
||||
if((0x0030 <= x && x<= 0x0039) || (0x0041 <= x && x <= 0x005a ) || (0x0061 <= x && x <= 0x007a))
|
||||
{
|
||||
if(flag)
|
||||
{
|
||||
len ++;
|
||||
}
|
||||
else
|
||||
{
|
||||
lhs = i;
|
||||
len = 1;
|
||||
}
|
||||
flag = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(flag)
|
||||
{
|
||||
words.push_back(string(sentence, lhs, len));
|
||||
}
|
||||
flag = false;
|
||||
}
|
||||
}
|
||||
if(flag)
|
||||
{
|
||||
words.push_back(string(sentence, lhs, len));
|
||||
}
|
||||
}
|
||||
//inline void extractWords(const string& sentence, vector<string>& words)
|
||||
//{
|
||||
// bool flag = false;
|
||||
// uint lhs = 0, len = 0;
|
||||
// for(uint i = 0; i < sentence.size(); i++)
|
||||
// {
|
||||
// char x = sentence[i];
|
||||
// if((0x0030 <= x && x<= 0x0039) || (0x0041 <= x && x <= 0x005a ) || (0x0061 <= x && x <= 0x007a))
|
||||
// {
|
||||
// if(flag)
|
||||
// {
|
||||
// len ++;
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// lhs = i;
|
||||
// len = 1;
|
||||
// }
|
||||
// flag = true;
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// if(flag)
|
||||
// {
|
||||
// words.push_back(string(sentence, lhs, len));
|
||||
// }
|
||||
// flag = false;
|
||||
// }
|
||||
// }
|
||||
// if(flag)
|
||||
// {
|
||||
// words.push_back(string(sentence, lhs, len));
|
||||
// }
|
||||
//}
|
||||
|
||||
|
||||
}
|
||||
|
@ -1,21 +0,0 @@
|
||||
/************************************
|
||||
* file enc : utf8
|
||||
* author : wuyanyi09@gmail.com
|
||||
************************************/
|
||||
#ifndef LIMONP_TYPEDEFS_H
|
||||
#define LIMONP_TYPEDEFS_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <vector>
|
||||
#include <sys/types.h>
|
||||
#include <tr1/unordered_map>
|
||||
#define HashMap std::tr1::unordered_map
|
||||
|
||||
namespace Limonp
|
||||
{
|
||||
typedef std::vector<uint16_t> Unicode;
|
||||
typedef std::vector<uint16_t>::const_iterator UnicodeConstIterator;
|
||||
}
|
||||
|
||||
|
||||
#endif
|
@ -1,142 +0,0 @@
|
||||
/************************************
|
||||
* file enc : ascii
|
||||
* author : wuyanyi09@gmail.com
|
||||
************************************/
|
||||
#ifndef LIMONP_VEC_FUNCTS_H
|
||||
#define LIMONP_VEC_FUNCTS_H
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
#include <queue>
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <utility>
|
||||
#include <algorithm>
|
||||
#include <sstream>
|
||||
|
||||
#define FOR_VECTOR(vec, i) for(size_t i = 0; i < vec.size(); i++)
|
||||
|
||||
#define PRINT_VECTOR(vec) FOR_VECTOR(vec, i)\
|
||||
{\
|
||||
cout<<vec[i]<<endl;\
|
||||
}
|
||||
|
||||
#define PRINT_MATRIX(mat) FOR_VECTOR(mat, i) \
|
||||
{\
|
||||
FOR_VECTOR(mat[i], j)\
|
||||
{\
|
||||
cout<<"["<<i<<","<<j<<"]:"<<mat[i][j]<<endl;\
|
||||
}\
|
||||
}
|
||||
|
||||
namespace Limonp
|
||||
{
|
||||
using namespace std;
|
||||
template <typename T>
|
||||
bool vecToString(const vector<T>& vec, string& res)
|
||||
{
|
||||
if(vec.empty())
|
||||
{
|
||||
res = "[]";
|
||||
return false;
|
||||
}
|
||||
stringstream ss;
|
||||
ss<<"[\""<<vec[0];
|
||||
for(uint i = 1; i < vec.size(); i++)
|
||||
{
|
||||
ss<<"\", \""<<vec[i];
|
||||
}
|
||||
ss<<"\"]";
|
||||
res = ss.str();
|
||||
return true;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
string vecToString(const vector<T>& vec)
|
||||
{
|
||||
string res;
|
||||
vecToString(vec, res);
|
||||
return res;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
bool isInVec(const vector<T>& vec, const T& item)
|
||||
{
|
||||
typename vector<T>::const_iterator it = find(vec.begin(), vec.end(), item);
|
||||
return it != vec.end();
|
||||
}
|
||||
template<typename T>
|
||||
void splitVec(const vector<T>& vecSrc, vector< pair<T, vector<T> > >& outVec, const vector<T>& patterns)
|
||||
{
|
||||
vector<T> tmp;
|
||||
T pattern;
|
||||
size_t patternSize = patterns.size();
|
||||
for(size_t i = 0; i < vecSrc.size(); i++)
|
||||
{
|
||||
size_t patternPos = patternSize;
|
||||
for(size_t j = 0; j < patternSize; j++)
|
||||
{
|
||||
if(patterns[j] == vecSrc[i])
|
||||
{
|
||||
patternPos = j;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(patternPos != patternSize)
|
||||
{
|
||||
if(!tmp.empty())
|
||||
{
|
||||
outVec.push_back(make_pair<T, vector<T> >(pattern, tmp));
|
||||
tmp.clear();
|
||||
}
|
||||
pattern = patterns[patternPos];
|
||||
}
|
||||
else
|
||||
{
|
||||
tmp.push_back(vecSrc[i]);
|
||||
}
|
||||
}
|
||||
if(!tmp.empty())
|
||||
{
|
||||
outVec.push_back(make_pair<T, vector<T> >(pattern, tmp));
|
||||
}
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void splitVec(const vector<T>& vecSrc, vector< vector<T> >& outVec, const vector<T>& patternVec)
|
||||
{
|
||||
vector<T> tmp;
|
||||
for(size_t i = 0; i < vecSrc.size(); i++)
|
||||
{
|
||||
bool flag = false;
|
||||
for(size_t j = 0; j < patternVec.size(); j++)
|
||||
{
|
||||
if(patternVec[j] == vecSrc[i])
|
||||
{
|
||||
flag = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(flag)
|
||||
{
|
||||
if(!tmp.empty())
|
||||
{
|
||||
outVec.push_back(tmp);
|
||||
tmp.clear();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
tmp.push_back(vecSrc[i]);
|
||||
}
|
||||
}
|
||||
if(!tmp.empty())
|
||||
{
|
||||
outVec.push_back(tmp);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
Loading…
x
Reference in New Issue
Block a user