react-native-jieba 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Jieba.podspec +30 -0
- package/LICENSE +20 -0
- package/README.md +103 -0
- package/android/CMakeLists.txt +29 -0
- package/android/build.gradle +60 -0
- package/android/generated/java/com/jieba/NativeJiebaAndroidHelperSpec.java +38 -0
- package/android/generated/java/com/jieba/NativeJiebaSpec.java +74 -0
- package/android/generated/jni/CMakeLists.txt +28 -0
- package/android/generated/jni/JiebaSpec-generated.cpp +98 -0
- package/android/generated/jni/JiebaSpec.h +39 -0
- package/android/generated/jni/react/renderer/components/JiebaSpec/JiebaSpecJSI.h +144 -0
- package/android/src/main/AndroidManifest.xml +2 -0
- package/android/src/main/java/com/jieba/JiebaAndroidHelperModule.kt +48 -0
- package/android/src/main/java/com/jieba/JiebaPackage.kt +32 -0
- package/cpp/JiebaImpl.cpp +154 -0
- package/cpp/JiebaImpl.h +37 -0
- package/cpp/cppjieba/LICENSE +20 -0
- package/cpp/cppjieba/deps/limonp/LICENSE +20 -0
- package/cpp/cppjieba/deps/limonp/include/limonp/ArgvContext.hpp +70 -0
- package/cpp/cppjieba/deps/limonp/include/limonp/Closure.hpp +206 -0
- package/cpp/cppjieba/deps/limonp/include/limonp/Colors.hpp +31 -0
- package/cpp/cppjieba/deps/limonp/include/limonp/Condition.hpp +38 -0
- package/cpp/cppjieba/deps/limonp/include/limonp/Config.hpp +103 -0
- package/cpp/cppjieba/deps/limonp/include/limonp/ForcePublic.hpp +7 -0
- package/cpp/cppjieba/deps/limonp/include/limonp/LocalVector.hpp +139 -0
- package/cpp/cppjieba/deps/limonp/include/limonp/Logging.hpp +92 -0
- package/cpp/cppjieba/deps/limonp/include/limonp/NonCopyable.hpp +21 -0
- package/cpp/cppjieba/deps/limonp/include/limonp/StdExtension.hpp +157 -0
- package/cpp/cppjieba/deps/limonp/include/limonp/StringUtil.hpp +386 -0
- package/cpp/cppjieba/dict/hmm_model.utf8 +34 -0
- package/cpp/cppjieba/dict/idf.utf8 +258826 -0
- package/cpp/cppjieba/dict/jieba.dict.utf8 +348982 -0
- package/cpp/cppjieba/dict/stop_words.utf8 +1534 -0
- package/cpp/cppjieba/dict/user.dict.utf8 +3 -0
- package/cpp/cppjieba/include/cppjieba/DictTrie.hpp +322 -0
- package/cpp/cppjieba/include/cppjieba/FullSegment.hpp +94 -0
- package/cpp/cppjieba/include/cppjieba/HMMModel.hpp +131 -0
- package/cpp/cppjieba/include/cppjieba/HMMSegment.hpp +211 -0
- package/cpp/cppjieba/include/cppjieba/Jieba.hpp +169 -0
- package/cpp/cppjieba/include/cppjieba/KeywordExtractor.hpp +152 -0
- package/cpp/cppjieba/include/cppjieba/MPSegment.hpp +137 -0
- package/cpp/cppjieba/include/cppjieba/MixSegment.hpp +109 -0
- package/cpp/cppjieba/include/cppjieba/PosTagger.hpp +77 -0
- package/cpp/cppjieba/include/cppjieba/PreFilter.hpp +54 -0
- package/cpp/cppjieba/include/cppjieba/QuerySegment.hpp +89 -0
- package/cpp/cppjieba/include/cppjieba/SegmentBase.hpp +46 -0
- package/cpp/cppjieba/include/cppjieba/SegmentTagged.hpp +23 -0
- package/cpp/cppjieba/include/cppjieba/TextRankExtractor.hpp +192 -0
- package/cpp/cppjieba/include/cppjieba/Trie.hpp +200 -0
- package/cpp/cppjieba/include/cppjieba/Unicode.hpp +231 -0
- package/cpp/cppjieba/include/cppjieba/UnicodeFile.hpp +68 -0
- package/ios/OnLoad.mm +35 -0
- package/ios/generated/ReactCodegen/JiebaSpec/JiebaSpec-generated.mm +126 -0
- package/ios/generated/ReactCodegen/JiebaSpec/JiebaSpec.h +103 -0
- package/ios/generated/ReactCodegen/JiebaSpecJSI.h +144 -0
- package/lib/module/NativeJieba.js +5 -0
- package/lib/module/NativeJieba.js.map +1 -0
- package/lib/module/NativeJiebaAndroidHelper.js +5 -0
- package/lib/module/NativeJiebaAndroidHelper.js.map +1 -0
- package/lib/module/index.js +5 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/init.js +24 -0
- package/lib/module/init.js.map +1 -0
- package/lib/module/jieba.js +31 -0
- package/lib/module/jieba.js.map +1 -0
- package/lib/module/package.json +1 -0
- package/lib/typescript/package.json +1 -0
- package/lib/typescript/src/NativeJieba.d.ts +22 -0
- package/lib/typescript/src/NativeJieba.d.ts.map +1 -0
- package/lib/typescript/src/NativeJiebaAndroidHelper.d.ts +7 -0
- package/lib/typescript/src/NativeJiebaAndroidHelper.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +4 -0
- package/lib/typescript/src/index.d.ts.map +1 -0
- package/lib/typescript/src/init.d.ts +2 -0
- package/lib/typescript/src/init.d.ts.map +1 -0
- package/lib/typescript/src/jieba.d.ts +18 -0
- package/lib/typescript/src/jieba.d.ts.map +1 -0
- package/package.json +197 -0
- package/react-native.config.js +17 -0
- package/src/NativeJieba.ts +19 -0
- package/src/NativeJiebaAndroidHelper.ts +7 -0
- package/src/index.tsx +13 -0
- package/src/init.ts +25 -0
- package/src/jieba.ts +43 -0
|
@@ -0,0 +1,386 @@
|
|
|
1
|
+
/************************************
|
|
2
|
+
* file enc : ascii
|
|
3
|
+
* author : wuyanyi09@gmail.com
|
|
4
|
+
************************************/
|
|
5
|
+
#ifndef LIMONP_STR_FUNCTS_H
|
|
6
|
+
#define LIMONP_STR_FUNCTS_H
|
|
7
|
+
#include <fstream>
|
|
8
|
+
#include <iostream>
|
|
9
|
+
#include <string>
|
|
10
|
+
#include <vector>
|
|
11
|
+
#include <algorithm>
|
|
12
|
+
#include <cctype>
|
|
13
|
+
#include <map>
|
|
14
|
+
#include <cassert>
|
|
15
|
+
#include <ctime>
|
|
16
|
+
#include <stdint.h>
|
|
17
|
+
#include <stdio.h>
|
|
18
|
+
#include <stdarg.h>
|
|
19
|
+
#include <memory.h>
|
|
20
|
+
#include <functional>
|
|
21
|
+
#include <locale>
|
|
22
|
+
#include <sstream>
|
|
23
|
+
#include <sys/types.h>
|
|
24
|
+
#include <iterator>
|
|
25
|
+
#include <algorithm>
|
|
26
|
+
#include "StdExtension.hpp"
|
|
27
|
+
|
|
28
|
+
namespace limonp {
|
|
29
|
+
using namespace std;
|
|
30
|
+
inline string StringFormat(const char* fmt, ...) {
|
|
31
|
+
int size = 256;
|
|
32
|
+
std::string str;
|
|
33
|
+
va_list ap;
|
|
34
|
+
while (1) {
|
|
35
|
+
str.resize(size);
|
|
36
|
+
va_start(ap, fmt);
|
|
37
|
+
int n = vsnprintf((char *)str.c_str(), size, fmt, ap);
|
|
38
|
+
va_end(ap);
|
|
39
|
+
if (n > -1 && n < size) {
|
|
40
|
+
str.resize(n);
|
|
41
|
+
return str;
|
|
42
|
+
}
|
|
43
|
+
if (n > -1)
|
|
44
|
+
size = n + 1;
|
|
45
|
+
else
|
|
46
|
+
size *= 2;
|
|
47
|
+
}
|
|
48
|
+
return str;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
template<class T>
|
|
52
|
+
void Join(T begin, T end, string& res, const string& connector) {
|
|
53
|
+
if(begin == end) {
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
stringstream ss;
|
|
57
|
+
ss<<*begin;
|
|
58
|
+
begin++;
|
|
59
|
+
while(begin != end) {
|
|
60
|
+
ss << connector << *begin;
|
|
61
|
+
begin ++;
|
|
62
|
+
}
|
|
63
|
+
res = ss.str();
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
template<class T>
|
|
67
|
+
string Join(T begin, T end, const string& connector) {
|
|
68
|
+
string res;
|
|
69
|
+
Join(begin ,end, res, connector);
|
|
70
|
+
return res;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
inline string& Upper(string& str) {
|
|
74
|
+
transform(str.begin(), str.end(), str.begin(), (int (*)(int))toupper);
|
|
75
|
+
return str;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
inline string& Lower(string& str) {
|
|
79
|
+
transform(str.begin(), str.end(), str.begin(), (int (*)(int))tolower);
|
|
80
|
+
return str;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
inline bool IsSpace(unsigned c) {
|
|
84
|
+
// when passing large int as the argument of isspace, it core dump, so here need a type cast.
|
|
85
|
+
return c > 0xff ? false : std::isspace(c & 0xff) != 0;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
inline std::string& LTrim(std::string &s) {
|
|
89
|
+
s.erase(s.begin(), std::find_if(s.begin(), s.end(), [](unsigned char ch) {
|
|
90
|
+
return !std::isspace(ch);
|
|
91
|
+
}));
|
|
92
|
+
return s;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
inline std::string& RTrim(std::string &s) {
|
|
96
|
+
s.erase(std::find_if(s.rbegin(), s.rend(), [](unsigned char ch) {
|
|
97
|
+
return !std::isspace(ch);
|
|
98
|
+
}).base(), s.end());
|
|
99
|
+
return s;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
inline std::string& Trim(std::string &s) {
|
|
103
|
+
return LTrim(RTrim(s));
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
inline std::string& LTrim(std::string& s, char x) {
|
|
107
|
+
s.erase(s.begin(), std::find_if(s.begin(), s.end(),
|
|
108
|
+
[x](unsigned char c) { return !std::isspace(c) && c != x; }));
|
|
109
|
+
return s;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
inline std::string& RTrim(std::string& s, char x) {
|
|
113
|
+
s.erase(std::find_if(s.rbegin(), s.rend(),
|
|
114
|
+
[x](unsigned char c) { return !std::isspace(c) && c != x; }).base(), s.end());
|
|
115
|
+
return s;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
inline std::string& Trim(std::string &s, char x) {
|
|
119
|
+
return LTrim(RTrim(s, x), x);
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
inline void Split(const string& src, vector<string>& res, const string& pattern, size_t maxsplit = string::npos) {
|
|
123
|
+
res.clear();
|
|
124
|
+
size_t Start = 0;
|
|
125
|
+
size_t end = 0;
|
|
126
|
+
string sub;
|
|
127
|
+
while(Start < src.size()) {
|
|
128
|
+
end = src.find_first_of(pattern, Start);
|
|
129
|
+
if(string::npos == end || res.size() >= maxsplit) {
|
|
130
|
+
sub = src.substr(Start);
|
|
131
|
+
res.push_back(sub);
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
sub = src.substr(Start, end - Start);
|
|
135
|
+
res.push_back(sub);
|
|
136
|
+
Start = end + 1;
|
|
137
|
+
}
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
inline vector<string> Split(const string& src, const string& pattern, size_t maxsplit = string::npos) {
|
|
142
|
+
vector<string> res;
|
|
143
|
+
Split(src, res, pattern, maxsplit);
|
|
144
|
+
return res;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
inline bool StartsWith(const string& str, const string& prefix) {
|
|
148
|
+
if(prefix.length() > str.length()) {
|
|
149
|
+
return false;
|
|
150
|
+
}
|
|
151
|
+
return 0 == str.compare(0, prefix.length(), prefix);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
inline bool EndsWith(const string& str, const string& suffix) {
|
|
155
|
+
if(suffix.length() > str.length()) {
|
|
156
|
+
return false;
|
|
157
|
+
}
|
|
158
|
+
return 0 == str.compare(str.length() - suffix.length(), suffix.length(), suffix);
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
inline bool IsInStr(const string& str, char ch) {
|
|
162
|
+
return str.find(ch) != string::npos;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
inline uint16_t TwocharToUint16(char high, char low) {
|
|
166
|
+
return (((uint16_t(high) & 0x00ff ) << 8) | (uint16_t(low) & 0x00ff));
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
template <class Uint16Container>
|
|
170
|
+
bool Utf8ToUnicode(const char * const str, size_t len, Uint16Container& vec) {
|
|
171
|
+
if(!str) {
|
|
172
|
+
return false;
|
|
173
|
+
}
|
|
174
|
+
char ch1, ch2;
|
|
175
|
+
uint16_t tmp;
|
|
176
|
+
vec.clear();
|
|
177
|
+
for(size_t i = 0; i < len;) {
|
|
178
|
+
if(!(str[i] & 0x80)) { // 0xxxxxxx
|
|
179
|
+
vec.push_back(str[i]);
|
|
180
|
+
i++;
|
|
181
|
+
} else if ((uint8_t)str[i] <= 0xdf && i + 1 < len) { // 110xxxxxx
|
|
182
|
+
ch1 = (str[i] >> 2) & 0x07;
|
|
183
|
+
ch2 = (str[i+1] & 0x3f) | ((str[i] & 0x03) << 6 );
|
|
184
|
+
tmp = (((uint16_t(ch1) & 0x00ff ) << 8) | (uint16_t(ch2) & 0x00ff));
|
|
185
|
+
vec.push_back(tmp);
|
|
186
|
+
i += 2;
|
|
187
|
+
} else if((uint8_t)str[i] <= 0xef && i + 2 < len) {
|
|
188
|
+
ch1 = ((uint8_t)str[i] << 4) | ((str[i+1] >> 2) & 0x0f );
|
|
189
|
+
ch2 = (((uint8_t)str[i+1]<<6) & 0xc0) | (str[i+2] & 0x3f);
|
|
190
|
+
tmp = (((uint16_t(ch1) & 0x00ff ) << 8) | (uint16_t(ch2) & 0x00ff));
|
|
191
|
+
vec.push_back(tmp);
|
|
192
|
+
i += 3;
|
|
193
|
+
} else {
|
|
194
|
+
return false;
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
return true;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
template <class Uint16Container>
|
|
201
|
+
bool Utf8ToUnicode(const string& str, Uint16Container& vec) {
|
|
202
|
+
return Utf8ToUnicode(str.c_str(), str.size(), vec);
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
template <class Uint32Container>
|
|
206
|
+
bool Utf8ToUnicode32(const string& str, Uint32Container& vec) {
|
|
207
|
+
uint32_t tmp;
|
|
208
|
+
vec.clear();
|
|
209
|
+
for(size_t i = 0; i < str.size();) {
|
|
210
|
+
if(!(str[i] & 0x80)) { // 0xxxxxxx
|
|
211
|
+
// 7bit, total 7bit
|
|
212
|
+
tmp = (uint8_t)(str[i]) & 0x7f;
|
|
213
|
+
i++;
|
|
214
|
+
} else if ((uint8_t)str[i] <= 0xdf && i + 1 < str.size()) { // 110xxxxxx
|
|
215
|
+
// 5bit, total 5bit
|
|
216
|
+
tmp = (uint8_t)(str[i]) & 0x1f;
|
|
217
|
+
|
|
218
|
+
// 6bit, total 11bit
|
|
219
|
+
tmp <<= 6;
|
|
220
|
+
tmp |= (uint8_t)(str[i+1]) & 0x3f;
|
|
221
|
+
i += 2;
|
|
222
|
+
} else if((uint8_t)str[i] <= 0xef && i + 2 < str.size()) { // 1110xxxxxx
|
|
223
|
+
// 4bit, total 4bit
|
|
224
|
+
tmp = (uint8_t)(str[i]) & 0x0f;
|
|
225
|
+
|
|
226
|
+
// 6bit, total 10bit
|
|
227
|
+
tmp <<= 6;
|
|
228
|
+
tmp |= (uint8_t)(str[i+1]) & 0x3f;
|
|
229
|
+
|
|
230
|
+
// 6bit, total 16bit
|
|
231
|
+
tmp <<= 6;
|
|
232
|
+
tmp |= (uint8_t)(str[i+2]) & 0x3f;
|
|
233
|
+
|
|
234
|
+
i += 3;
|
|
235
|
+
} else if((uint8_t)str[i] <= 0xf7 && i + 3 < str.size()) { // 11110xxxx
|
|
236
|
+
// 3bit, total 3bit
|
|
237
|
+
tmp = (uint8_t)(str[i]) & 0x07;
|
|
238
|
+
|
|
239
|
+
// 6bit, total 9bit
|
|
240
|
+
tmp <<= 6;
|
|
241
|
+
tmp |= (uint8_t)(str[i+1]) & 0x3f;
|
|
242
|
+
|
|
243
|
+
// 6bit, total 15bit
|
|
244
|
+
tmp <<= 6;
|
|
245
|
+
tmp |= (uint8_t)(str[i+2]) & 0x3f;
|
|
246
|
+
|
|
247
|
+
// 6bit, total 21bit
|
|
248
|
+
tmp <<= 6;
|
|
249
|
+
tmp |= (uint8_t)(str[i+3]) & 0x3f;
|
|
250
|
+
|
|
251
|
+
i += 4;
|
|
252
|
+
} else {
|
|
253
|
+
return false;
|
|
254
|
+
}
|
|
255
|
+
vec.push_back(tmp);
|
|
256
|
+
}
|
|
257
|
+
return true;
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
template <class Uint32ContainerConIter>
|
|
261
|
+
void Unicode32ToUtf8(Uint32ContainerConIter begin, Uint32ContainerConIter end, string& res) {
|
|
262
|
+
res.clear();
|
|
263
|
+
uint32_t ui;
|
|
264
|
+
while(begin != end) {
|
|
265
|
+
ui = *begin;
|
|
266
|
+
if(ui <= 0x7f) {
|
|
267
|
+
res += char(ui);
|
|
268
|
+
} else if(ui <= 0x7ff) {
|
|
269
|
+
res += char(((ui >> 6) & 0x1f) | 0xc0);
|
|
270
|
+
res += char((ui & 0x3f) | 0x80);
|
|
271
|
+
} else if(ui <= 0xffff) {
|
|
272
|
+
res += char(((ui >> 12) & 0x0f) | 0xe0);
|
|
273
|
+
res += char(((ui >> 6) & 0x3f) | 0x80);
|
|
274
|
+
res += char((ui & 0x3f) | 0x80);
|
|
275
|
+
} else {
|
|
276
|
+
res += char(((ui >> 18) & 0x03) | 0xf0);
|
|
277
|
+
res += char(((ui >> 12) & 0x3f) | 0x80);
|
|
278
|
+
res += char(((ui >> 6) & 0x3f) | 0x80);
|
|
279
|
+
res += char((ui & 0x3f) | 0x80);
|
|
280
|
+
}
|
|
281
|
+
begin ++;
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
template <class Uint16ContainerConIter>
|
|
286
|
+
void UnicodeToUtf8(Uint16ContainerConIter begin, Uint16ContainerConIter end, string& res) {
|
|
287
|
+
res.clear();
|
|
288
|
+
uint16_t ui;
|
|
289
|
+
while(begin != end) {
|
|
290
|
+
ui = *begin;
|
|
291
|
+
if(ui <= 0x7f) {
|
|
292
|
+
res += char(ui);
|
|
293
|
+
} else if(ui <= 0x7ff) {
|
|
294
|
+
res += char(((ui>>6) & 0x1f) | 0xc0);
|
|
295
|
+
res += char((ui & 0x3f) | 0x80);
|
|
296
|
+
} else {
|
|
297
|
+
res += char(((ui >> 12) & 0x0f )| 0xe0);
|
|
298
|
+
res += char(((ui>>6) & 0x3f )| 0x80 );
|
|
299
|
+
res += char((ui & 0x3f) | 0x80);
|
|
300
|
+
}
|
|
301
|
+
begin ++;
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
|
|
306
|
+
template <class Uint16Container>
|
|
307
|
+
bool GBKTrans(const char* const str, size_t len, Uint16Container& vec) {
|
|
308
|
+
vec.clear();
|
|
309
|
+
if(!str) {
|
|
310
|
+
return true;
|
|
311
|
+
}
|
|
312
|
+
size_t i = 0;
|
|
313
|
+
while(i < len) {
|
|
314
|
+
if(0 == (str[i] & 0x80)) {
|
|
315
|
+
vec.push_back(uint16_t(str[i]));
|
|
316
|
+
i++;
|
|
317
|
+
} else {
|
|
318
|
+
if(i + 1 < len) { //&& (str[i+1] & 0x80))
|
|
319
|
+
uint16_t tmp = (((uint16_t(str[i]) & 0x00ff ) << 8) | (uint16_t(str[i+1]) & 0x00ff));
|
|
320
|
+
vec.push_back(tmp);
|
|
321
|
+
i += 2;
|
|
322
|
+
} else {
|
|
323
|
+
return false;
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
return true;
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
template <class Uint16Container>
|
|
331
|
+
bool GBKTrans(const string& str, Uint16Container& vec) {
|
|
332
|
+
return GBKTrans(str.c_str(), str.size(), vec);
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
template <class Uint16ContainerConIter>
|
|
336
|
+
void GBKTrans(Uint16ContainerConIter begin, Uint16ContainerConIter end, string& res) {
|
|
337
|
+
res.clear();
|
|
338
|
+
//pair<char, char> pa;
|
|
339
|
+
char first, second;
|
|
340
|
+
while(begin != end) {
|
|
341
|
+
//pa = uint16ToChar2(*begin);
|
|
342
|
+
first = ((*begin)>>8) & 0x00ff;
|
|
343
|
+
second = (*begin) & 0x00ff;
|
|
344
|
+
if(first & 0x80) {
|
|
345
|
+
res += first;
|
|
346
|
+
res += second;
|
|
347
|
+
} else {
|
|
348
|
+
res += second;
|
|
349
|
+
}
|
|
350
|
+
begin++;
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
/*
|
|
355
|
+
* format example: "%Y-%m-%d %H:%M:%S"
|
|
356
|
+
*/
|
|
357
|
+
inline void GetTime(const string& format, string& timeStr) {
|
|
358
|
+
time_t timeNow;
|
|
359
|
+
time(&timeNow);
|
|
360
|
+
|
|
361
|
+
struct tm tmNow;
|
|
362
|
+
|
|
363
|
+
#if defined(_WIN32) || defined(_WIN64)
|
|
364
|
+
errno_t e = localtime_s(&tmNow, &timeNow);
|
|
365
|
+
assert(e == 0);
|
|
366
|
+
#else
|
|
367
|
+
struct tm * tm_tmp = localtime_r(&timeNow, &tmNow);
|
|
368
|
+
assert(tm_tmp != nullptr);
|
|
369
|
+
#endif
|
|
370
|
+
|
|
371
|
+
timeStr.resize(64);
|
|
372
|
+
|
|
373
|
+
size_t len = strftime((char*)timeStr.c_str(), timeStr.size(), format.c_str(), &tmNow);
|
|
374
|
+
|
|
375
|
+
timeStr.resize(len);
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
inline string PathJoin(const string& path1, const string& path2) {
|
|
379
|
+
if(EndsWith(path1, "/")) {
|
|
380
|
+
return path1 + path2;
|
|
381
|
+
}
|
|
382
|
+
return path1 + "/" + path2;
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
}
|
|
386
|
+
#endif
|