aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/github.com/ClickHouse/clickhouse-go/word_matcher.go
blob: 7cd9dcd7502234938b46a6bc1da6e39207037ac0 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package clickhouse

import (
	"strings"
	"unicode"
)

// wordMatcher is a simple automata to match a single word (case insensitive)
type wordMatcher struct {
	word     []rune
	position uint8
}

// newMatcher returns matcher for word needle
func newMatcher(needle string) *wordMatcher {
	return &wordMatcher{word: []rune(strings.ToUpper(needle)),
		position: 0}
}

func (m *wordMatcher) matchRune(r rune) bool {
	if m.word[m.position] == unicode.ToUpper(r) {
		if m.position == uint8(len(m.word)-1) {
			m.position = 0
			return true
		}
		m.position++
	} else {
		m.position = 0
	}
	return false
}