-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathparser.go
53 lines (50 loc) · 1.7 KB
/
parser.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
package main
import (
"fmt"
"strconv"
"strings"
)
func getUnicodeValueSlice(arg string) ([]string, error) {
var returnSlice []string
// strip the case insensitive 'x' value from exclude request arguments (detected in calling code)
if strings.HasPrefix(arg, "x") || strings.HasPrefix(arg, "X") {
arg = arg[1:]
}
if strings.Contains(arg, "-") {
tempUniList := strings.Split(arg, "-")
if len(tempUniList[0]) < 4 {
// handle argument that is not formatted as unicode hexadecimal value
lenErr := fmt.Errorf("the argment '%s' is not properly formatted as a Unicode hexadecimal value", tempUniList[0])
return returnSlice, lenErr
}
if len(tempUniList[1]) < 4 {
// handle argument that is not formatted as unicode hexadecimal value
lenErr := fmt.Errorf("the argment '%s' is not properly formatted as a Unicode hexadecimal value", tempUniList[1])
return returnSlice, lenErr
}
startInt, startParseErr := strconv.ParseInt(tempUniList[0], 16, 32)
endInt, endParseErr := strconv.ParseInt(tempUniList[1], 16, 32)
if startParseErr != nil {
return returnSlice, startParseErr
}
if endParseErr != nil {
return returnSlice, endParseErr
}
for i := startInt; i <= endInt; i++ {
returnSlice = append(returnSlice, fmt.Sprintf("%U", i))
}
} else {
if len(arg) > 3 {
anInt, parseErr := strconv.ParseInt(arg, 16, 32)
if parseErr != nil {
return returnSlice, parseErr
}
returnSlice = append(returnSlice, fmt.Sprintf("%U", anInt))
} else {
// handle argument that is not formatted as unicode hexadecimal value
lenErr := fmt.Errorf("the argment '%s' is not properly formatted as a Unicode hexadecimal value", arg)
return returnSlice, lenErr
}
}
return returnSlice, nil
}