-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathPinyinRes.cpp
More file actions
30 lines (26 loc) · 850 Bytes
/
PinyinRes.cpp
File metadata and controls
30 lines (26 loc) · 850 Bytes
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
#include <cpp-pinyin/PinyinRes.h>
namespace Pinyin
{
// Convert PinyinResVector to std::vector<std::string>
std::vector<std::string> PinyinResVector::toStdVector() const {
std::vector<std::string> result;
result.reserve(this->size());
for (const auto &res : *this) {
result.emplace_back(res.error ? res.hanzi : res.pinyin);
}
return result;
}
// Convert PinyinResVector to std::string with delimiter
std::string PinyinResVector::toStdStr(const std::string &delimiter) const {
std::string result;
bool first = true;
for (const auto &res : *this) {
if (!first) {
result += delimiter;
}
result += res.error ? res.hanzi : res.pinyin;
first = false;
}
return result;
}
}