Browse Source

basic: implement Section.String() and Field.String()

to ease development

Signed-off-by: Alejandro Mery <amery@jpi.io>
pull/5/head
Alejandro Mery 1 year ago
parent
commit
16d52188f6
  1. 18
      basic/write.go

18
basic/write.go

@ -45,6 +45,14 @@ func writeFieldsTo(w io.Writer, fields []Field, nl string) (int64, error) {
return int64(written), nil
}
// String generates a string output for "%s"
func (field Field) String() string {
var buf bytes.Buffer
_, _ = writeFieldsTo(&buf, []Field{field}, WriteNewLine)
return buf.String()
}
func writeSectionToBuffer(w *bytes.Buffer, sec *Section, nl string) int {
var written, n int
@ -74,6 +82,14 @@ func writeSectionToBuffer(w *bytes.Buffer, sec *Section, nl string) int {
return written + int(n64)
}
// String generates a string output for "%s"
func (sec *Section) String() string {
var buf bytes.Buffer
_ = writeSectionToBuffer(&buf, sec, WriteNewLine)
return buf.String()
}
// WriteTo writes a INI representation of the document
// onto the provided writer.
func (doc *Document) WriteTo(w io.Writer) (int64, error) {
@ -81,7 +97,7 @@ func (doc *Document) WriteTo(w io.Writer) (int64, error) {
return buf.WriteTo(w)
}
// GoString generates a string output for "%s"
// String generates a string output for "%s"
func (doc *Document) String() string {
buf := doc.AsBuffer(WriteNewLine)
return buf.String()

Loading…
Cancel
Save