From e3b2244287665ecf972521ae6385652796101175 Mon Sep 17 00:00:00 2001 From: Sasha Koshka Date: Sat, 27 Apr 2024 19:43:26 -0400 Subject: [PATCH] Key value files are stringable --- key-value/key-value.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/key-value/key-value.go b/key-value/key-value.go index b234ab8..e109a8f 100644 --- a/key-value/key-value.go +++ b/key-value/key-value.go @@ -12,6 +12,7 @@ package keyValue // MISS ME WITH THAT SHIT! import "io" +import "fmt" import "bufio" import "strings" import "strconv" @@ -189,6 +190,23 @@ func isKeyValid (key string) bool { // File represents a key/value file. type File map[string] Group +// String returns a string representation of the file. +func (file File) String () string { + outb := strings.Builder { } + for name, group := range file { + fmt.Fprintf(&outb, "[%s]\n", name) + for key, entry := range group { + fmt.Fprintf(&outb, "%s=%s\n", key, entry.Value) + for loc, localized := range entry.Localized { + fmt.Fprintf(&outb, "%s[%v]=%s\n", key, loc, localized) + } + } + } + out := outb.String() + if len(out) > 0 { out = out[:len(out) - 2] } + return out +} + // Group represents a group of entries. type Group map[string] Entry