Browse Source

final - apostrophes detections works #02

master
kauri 3 years ago
parent
commit
7b843c5353
  1. 36
      main.go

36
main.go

@ -41,7 +41,7 @@ func main() {
output_text = FixApostrophes(output_text) // apostrophes being checked
fmt.Println(string(output_text))
// fmt.Println(string(output_text))
os.WriteFile(string(os.Args[2]), []byte(string(output_text)), os.ModePerm)
}
@ -84,36 +84,48 @@ func FixApostrophes(text string) string {
for i, letter := range runes {
if letter == mark2 {
// fmt.Println("mark2 detected")
if i > 0 && i < len(runes)-1 && runes[i-1] != 32 && runes[i+1] != 32 {
fmt.Println("check: mark 2 detected")
// fmt.Println("check: mark 2 in text")
continue
}
}
if letter == mark1 {
if letter == mark1 { // separate if for troubleshooting only; will be joined with previous if
// fmt.Println("mark1 detected")
if i > 0 && i < len(runes)-1 && runes[i-1] != 32 && runes[i+1] != 32 {
fmt.Println("check: mark 1 detected ")
// fmt.Println("check: mark 1 in text")
continue
}
}
// runes = append(runes[:i], runes[i+2:]...)
// runes = append(runes[:i-1], runes[i:]...)
if letter == mark1 || letter == mark2 {
if pair_count {
if i < (len(runes)-2) && runes[i+1] == 32 { // somewhy will not enter into this if
// text = text[:i] + "‘" + text[i+2:]
runes = append(runes[:i], runes[i+2:]...)
if i < len(runes)-2 && runes[i+1] == rune(32) {
runes = append(runes[:i], runes[i+2:]...) // suspected reason for malfunction
pair_count = false
// fmt.Println("first_...")
continue
} else {
pair_count = false
// fmt.Println("first...")
continue
}
}
if !pair_count {
if (i > 1) && runes[i-1] == 32 {
// text = text[:i-1] + "’" + text[i+1:]
runes = append(runes[:i-1], runes[i:]...)
if i > 1 && runes[i-1] == rune(32) {
runes = append(runes[:i-1], runes[i:]...) // suspected reason for malfunction
pair_count = true
// a = append(a[:i], append([]T{x}, a[i:]...)...) --to insert
// fmt.Println("..._second")
continue
} else {
pair_count = true
// fmt.Println("...second")
continue
}
}
}

Loading…
Cancel
Save