浏览代码

Move char matching util function out of tokenize.tossUntilNeitherOf()

In preparation for reuse by next commit.
Alois Mahdal 2 天前
父节点
当前提交
005793cae5
共有 1 个文件被更改,包括 10 次插入9 次删除
  1. 10
    9
      app/tokenize/tokenize.go

+ 10
- 9
app/tokenize/tokenize.go 查看文件

49
 
49
 
50
 func (self *reader) tossUntilNeitherOf(needles string) bool {
50
 func (self *reader) tossUntilNeitherOf(needles string) bool {
51
 	self.checkPos()
51
 	self.checkPos()
52
-	match := func(b byte, ns string) bool {
53
-		for i := range len(ns) {
54
-			if b == ns[i] {
55
-				return true
56
-			}
57
-		}
58
-		return false
59
-	}
60
 	tossed := uint(0)
52
 	tossed := uint(0)
61
 	for {
53
 	for {
62
 		idx := self.pos + tossed
54
 		idx := self.pos + tossed
63
 		if idx == self.len() {
55
 		if idx == self.len() {
64
 			break
56
 			break
65
 		}
57
 		}
66
-		if match(self.data[idx], needles) {
58
+		if hasByte(self.data[idx], needles) {
67
 			tossed += 1
59
 			tossed += 1
68
 			continue
60
 			continue
69
 		}
61
 		}
73
 	return tossed > 0
65
 	return tossed > 0
74
 }
66
 }
75
 
67
 
68
+func hasByte(b byte, ns string) bool {
69
+	for i := range len(ns) {
70
+		if b == ns[i] {
71
+			return true
72
+		}
73
+	}
74
+	return false
75
+}
76
+
76
 func (self *reader) tossChar() {
77
 func (self *reader) tossChar() {
77
 	self.checkPos()
78
 	self.checkPos()
78
 	self.pos += 1
79
 	self.pos += 1