-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
155 lines (137 loc) · 3.59 KB
/
main.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
package main
import (
"bufio"
"fmt"
"os"
"strings"
)
func main() {
if len(os.Args) == 2 {
textFromOutside := os.Args[1]
fileLines := ReadStandardTxt()
// fmt.Println(textFromOutside, fileLines)
asciiTemplates := return2dASCIIArray(fileLines)
// fmt.Println(asciiTemplates)
// printMultipleCharacter(textFromOutside, asciiTemplates)
// fmt.Println(int('\n'))
// test1 := "\nHello\nWorld\n\nMom\n\n\nAnd Dad\n"
// fmt.Println(returnstring2EndlineArray(textFromOutside))
printAllStringASCII(textFromOutside, asciiTemplates)
}
}
func ReadStandardTxt() []string {
readFile, err := os.Open("standard.txt")
if err != nil {
fmt.Println(err)
}
fileScanner := bufio.NewScanner(readFile)
fileScanner.Split(bufio.ScanLines)
var fileLines []string
for fileScanner.Scan() {
fileLines = append(fileLines, fileScanner.Text())
}
readFile.Close()
return fileLines
}
func return2dASCIIArray(fileLines []string) [][]string {
var asciiTemplates [][]string
counter := 0
var tempAsciArray []string
for _, line := range fileLines {
counter++
// fmt.Println(index, line)
if counter != 1 {
tempAsciArray = append(tempAsciArray, line)
}
if counter == 9 {
// fmt.Println("add to list") // but dont include the first line because it is empty line
asciiTemplates = append(asciiTemplates, tempAsciArray)
counter = 0
tempAsciArray = nil
} else {
}
}
return asciiTemplates
}
// problem '\n' logic when we have 2 '\n' or 1 '\n' is different
func printMultipleCharacter(s string, asciiTemplates [][]string) {
// for ex 'hello'
// we gonna write all letters index 0 after $ after \n after index 1 after $ after \n
tempIntArrLetter := returnAsciiCodeInt(s)
for i := 0; i < 8; i++ {
for _, v := range tempIntArrLetter {
fmt.Print(asciiTemplates[v][i])
}
fmt.Println("$")
}
}
func returnAsciiCodeInt(s string) []int {
var tempIntArrLetter []int
for _, v := range s {
tempIntArrLetter = append(tempIntArrLetter, (int(v) - 32))
}
return tempIntArrLetter
}
func printAllStringASCII(text string, asciiTemplates [][]string) {
/*
if ends w \n it gonna print println $
if you can see text after \n chec;
before \n
if yes println $
if no println
*/
/*
func to uses printMultipleCharacters print whole stringfrom outside
*/
// Split the input string into an array of strings
// split the line into words if there is a "\r\n" symbol
substrings := returnstring2EndlineArray(text)
lenOfsubstrings := len(substrings)
for index, v := range substrings {
if v == "\\n" {
// If it is last one
if index == lenOfsubstrings-1 {
fmt.Println("$")
} else if index == 0 {
fmt.Println("$") // no idea CHECK IT POTENTIAL ERROR
} else {
if substrings[index-1] == "\\n" {
fmt.Println("$")
} else {
// "Hello\nWorld"
}
}
} else {
printMultipleCharacter(v, asciiTemplates)
}
}
}
func returnstring2EndlineArray(text string) []string {
substrings := make([]string, 0)
escapedN := "\\n"
newline := "\n"
for {
idx := strings.Index(text, escapedN)
if idx == -1 {
substrings = append(substrings, text)
break
}
substrings = append(substrings, text[:idx])
if idx+len(escapedN) < len(text) && text[idx+len(escapedN)] == 'n' {
substrings = append(substrings, newline)
text = text[idx+len(escapedN)+1:]
} else {
substrings = append(substrings, escapedN)
text = text[idx+len(escapedN):]
}
}
// fmt.Printf("%#v\n", substrings)
var mysubstring2 []string
for _, mysub := range substrings {
if mysub != "" {
mysubstring2 = append(mysubstring2, mysub)
}
}
// fmt.Printf("%#v\n", mysubstring2)
return mysubstring2
}