README | 4 ++++ r.go | 4 +++- w.go | 10 +++++++--- diff --git a/README b/README index 08b01d4cc032270e4c6da77a4914ed5a8ad0b940f75dfe23ae21fc9bb80f94c6..9197bf147fa9556e0334b1982299c9e53aaeefd0ef070c6583270732ec12d9de 100644 --- a/README +++ b/README @@ -7,4 +7,8 @@ * iterate through the records and their fields * 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. diff --git a/r.go b/r.go index 03fb50ecbf893ccdcec393b81948db2ba4dc0007bac1800c96adcb5b00e695eb..bd079e22e81aa7cc30147a600362b8d372b96c800fab876905e6bb8d43cfdb0c 100644 --- a/r.go +++ b/r.go @@ -80,7 +80,9 @@ } 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) diff --git a/w.go b/w.go index b265dda7a875c0b6e5aee3287cae56acbf4586df372d88bde5759d04f3b0efd3..0f4b84203d3d7b13dba930651e85c77edbad427ab7dff54eb0bcbb0127df4a0c 100644 --- a/w.go +++ b/w.go @@ -37,7 +37,9 @@ 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 @@ -48,13 +50,15 @@ } 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