Key value files are stringable

This commit is contained in:
Sasha Koshka 2024-04-27 19:43:26 -04:00
parent 0e0fbeaa88
commit e3b2244287
1 changed files with 18 additions and 0 deletions

View File

@ -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