* ignore comments
* support continuation lines (\$) and multilines (^+)
+Limitations:
+* leading spaces in the first line of the value are ignored
+* trailing backslash at the end of lines is cut
+
It is free software: see the file COPYING for copying conditions.
text = r.scanner.Text()
if continuation {
- if text[len(text)-1] == '\\' {
+ if len(text) == 0 {
+ continuation = false
+ } else if text[len(text)-1] == '\\' {
lines = append(lines, text[:len(text)-1])
} else {
lines = append(lines, text)
func (w *Writer) WriteFields(fs ...Field) (written int, err error) {
var n int
for _, f := range fs {
- n, err = w.w.WriteString(f.Name + ": " + strings.TrimLeft(f.Value, " ") + "\n")
+ n, err = w.w.WriteString(
+ f.Name + ": " + strings.TrimRight(strings.TrimLeft(f.Value, " "), "\\") + "\n",
+ )
written += n
if err != nil {
return
func (w *Writer) WriteFieldMultiline(name string, lines []string) (written int, err error) {
var n int
- n, err = w.w.WriteString(name + ": " + strings.TrimLeft(lines[0], " ") + "\n")
+ n, err = w.w.WriteString(
+ name + ": " + strings.TrimRight(strings.TrimLeft(lines[0], " "), "\\") + "\n",
+ )
written += n
if err != nil {
return
}
for _, l := range lines[1:] {
- n, err = w.w.WriteString("+ " + l + "\n")
+ n, err = w.w.WriteString("+ " + strings.TrimRight(l, "\\") + "\n")
written += n
if err != nil {
return