-
Notifications
You must be signed in to change notification settings - Fork 0
/
punctuation.go
38 lines (35 loc) · 1.1 KB
/
punctuation.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
package reloaded
import (
"strings"
)
func punctuate(words []string) {
chars := ".,!?:;"
for index, word := range words {
for _, punct := range chars {
if len(word) > 0 && strings.HasPrefix(word, string(punct)) && index < len(words)-1 {
words[index-1] += words[index][:1]
words[index] = words[index][1:]
// fmt.Println(words[index])
}
if len(word) > 0 && strings.HasPrefix(word, string(punct)) && strings.HasSuffix(word, string(punct)) && index == len(words)-1 {
// words[index-1] += words[index][:1]
words[index-1] += words[index]
// fmt.Println(words[index])
words = words[:index]
}
if len(word) > 0 && strings.HasPrefix(word, string(punct)) && index < len(words)-1 && strings.HasSuffix(word, string(punct)) {
words[index-1] += words[index]
// fmt.Println(words[ilsndex])
words = append(words[:index], words[index+1:]...)
}
}
}
for index, word := range words {
for _, punct := range chars {
if len(word) > 0 && strings.HasPrefix(word, string(punct)) && index == len(words)-1 {
words[index-1] += words[index]
words = words[:index-5]
}
}
}
}