option-type #23
@@ -97,6 +97,32 @@ func (sn Snake) String() string {
|
|||||||
return out.String()
|
return out.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (sn Snake) CharsString() string {
|
||||||
|
if len(sn) == 0 || len(sn[0]) == 0 || len(sn[0][0]) == 0 {
|
||||||
|
return "EMPTY"
|
||||||
|
}
|
||||||
|
|
||||||
|
out := strings.Builder { }
|
||||||
|
for index, sector := range sn {
|
||||||
|
if index > 0 { out.WriteString(" : ") }
|
||||||
|
out.WriteRune('[')
|
||||||
|
for index, variation := range sector {
|
||||||
|
if index > 0 { out.WriteString(" / ") }
|
||||||
|
for _, byt := range variation {
|
||||||
|
run := rune(byt)
|
||||||
|
if unicode.IsPrint(run) && run < 0x7F {
|
||||||
|
out.WriteRune(run)
|
||||||
|
} else {
|
||||||
|
out.WriteRune('.')
|
||||||
|
}
|
||||||
|
out.WriteRune(' ')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
out.WriteRune(']')
|
||||||
|
}
|
||||||
|
return out.String()
|
||||||
|
}
|
||||||
|
|
||||||
// HexBytes formats bytes into a hexadecimal string.
|
// HexBytes formats bytes into a hexadecimal string.
|
||||||
func HexBytes(data []byte) string {
|
func HexBytes(data []byte) string {
|
||||||
if len(data) == 0 { return "EMPTY" }
|
if len(data) == 0 { return "EMPTY" }
|
||||||
@@ -107,6 +133,24 @@ func HexBytes(data []byte) string {
|
|||||||
return out.String()
|
return out.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// HexChars returns all printable bytes in the string, with non-printable ones
|
||||||
|
// replaced with a dot. Each character has an extra space after it for placing
|
||||||
|
// underneath the result of HexBytes.
|
||||||
|
func HexChars(data []byte) string {
|
||||||
|
if len(data) == 0 { return "EMPTY" }
|
||||||
|
out := strings.Builder { }
|
||||||
|
for _, byt := range data {
|
||||||
|
run := rune(byt)
|
||||||
|
if unicode.IsPrint(run) && run < 0x7F {
|
||||||
|
out.WriteRune(run)
|
||||||
|
} else {
|
||||||
|
out.WriteRune('.')
|
||||||
|
}
|
||||||
|
out.WriteRune(' ')
|
||||||
|
}
|
||||||
|
return out.String()
|
||||||
|
}
|
||||||
|
|
||||||
// Describe returns a string representing the type and data of the given value.
|
// Describe returns a string representing the type and data of the given value.
|
||||||
func Describe(value any) string {
|
func Describe(value any) string {
|
||||||
desc := describer { }
|
desc := describer { }
|
||||||
|
|||||||
Reference in New Issue
Block a user