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 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) 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 { for i, letter := range runes {
if letter == mark2 { if letter == mark2 {
// fmt.Println("mark2 detected")
if i > 0 && i < len(runes)-1 && runes[i-1] != 32 && runes[i+1] != 32 { 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 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 { 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 continue
} }
} }
// runes = append(runes[:i], runes[i+2:]...)
// runes = append(runes[:i-1], runes[i:]...)
if letter == mark1 || letter == mark2 { if letter == mark1 || letter == mark2 {
if pair_count { if pair_count {
if i < (len(runes)-2) && runes[i+1] == 32 { // somewhy will not enter into this if if i < len(runes)-2 && runes[i+1] == rune(32) {
// text = text[:i] + "‘" + text[i+2:] runes = append(runes[:i], runes[i+2:]...) // suspected reason for malfunction
runes = append(runes[:i], runes[i+2:]...)
pair_count = false pair_count = false
// fmt.Println("first_...")
continue
} else {
pair_count = false
// fmt.Println("first...")
continue continue
} }
} }
if !pair_count { if !pair_count {
if (i > 1) && runes[i-1] == 32 { if i > 1 && runes[i-1] == rune(32) {
// text = text[:i-1] + "’" + text[i+1:] runes = append(runes[:i-1], runes[i:]...) // suspected reason for malfunction
runes = append(runes[:i-1], runes[i:]...)
pair_count = true pair_count = true
// fmt.Println("..._second")
// a = append(a[:i], append([]T{x}, a[i:]...)...) --to insert continue
} else {
pair_count = true
// fmt.Println("...second")
continue
} }
} }
} }

Loading…
Cancel
Save