~ubuntu-branches/ubuntu/utopic/golang/utopic

« back to all changes in this revision

Viewing changes to src/pkg/encoding/csv/writer.go

  • Committer: Package Import Robot
  • Author(s): James Page
  • Date: 2013-08-20 14:06:23 UTC
  • mfrom: (14.1.23 saucy-proposed)
  • Revision ID: package-import@ubuntu.com-20130820140623-b414jfxi3m0qkmrq
Tags: 2:1.1.2-2ubuntu1
* Merge from Debian unstable (LP: #1211749, #1202027). Remaining changes:
  - 016-armhf-elf-header.patch: Use correct ELF header for armhf binaries.
  - d/control,control.cross: Update Breaks/Replaces for Ubuntu
    versions to ensure smooth upgrades, regenerate control file.

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
//
23
23
// If UseCRLF is true, the Writer ends each record with \r\n instead of \n.
24
24
type Writer struct {
25
 
        Comma   rune // Field delimiter (set to to ',' by NewWriter)
 
25
        Comma   rune // Field delimiter (set to ',' by NewWriter)
26
26
        UseCRLF bool // True to use \r\n as the line terminator
27
27
        w       *bufio.Writer
28
28
}
92
92
}
93
93
 
94
94
// Flush writes any buffered data to the underlying io.Writer.
 
95
// To check if an error occurred during the Flush, call Error.
95
96
func (w *Writer) Flush() {
96
97
        w.w.Flush()
97
98
}
98
99
 
 
100
// Error reports any error that has occurred during a previous Write or Flush.
 
101
func (w *Writer) Error() error {
 
102
        _, err := w.w.Write(nil)
 
103
        return err
 
104
}
 
105
 
99
106
// WriteAll writes multiple CSV records to w using Write and then calls Flush.
100
107
func (w *Writer) WriteAll(records [][]string) (err error) {
101
108
        for _, record := range records {
102
109
                err = w.Write(record)
103
110
                if err != nil {
104
 
                        break
 
111
                        return err
105
112
                }
106
113
        }
107
 
        w.Flush()
108
 
        return nil
 
114
        return w.w.Flush()
109
115
}
110
116
 
111
117
// fieldNeedsQuotes returns true if our field must be enclosed in quotes.