MCPcopy Create free account
hub / github.com/BYVoid/OpenCC / AppendConverted

Method AppendConverted

src/Conversion.cpp:29–64  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

27 : dict(_dict), prefixMatch(new PrefixMatch(_dict)) {}
28
29void Conversion::AppendConverted(std::string_view phrase,
30 std::string* output) const {
31 if (phrase.empty()) {
32 return;
33 }
34 const size_t phraseLength = phrase.size();
35 output->reserve(output->size() + phraseLength + phraseLength / 5);
36
37 const char* phraseData = phrase.data();
38 const char* phraseEnd = phraseData + phraseLength;
39 for (const char* pstr = phraseData; pstr < phraseEnd;) {
40 size_t remainingLength = phraseEnd - pstr;
41 const PrefixMatchView matched =
42 prefixMatch->MatchPrefixView(pstr, remainingLength);
43 size_t matchedLength;
44 if (!matched.matched) {
45 matchedLength =
46 UTF8Util::NextIdeographicDescriptionSequenceLength(pstr,
47 remainingLength);
48 if (matchedLength == 0) {
49 matchedLength = UTF8Util::NextCharLength(pstr);
50 }
51 if (matchedLength > remainingLength) {
52 matchedLength = remainingLength;
53 }
54 output->append(pstr, matchedLength);
55 } else {
56 matchedLength = matched.keyLength;
57 if (matchedLength > remainingLength) {
58 matchedLength = remainingLength;
59 }
60 output->append(matched.value.data(), matched.value.size());
61 }
62 pstr += matchedLength;
63 }
64}
65
66std::string Conversion::Convert(std::string_view phrase) const {
67 if (phrase.empty()) {

Callers 1

Calls 8

NextCharLengthFunction · 0.85
MatchPrefixViewMethod · 0.80
emptyMethod · 0.45
sizeMethod · 0.45
reserveMethod · 0.45
dataMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected