diff --git a/ini.go b/ini.go index c82374b..e7b0529 100644 --- a/ini.go +++ b/ini.go @@ -64,26 +64,15 @@ func (parser *Parser) Parse() Entry { if assignmentIndex := strings.Index(line, "="); assignmentIndex > -1 { // Key with value. - var value = strings.TrimSpace(line[assignmentIndex+1:]) - var valueLen = len(value) - - if valueLen != 0 { - var valueTail = len(value) - 1 - - if (value[0] == '"') && (value[valueTail] == '"') { - value = value[1:valueTail] - } - } - return Entry{ Section: parser.section, - Key: strings.TrimSpace(line[0:assignmentIndex]), - Value: value, + Key: unquote(strings.TrimSpace(line[0:assignmentIndex])), + Value: unquote(strings.TrimSpace(line[assignmentIndex+1:])), } } // Key which is its own value. - var keyValue = line[1:lineTail] + var keyValue = unquote(line[1:lineTail]) return Entry{ Section: parser.section, @@ -105,3 +94,18 @@ type Parser struct { section string isEnd bool } + +// Returns a string with the the outer-most quotes surrounding `s` trimmed, should they exist. +func unquote(s string) string { + var sLen = len(s) + + if sLen != 0 { + var sTail = sLen - 1 + + if (s[0] == '"') && (s[sTail] == '"') { + return s[1:sTail] + } + } + + return s +}