From 7b843c5353838575eafb688d7842e111b6d32c0e Mon Sep 17 00:00:00 2001 From: kauri Date: Sat, 18 Sep 2021 18:44:15 +0300 Subject: [PATCH] final - apostrophes detections works #02 --- main.go | 36 ++++++++++++++++++++++++------------ 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/main.go b/main.go index dc21881..f81efb6 100644 --- a/main.go +++ b/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 } } }