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

Method MatchPrefix

src/PrefixMatch.cpp:399–424  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

397PrefixMatch::~PrefixMatch() {}
398
399PrefixMatch::Match PrefixMatch::MatchPrefix(const char* word,
400 size_t len) const {
401 if (singleDict != nullptr) {
402 struct MatchCache {
403 std::string key;
404 std::string value;
405 };
406 // key/value pointers are valid until the next MatchPrefix() call on this
407 // thread.
408 static thread_local MatchCache matchCache;
409 const PrefixMatchView pv = singleDict->MatchPrefixValue(word, len);
410 if (pv.matched) {
411 matchCache.key = std::string(pv.key);
412 matchCache.value = std::string(pv.value);
413 return Match{true, pv.keyLength, &matchCache.key, &matchCache.value};
414 }
415 return Match{false, 0, nullptr, nullptr};
416 }
417
418 const Tables::Matcher::Candidate candidate =
419 tables->matcher->MatchPrefixCandidate(word, len);
420 if (candidate.hasValue) {
421 return Match{true, candidate.keyLength, candidate.key, candidate.value};
422 }
423 return Match{false, 0, nullptr, nullptr};
424}
425
426PrefixMatchView PrefixMatch::MatchPrefixView(const char* word,
427 size_t len) const {

Callers

nothing calls this directly

Calls 2

MatchPrefixValueMethod · 0.45
MatchPrefixCandidateMethod · 0.45

Tested by

no test coverage detected