瀏覽代碼

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,21 +49,13 @@ func (self *reader) takeUntil(needle string) (string, bool) {
49 49
 
50 50
 func (self *reader) tossUntilNeitherOf(needles string) bool {
51 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 52
 	tossed := uint(0)
61 53
 	for {
62 54
 		idx := self.pos + tossed
63 55
 		if idx == self.len() {
64 56
 			break
65 57
 		}
66
-		if match(self.data[idx], needles) {
58
+		if hasByte(self.data[idx], needles) {
67 59
 			tossed += 1
68 60
 			continue
69 61
 		}
@@ -73,6 +65,15 @@ func (self *reader) tossUntilNeitherOf(needles string) bool {
73 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 77
 func (self *reader) tossChar() {
77 78
 	self.checkPos()
78 79
 	self.pos += 1