int32_t UCharsDictionaryMatcher::matches(UText *text, int32_t maxLength, int32_t limit, int32_t *lengths, int32_t *cpLengths, int32_t *values, int32_t *prefix, UnicodeSet const* ignoreSet, int32_t minLength) const { UCharsTrie uct(characters); int32_t startingTextIndex = utext_getNativeIndex(text); int32_t wordCount = 0; int32_t codePointsMatched = 0; for (UChar32 c = utext_next32(text); c >= 0; c=utext_next32(text)) { UStringTrieResult result = (codePointsMatched == 0) ? uct.first(c) : uct.next(c); int32_t lengthMatched = utext_getNativeIndex(text) - startingTextIndex; codePointsMatched += 1; if (ignoreSet != NULL && ignoreSet->contains(c)) { continue; } if (USTRINGTRIE_HAS_VALUE(result)) { if (codePointsMatched < minLength) { continue; } if (wordCount < limit) { if (values != NULL) { values[wordCount] = uct.getValue(); } if (lengths != NULL) { lengths[wordCount] = lengthMatched; } if (cpLengths != NULL) { cpLengths[wordCount] = codePointsMatched; } ++wordCount; } if (result == USTRINGTRIE_FINAL_VALUE) { break; } } else if (result == USTRINGTRIE_NO_MATCH) { break; } if (lengthMatched >= maxLength) { break; } } if (prefix != NULL) { *prefix = codePointsMatched; } return wordCount; }
int32_t UCharsDictionaryMatcher::matches(UText *text, int32_t maxLength, int32_t *lengths, int32_t &count, int32_t limit, int32_t *values) const { UCharsTrie uct(characters); UChar32 c = utext_next32(text); if (c < 0) { return 0; } UStringTrieResult result = uct.first(c); int32_t numChars = 1; count = 0; for (;;) { if (USTRINGTRIE_HAS_VALUE(result)) { if (count < limit) { if (values != NULL) { values[count] = uct.getValue(); } lengths[count++] = numChars; } if (result == USTRINGTRIE_FINAL_VALUE) { break; } } else if (result == USTRINGTRIE_NO_MATCH) { break; } // TODO: why do we have a text limit if the UText knows its length? if (numChars >= maxLength) { break; } c = utext_next32(text); if (c < 0) { break; } ++numChars; result = uct.next(c); } return numChars; }