Fix build error

This commit is contained in:
kayomn 2022-12-20 23:22:18 +00:00
parent 8f82318cce
commit a82d80cf7f
1 changed files with 29 additions and 8 deletions

37
ini.go
View File

@ -96,7 +96,7 @@ type Parser struct {
} }
// Attempts to write `entries` to `writer`, returning any error that occured during writing. // Attempts to write `entries` to `writer`, returning any error that occured during writing.
func Write(writer io.Writer, entries []Entry) error { func Write(writer io.StringWriter, entries []Entry) error {
// TODO: Not happy with this solution to writing files, needs more revision. // TODO: Not happy with this solution to writing files, needs more revision.
var section = "" var section = ""
@ -104,16 +104,37 @@ func Write(writer io.Writer, entries []Entry) error {
if entry.Section != section { if entry.Section != section {
section = entry.Section section = entry.Section
writer.Write([]byte{'['}) if _, writeError := writer.WriteString("["); writeError != nil {
writer.Write([]byte(entry.Section)) return writeError
writer.Write([]byte{']', '\n'}) }
if _, writeError := writer.WriteString(entry.Section); writeError != nil {
return writeError
}
if _, writeError := writer.WriteString("]"); writeError != nil {
return writeError
}
} }
writer.Write([]byte(entry.Key)) if _, writeError := writer.WriteString(entry.Key); writeError != nil {
writer.Write([]byte{' ', '=', ' '}) return writeError
writer.Write([]byte(entry.Value)) }
writer.Write([]byte{'\n'})
if _, writeError := writer.WriteString(" = "); writeError != nil {
return writeError
}
if _, writeError := writer.WriteString(entry.Value); writeError != nil {
return writeError
}
if _, writeError := writer.WriteString("\n"); writeError != nil {
return writeError
}
} }
return nil
} }
// Returns a string with the the outer-most quotes surrounding `s` trimmed, should they exist. // Returns a string with the the outer-most quotes surrounding `s` trimmed, should they exist.