Skip to content

Commit

Permalink
Fix #294
Browse files Browse the repository at this point in the history
  • Loading branch information
yhirose committed Mar 31, 2024
1 parent 9f06da7 commit f610523
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions peglib.h
Original file line number Diff line number Diff line change
Expand Up @@ -381,9 +381,9 @@ class Trie {
: ignore_case_(ignore_case) {
size_t id = 0;
for (const auto &item : items) {
const auto &s = ignore_case ? to_lower(item) : item;
for (size_t len = 1; len <= item.size(); len++) {
auto last = len == item.size();
const auto &s = ignore_case ? to_lower(item) : item;
std::string_view sv(s.data(), len);
auto it = dic_.find(sv);
if (it == dic_.end()) {
Expand All @@ -399,12 +399,17 @@ class Trie {
}

size_t match(const char *text, size_t text_len, size_t &id) const {
std::string lower_text;
if (ignore_case_) {
lower_text = to_lower(text);
text = lower_text.data();
}

size_t match_len = 0;
auto done = false;
size_t len = 1;
while (!done && len <= text_len) {
const auto &s = ignore_case_ ? to_lower(text) : std::string(text);
std::string_view sv(s.data(), len);
std::string_view sv(text, len);
auto it = dic_.find(sv);
if (it == dic_.end()) {
done = true;
Expand Down

0 comments on commit f610523

Please sign in to comment.