-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtools.go
69 lines (53 loc) · 1.2 KB
/
tools.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
package main
import (
"bufio"
"fmt"
"os"
"strings"
)
var tools map[Tool]string = map[Tool]string{
makeTool("вода", "вода"): "море",
}
// Parser return slice of strings
func Parser(str string) (res [3]string) {
var curRes string
space := " "
for _, val := range str {
val := string(val)
if val != space && val != "=" && val != "+" {
curRes += string(val)
} else if val == space {
continue
} else if val == "=" {
curRes = strings.ToLower(curRes)
res[0] = curRes
curRes = ""
} else if val == "+" {
curRes = strings.ToLower(curRes)
res[1] = curRes
curRes = ""
}
}
res[2] = strings.ToLower(curRes)
return
}
// AppendToTools adds formula to tools
func AppendToTools(formula string) {
var res, tool1, tool2 string
tmp := Parser(formula)
res, tool1, tool2 = tmp[0], tmp[1], tmp[2]
tools[makeTool(tool1, tool2)] = res
}
// AddFormulas adds every formulas to map
func AddFormulas() error {
file, err := os.Open("formulas.txt")
if err != nil {
return fmt.Errorf("problems with opening file in AddFormulas %v", err)
}
scanner := bufio.NewScanner(file)
for scanner.Scan() {
formula := string(scanner.Text())
AppendToTools(formula)
}
return nil
}