1package clickhouse
2
3import (
4	"strings"
5	"unicode"
6)
7
8// wordMatcher is a simple automata to match a single word (case insensitive)
9type wordMatcher struct {
10	word     []rune
11	position uint8
12}
13
14// newMatcher returns matcher for word needle
15func newMatcher(needle string) *wordMatcher {
16	return &wordMatcher{word: []rune(strings.ToUpper(needle)),
17		position: 0}
18}
19
20func (m *wordMatcher) matchRune(r rune) bool {
21	if m.word[m.position] == unicode.ToUpper(r) {
22		if m.position == uint8(len(m.word)-1) {
23			m.position = 0
24			return true
25		}
26		m.position++
27	} else {
28		m.position = 0
29	}
30	return false
31}
32