iris/mvc/activator/methodfunc/func_lexer.go
Gerasimos (Makis) Maropoulos 69b5327ecc Update to Version 8.4.2 | Read HISTORY.md
https://github.com/kataras/iris/blob/master/HISTORY.md#fr-15-september-2017--v842

Former-commit-id: 0ee4cc1d93ef7f26e5d402fdfbe07062aff5b08c
2017-09-15 15:05:35 +03:00

90 lines
1.3 KiB
Go

package methodfunc
import (
"unicode"
)
const (
tokenBy = "By"
tokenWildcard = "Wildcard" // should be followed by "By",
)
// word lexer, not characters.
type lexer struct {
words []string
cur int
}
func newLexer(s string) *lexer {
l := new(lexer)
l.reset(s)
return l
}
func (l *lexer) reset(trailing string) {
l.cur = -1
var words []string
if trailing != "" {
end := len(trailing)
start := -1
for i, n := 0, end; i < n; i++ {
c := rune(trailing[i])
if unicode.IsUpper(c) {
// it doesn't count the last uppercase
if start != -1 {
end = i
words = append(words, trailing[start:end])
}
start = i
continue
}
end = i + 1
}
if end > 0 && len(trailing) >= end {
words = append(words, trailing[start:end])
}
}
l.words = words
}
func (l *lexer) next() (w string) {
cur := l.cur + 1
if w = l.peek(cur); w != "" {
l.cur++
}
return
}
func (l *lexer) skip() {
if cur := l.cur + 1; cur < len(l.words) {
l.cur = cur
} else {
l.cur = len(l.words) - 1
}
}
func (l *lexer) peek(idx int) string {
if idx < len(l.words) {
return l.words[idx]
}
return ""
}
func (l *lexer) peekNext() (w string) {
return l.peek(l.cur + 1)
}
func (l *lexer) peekPrev() (w string) {
if l.cur > 0 {
cur := l.cur - 1
w = l.words[cur]
}
return w
}