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

Method MatchPrefix

src/Dict.cpp:25–40  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

23using namespace opencc;
24
25Optional<const DictEntry*> Dict::MatchPrefix(const char* word,
26 size_t wordLen) const {
27 long len = static_cast<long>((std::min)(KeyMaxLength(), wordLen));
28 std::string wordTrunc = UTF8Util::TruncateUTF8(word, len);
29 const char* wordTruncPtr = wordTrunc.c_str() + len;
30 for (; len > 0;) {
31 wordTrunc.resize(static_cast<size_t>(len));
32 wordTruncPtr = wordTrunc.c_str() + len;
33 const Optional<const DictEntry*>& result = Match(wordTrunc.c_str());
34 if (!result.IsNull()) {
35 return result;
36 }
37 len -= static_cast<long>(UTF8Util::PrevCharLength(wordTruncPtr));
38 }
39 return Optional<const DictEntry*>::Null();
40}
41
42std::vector<const DictEntry*> Dict::MatchAllPrefixes(const char* word,
43 size_t wordLen) const {

Callers 6

TEST_FFunction · 0.45
TEST_FFunction · 0.45
TEST_FFunction · 0.45
TestMatchPrefixMethod · 0.45
TEST_FFunction · 0.45
TEST_FFunction · 0.45

Calls 5

TruncateUTF8Function · 0.85
PrevCharLengthFunction · 0.85
MatchFunction · 0.70
resizeMethod · 0.45
IsNullMethod · 0.45

Tested by 6

TEST_FFunction · 0.36
TEST_FFunction · 0.36
TEST_FFunction · 0.36
TestMatchPrefixMethod · 0.36
TEST_FFunction · 0.36
TEST_FFunction · 0.36