-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.go
32 lines (29 loc) · 874 Bytes
/
utils.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
package rotten_tomato
import (
"fmt"
"regexp"
"strings"
)
func GetChunksFromString(startTag string, endTag string, content string) []string {
startTagLength := len(startTag)
endTagLength := len(endTag)
startTagReg := regexp.MustCompile(fmt.Sprintf(`%s(.*?)`, regexp.QuoteMeta(startTag)))
num_snippets := len(startTagReg.FindAllString(content, -1))
chunks := []string{}
j := 0
for i := 0; i < num_snippets; i++ {
rawChunk := content[j : len(content)-1]
start_idx := strings.Index(rawChunk, startTag)
end_idx := strings.Index(rawChunk, endTag)
if start_idx == -1 || end_idx == -1 {
continue
}
chunk := rawChunk[start_idx+startTagLength : end_idx]
chunks = append(chunks, chunk)
j += end_idx + endTagLength
}
return chunks
}
func RemoveSpecialChars(raw string) string {
return regexp.MustCompile(`[^a-zA-Z0-9 ]+`).ReplaceAllString(raw, "")
}