mirror of
https://github.com/tendermint/tendermint.git
synced 2026-07-28 02:52:48 +00:00
spec: merge spec repo into tendermint repo (#7804)
This commit is contained in:
+6
-48
@@ -28,54 +28,12 @@ func SplitAndTrimEmpty(s, sep, cutset string) []string {
|
||||
return nonEmptyStrings
|
||||
}
|
||||
|
||||
// StringInSlice returns true if a is found the list.
|
||||
func StringInSlice(a string, list []string) bool {
|
||||
for _, b := range list {
|
||||
if b == a {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// SplitAndTrim slices s into all subslices separated by sep and returns a
|
||||
// slice of the string s with all leading and trailing Unicode code points
|
||||
// contained in cutset removed. If sep is empty, SplitAndTrim splits after each
|
||||
// UTF-8 sequence. First part is equivalent to strings.SplitN with a count of
|
||||
// -1.
|
||||
func SplitAndTrim(s, sep, cutset string) []string {
|
||||
if s == "" {
|
||||
return []string{}
|
||||
}
|
||||
|
||||
spl := strings.Split(s, sep)
|
||||
for i := 0; i < len(spl); i++ {
|
||||
spl[i] = strings.Trim(spl[i], cutset)
|
||||
}
|
||||
return spl
|
||||
}
|
||||
|
||||
// TrimSpace removes all leading and trailing whitespace from the
|
||||
// string.
|
||||
func TrimSpace(s string) string { return strings.TrimSpace(s) }
|
||||
|
||||
// Returns true if s is a non-empty printable non-tab ascii character.
|
||||
func IsASCIIText(s string) bool {
|
||||
// ASCIITrim removes spaces from an a ASCII string, erroring if the
|
||||
// sequence is not an ASCII string.
|
||||
func ASCIITrim(s string) (string, error) {
|
||||
if len(s) == 0 {
|
||||
return false
|
||||
return "", nil
|
||||
}
|
||||
for _, b := range []byte(s) {
|
||||
if 32 <= b && b <= 126 {
|
||||
// good
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
// NOTE: Assumes that s is ASCII as per IsASCIIText(), otherwise panics.
|
||||
func ASCIITrim(s string) string {
|
||||
r := make([]byte, 0, len(s))
|
||||
for _, b := range []byte(s) {
|
||||
switch {
|
||||
@@ -84,10 +42,10 @@ func ASCIITrim(s string) string {
|
||||
case 32 < b && b <= 126:
|
||||
r = append(r, b)
|
||||
default:
|
||||
panic(fmt.Sprintf("non-ASCII (non-tab) char 0x%X", b))
|
||||
return "", fmt.Errorf("non-ASCII (non-tab) char 0x%X", b)
|
||||
}
|
||||
}
|
||||
return string(r)
|
||||
return string(r), nil
|
||||
}
|
||||
|
||||
// StringSliceEqual checks if string slices a and b are equal
|
||||
|
||||
Reference in New Issue
Block a user