diff --git a/key-value/key-value.go b/key-value/key-value.go index 30ee79e..2d2e4be 100644 --- a/key-value/key-value.go +++ b/key-value/key-value.go @@ -250,6 +250,24 @@ func (entry Entry) Localize (locale locale.Locale) string { return entry.Value } +// Unescape returns a new copy of this entry with its main value parsed and +// unescaped as a string, and its localized values parsed and unescaped as +// localestrings. +func (entry Entry) Unescape () (Entry, error) { + value, err := ParseString(entry.Value) + if err != nil { return Entry { }, err } + localizedValue := Entry { + Value: value, + Localized: make(map[locale.Locale] string), + } + for name, localized := range entry.Localized { + unescaped, err := ParseLocaleString(localized) + if err != nil { return Entry { }, err } + localizedValue.Localized[name] = unescaped + } + return localizedValue, nil +} + // TODO have functions to parse/validate all data types // ParseString parses a value of type string. @@ -269,6 +287,8 @@ func ParseString (value string) (string, error) { // The escape sequences \s, \n, \t, \r, and \\ are supported, meaning ASCII // space, newline, tab, carriage return, and backslash, respectively. func ParseLocaleString (value string) (string, error) { + value, err := escapeString(value) + if err != nil { return "", err } return value, nil }