Start trying to do comments/quoting properly.

This commit is contained in:
John Barton (joho)
2013-07-31 11:48:10 +10:00
parent b3b488372f
commit a37b438d54
2 changed files with 43 additions and 35 deletions

View File

@ -76,8 +76,25 @@ func parseLine(line string) (key string, value string, err error) {
}
key = strings.Trim(key, " ")
value = strings.Trim(splitString[1], " \"'")
value = strings.Replace(value, "\\\"", "\"", -1)
value = splitString[1]
// ditch the comments
if strings.Contains(value, "#") {
value = strings.Trim(strings.Split(value, "#")[0], " ")
}
// check if we've got quoted values
if strings.Count(value, "\"") == 2 || strings.Count(value, "'") == 2 {
// pull the quotes off the edge
value = strings.Trim(value, "\"'")
// expand quotes
value = strings.Replace(value, "\\\"", "\"", -1)
// expand newlines
value = strings.Replace(value, "\\n", "\n", -1)
}
// trim
value = strings.Trim(value, " ")
return
}