mirror of
https://github.com/yunionio/cloudpods.git
synced 2026-07-03 05:04:22 +08:00
37 lines
602 B
Go
37 lines
602 B
Go
package terminalparser
|
|
|
|
import (
|
|
"bytes"
|
|
"fmt"
|
|
"strings"
|
|
"unicode"
|
|
"unicode/utf8"
|
|
)
|
|
|
|
func DebugString(p string) string {
|
|
var s strings.Builder
|
|
for _, v := range []rune(p) {
|
|
if unicode.IsPrint(v) {
|
|
s.WriteRune(v)
|
|
} else {
|
|
s.WriteString(fmt.Sprintf("%q", v))
|
|
}
|
|
}
|
|
return s.String()
|
|
}
|
|
|
|
func IsAlphabetic(r rune) bool {
|
|
index := bytes.IndexRune([]byte(string(Alphabetic)), r)
|
|
if index < 0 {
|
|
return false
|
|
}
|
|
return true
|
|
}
|
|
|
|
func ReadRunePacket(p []byte) (code rune, rest []byte) {
|
|
r, l := utf8.DecodeRune(p)
|
|
if r == utf8.RuneError {
|
|
return utf8.RuneError, p
|
|
}
|
|
return r, p[l:]
|
|
} |