/
classtool.go
171 lines (108 loc) · 2.84 KB
/
classtool.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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
package translate
import (
"strings"
"fmt"
"hiank.net/translate/tool"
)
type ClassTool struct {
_dict *Dict
_focus *FileInfo /// the file's classinfo what is working
_info *FlushInfo
_hide bool // when some line start with "/*", _hide should set to true, and
_fileArr *FileArr
}
func NewClass(root string) *ClassTool {
tool := new(ClassTool)
*tool = ClassTool{
_dict: nil,//NewDict(dictName),
_focus: nil,
_info: nil,
_hide: false,
_fileArr: new(FileArr),
}
// tool._dict.InitDict(dictName)
tool._fileArr.InitArr(root)
fmt.Printf("files len : %v\n", len(tool._fileArr._fileArr))
return tool
}
func (t *ClassTool) InitDictWithPath(path string) {
t._dict = NewDict(path)
}
func (t *ClassTool) InitDictWithDict(dict map[string]*tool.Item) {
t._dict = new(Dict)
t._dict._dictFile = ""
t._dict._dict = dict
}
func (tool *ClassTool) pushLine(line []byte) {
lineStr := strings.TrimSpace(string(line))
switch {
case strings.HasPrefix(lineStr, "/*") || tool._hide:
tool._hide = !strings.HasSuffix(lineStr, "*/")
return
case classB(lineStr):
return
}
formatB := lineStr[strings.Index(lineStr, "\"")+1:]
arrStr := strings.Split(formatB, "\"")
m := tool._focus._dict
idx := 0
for _, str := range arrStr {
if idx % 2 == 0 && strings.IndexFunc(str, unicodeF) != -1 && !classBEx(str) {
item := tool._dict._dict[str]
if item == nil {
tool._dict._dict[str] = nil
} else {
m[str] = item
}
}
idx++
}
}
func (tool *ClassTool) nextFile() *FileInfo {
var name string
fileArr := tool._fileArr
if len(fileArr._fileArr) <= fileArr._fileIdx {
return nil
}
name = fileArr._fileArr[fileArr._fileIdx]
fileArr._fileIdx++
// println("next file " + name)
info := NewFileInfo(tool._info, name)
tool._focus = info
// fmt.Printf("info : %v", tool._focus)
// tool._content = "" ///
return info
}
func (tool *ClassTool) SetFlushInfo(info *FlushInfo) {
tool._info = info
}
func (tool *ClassTool) GetFlushInfo() *FlushInfo {
return tool._info
}
func (tool *ClassTool) flush() {
// tool._focus.save(func(content string, info *FileInfo) string {
// for key, value := range info._dict {
// key = "\"" + key + "\""
// content = strings.Replace(content, key, "L(" + strconv.Itoa(value.Key) + ")/*" + key + "*/", -1)
// }
// return content
// })
tool._focus.save(func(lineStr string, info *FileInfo) string {
key := strings.Trim(lineStr, " ")
key = strings.Trim(key, "\t")
if strings.HasPrefix(key, "<value>") {
item := tool._dict._dict[key]
if item == nil {
fmt.Printf("++++no value #%v#\n", key)
} else {
lineStr = strings.Replace(lineStr, key, item.Value, -1)
fmt.Printf(">>>>>>>>>#%v#\n", item)
}
}
fmt.Println("....<<<<" + lineStr)
return lineStr
})
}
func (tool *ClassTool) Flush() {
tool._dict.Flush()
}