@@ -88,43 +88,39 @@ func main() {
88
88
if isGlyphSearch {
89
89
stdinList := strings .Split (tmp .String (), ` ` )
90
90
for _ , arg := range stdinList {
91
- i , err := strconv . ParseInt (arg , 16 , 32 )
91
+ stdoutString , err := glyphSearch (arg )
92
92
if err != nil {
93
- os .Stderr .WriteString ("[Error] Unable to parse the Unicode code point value '" + arg + "'\n " )
93
+ errmsg := fmt .Sprintf ("%v" , err )
94
+ os .Stderr .WriteString ("[Error] Unable to parse the Unicode code point request '" + arg + "' to a glyph. " + errmsg + "\n " )
94
95
os .Exit (1 )
95
96
}
96
- // TODO: add check for printable glyph range integer value
97
- r := rune (i )
98
- stdoutString := "U+" + arg + " '" + string (r ) + "'"
99
97
fmt .Println (stdoutString )
100
98
}
101
99
102
100
} else { // stdin stream search for Unicode code point from glyph search request
103
101
stdinList := strings .Split (tmp .String (), "" ) // split the stdin string by glyph to a slice
104
- stdOutput := unicodeSearch (stdinList )
105
- for _ , line := range stdOutput {
106
- fmt .Println (line )
102
+ stdOutputList := unicodeSearch (stdinList )
103
+ for _ , stdoutString := range stdOutputList {
104
+ fmt .Println (stdoutString )
107
105
}
108
106
}
109
107
110
108
} else {
111
109
// argument search for glyph from Unicode code point search request
112
110
if isGlyphSearch {
113
111
for _ , arg := range os .Args [2 :] {
114
- i , err := strconv . ParseInt (arg , 16 , 32 )
112
+ stdoutString , err := glyphSearch (arg )
115
113
if err != nil {
116
- os .Stderr .WriteString ("[Error] Unable to parse the Unicode code point value '" + arg + "'\n " )
114
+ errmsg := fmt .Sprintf ("%v" , err )
115
+ os .Stderr .WriteString ("[Error] Unable to parse the Unicode code point request '" + arg + "' to a glyph. " + errmsg + "\n " )
117
116
os .Exit (1 )
118
117
}
119
- // TODO: add check for printable glyph range integer value
120
- r := rune (i )
121
- stdoutString := "U+" + arg + " '" + string (r ) + "'"
122
118
fmt .Println (stdoutString )
123
119
}
124
- } else { // argument search for Unicode code point from glyph search request
125
- stdOutput := unicodeSearch (os .Args [1 :])
126
- for _ , line := range stdOutput {
127
- fmt .Println (line )
120
+ } else { // argument search for Unicode code point from glyph search request
121
+ stdOutputList := unicodeSearch (os .Args [1 :])
122
+ for _ , stdoutString := range stdOutputList {
123
+ fmt .Println (stdoutString )
128
124
}
129
125
}
130
126
@@ -148,12 +144,45 @@ func stdinValidates(stdin *os.File) bool {
148
144
}
149
145
150
146
func handleStdInErrors () {
151
- os .Stderr .WriteString ("[Error] Please include at least one argument or pipe a string to the executable through the stdin stream.\n " )
147
+ os .Stderr .WriteString ("[Error] Please include at least one argument or pipe search requests to the executable through the stdin stream.\n " )
152
148
os .Stderr .WriteString (usage )
153
149
os .Exit (1 )
154
150
}
155
151
156
- // unicodeSearch decodes runs in command line requests to formatted Unicode code point values for stdout stream print
152
+ func isIntInRange (value int32 ) bool {
153
+ minPrintableInt , _ := strconv .ParseInt ("0020" , 16 , 32 )
154
+
155
+ if value > utf8 .MaxRune {
156
+ // value is higher than maximum acceptable Unicode code point
157
+ return false
158
+ }
159
+
160
+ if value < int32 (minPrintableInt ) {
161
+ // value is lower than minimum Unicode code point for printable glyphs
162
+ return false
163
+ }
164
+ // return true if integer value falls within acceptable range
165
+ return true
166
+ }
167
+
168
+ // glyphSearch identifies glyphs for Unicode code point (hexadecimal string) search requests
169
+ func glyphSearch (arg string ) (string , error ) {
170
+ i , err := strconv .ParseInt (arg , 16 , 32 )
171
+ if err != nil {
172
+ return "" , err
173
+ }
174
+ // test to confirm that Unicode code point falls in range U+0020 = min printable glyph to utf8.MaxRune value
175
+ ok := isIntInRange (int32 (i ))
176
+ if ! ok {
177
+ errmsg := fmt .Errorf ("Hexadecimal value '" + arg + "' was out of range." )
178
+ return "" , errmsg
179
+ }
180
+ r := rune (i )
181
+ stdoutString := "U+" + arg + " '" + string (r ) + "'"
182
+ return stdoutString , nil
183
+ }
184
+
185
+ // unicodeSearch identifies the Unicode code point for glyph search requests
157
186
func unicodeSearch (argv []string ) []string {
158
187
var solist []string
159
188
for i := 0 ; i < len (argv ); i ++ {
0 commit comments