-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHelper.go
43 lines (35 loc) · 838 Bytes
/
Helper.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
package util
import (
"errors"
"fmt"
"regexp"
)
var (
ptnLetter = regexp.MustCompile("^[a-zA-Z]$")
ptnNumber = regexp.MustCompile("^[0-9]$")
ptnLiteral = regexp.MustCompile("^[_a-zA-Z0-9]$")
ptnOperator = regexp.MustCompile("^[*+\\-<>=!&|^%/,]$")
)
func IsLetter(s string) bool {
return ptnLetter.MatchString(s)
}
func IsNumber(s string) bool {
return ptnNumber.MatchString(s)
}
func IsLiteral(s string) bool {
return ptnLiteral.MatchString(s)
}
func IsOperator(s string) bool {
return ptnOperator.MatchString(s)
}
func ErrWithArgs(format string, args ...string) error {
errMsg := fmt.Sprintf(format, args)
return errors.New(errMsg)
}
func MapToString(elements []interface{}) []string {
var results []string
for _, element := range elements {
results = append(results, element.(string))
}
return results
}