package main
import (
+ "strconv"
"unicode/utf8"
)
return (c >= '0' && c <= '9') || (c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || (c == '_')
}
+// IsWhitespace returns true if the given rune is a space, tab, or newline
+func IsWhitespace(c rune) bool {
+ return c == ' ' || c == '\t' || c == '\n'
+}
+
// Contains returns whether or not a string array contains a given string
func Contains(list []string, a string) bool {
for _, b := range list {
func Insert(str string, pos int, value string) string {
return string([]rune(str)[:pos]) + value + string([]rune(str)[pos:])
}
+
+// GetLeadingWhitespace returns the leading whitespace of the given string
+func GetLeadingWhitespace(str string) string {
+ ws := ""
+ for _, c := range str {
+ if c == ' ' || c == '\t' {
+ ws += string(c)
+ } else {
+ break
+ }
+ }
+ return ws
+}
+
+// IsSpaces checks if a given string is only spaces
+func IsSpaces(str string) bool {
+ for _, c := range str {
+ if c != ' ' {
+ return false
+ }
+ }
+
+ return true
+}
+
+// ParseBool is almost exactly like strconv.ParseBool, except it also accepts 'on' and 'off'
+// as 'true' and 'false' respectively
+func ParseBool(str string) (bool, error) {
+ if str == "on" {
+ return true, nil
+ }
+ if str == "off" {
+ return false, nil
+ }
+ return strconv.ParseBool(str)
+}