new type LinkedList, preliminary implementation
This commit is contained in:
+16
-1
@@ -4,7 +4,10 @@
|
||||
// formatter.go
|
||||
package kern
|
||||
|
||||
import "fmt"
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type FmtOpt uint32 // lower 16 bits hold a bit-mask, higher 16 bits hold an indentation number
|
||||
|
||||
@@ -46,6 +49,18 @@ type Formatter interface {
|
||||
ToString(options FmtOpt) string
|
||||
}
|
||||
|
||||
func Format(sb *strings.Builder, item any, opt FmtOpt) {
|
||||
if s, ok := item.(string); ok {
|
||||
sb.WriteByte('"')
|
||||
sb.WriteString(s)
|
||||
sb.WriteByte('"')
|
||||
} else if formatter, ok := item.(Formatter); ok {
|
||||
sb.WriteString(formatter.ToString(opt))
|
||||
} else {
|
||||
fmt.Fprintf(sb, "%v", item)
|
||||
}
|
||||
}
|
||||
|
||||
func GetFormatted(v any, opt FmtOpt) (text string) {
|
||||
if v == nil {
|
||||
text = "(nil)"
|
||||
|
||||
Reference in New Issue
Block a user