-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathTransCode.hpp
More file actions
44 lines (37 loc) · 1.02 KB
/
TransCode.hpp
File metadata and controls
44 lines (37 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
/************************************
* file enc : utf-8
* author : wuyanyi09@gmail.com
************************************/
#ifndef CPPJIEBA_TRANSCODE_H
#define CPPJIEBA_TRANSCODE_H
#include "utility/str_functs.hpp"
namespace CppJieba
{
using namespace Limonp;
typedef std::vector<uint16_t> Unicode;
typedef std::vector<uint16_t>::iterator UnicodeIterator;
namespace TransCode
{
inline bool decode(const string& str, vector<uint16_t>& vec)
{
#ifdef CPPJIEBA_GBK
return gbkTrans(str, vec);
#else
return utf8ToUnicode(str, vec);
#endif
}
inline bool encode(vector<uint16_t>::const_iterator begin, vector<uint16_t>::const_iterator end, string& res)
{
#ifdef CPPJIEBA_GBK
return gbkTrans(begin, end, res);
#else
return unicodeToUtf8(begin, end, res);
#endif
}
inline bool encode(const vector<uint16_t>& uni, string& res)
{
return encode(uni.begin(), uni.end(), res);
}
}
}
#endif