-
Notifications
You must be signed in to change notification settings - Fork 1
/
loop.go
74 lines (56 loc) · 1.37 KB
/
loop.go
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package emailforwardparser
import (
regexp "github.com/wasilibs/go-re2"
)
func _LoopRegexesReplace(regexes []*regexp.Regexp, str string) string {
match := str
for _, re := range regexes {
currentMatch := re.ReplaceAllString(str, "")
if len(currentMatch) < len(match) {
match = currentMatch
break
}
}
return match
}
func _LoopRegexesSplit(regexes []*regexp.Regexp, str string, highestPosition bool) []string {
var match []string
for _, re := range regexes {
currentMatch := splitWithRegexp(re, str)
if len(currentMatch) > 1 {
if highestPosition {
if match == nil || len(match[0]) > len(currentMatch[0]) {
match = currentMatch
}
} else {
match = currentMatch
break
}
}
}
return match
}
func _LoopRegexesMatch(regexes []*regexp.Regexp, str string, highestPosition bool) ([]string, *regexp.Regexp) {
var match []string
var regex *regexp.Regexp
matchIndex := 0
for _, re := range regexes {
currentMatch := re.FindStringSubmatch(str)
if currentMatch != nil {
currentMatchIndex := re.FindStringIndex(str)[0]
if highestPosition {
if match == nil || matchIndex > currentMatchIndex {
match = currentMatch
matchIndex = currentMatchIndex
regex = re
}
} else {
match = currentMatch
matchIndex = currentMatchIndex // why the warn?
regex = re
break
}
}
}
return match, regex
}