MCPcopy Index your code
hub / github.com/g3n/engine / parse

Function parse

tools/g3nicodes/main.go:103–138  ·  view source on GitHub ↗
(fin io.Reader, td *templateData)

Source from the content-addressed store, hash-verified

101}
102
103func parse(fin io.Reader, td *templateData) error {
104
105 // Read words from input reader and builds words map
106 scanner := bufio.NewScanner(fin)
107 for scanner.Scan() {
108 // Read next line
109 line := scanner.Text()
110 if err := scanner.Err(); err != nil {
111 return err
112 }
113 // Remove line terminator, spaces and ignore empty lines
114 line = strings.Trim(line, "\n ")
115 if len(line) == 0 {
116 continue
117 }
118
119 parts := strings.Split(line, " ")
120 if len(parts) != 2 {
121 continue
122 }
123 name := parts[0]
124 code := parts[1]
125 nameParts := strings.Split(name, "_")
126 for i := 0; i < len(nameParts); i++ {
127 nameParts[i] = strings.Title(nameParts[i])
128 }
129 finalName := strings.Join(nameParts, "")
130 // If name starts with number adds prefix
131 runes := []rune(finalName)
132 if unicode.IsDigit(runes[0]) {
133 finalName = "N" + finalName
134 }
135 td.Consts = append(td.Consts, constInfo{Name: finalName, Value: "0x" + code})
136 }
137 return nil
138}
139
140// Shows application usage
141func usage() {

Callers 1

mainFunction · 0.85

Calls 2

SplitMethod · 0.80
TextMethod · 0.45

Tested by

no test coverage detected