From ff1619b4a054b2ae53499a047192a598dc9c0306 Mon Sep 17 00:00:00 2001 From: Chaliy Roman Date: Fri, 6 Sep 2019 15:47:11 +0700 Subject: [PATCH] customization output delimiter --- file.go | 7 +++++-- ini.go | 2 ++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/file.go b/file.go index 017b77c..4a46ef7 100644 --- a/file.go +++ b/file.go @@ -48,6 +48,9 @@ func newFile(dataSources []dataSource, opts LoadOptions) *File { if len(opts.KeyValueDelimiters) == 0 { opts.KeyValueDelimiters = "=:" } + if len(opts.KeyValueDelimitersOutput) == 0 { + opts.KeyValueDelimitersOutput = "" + } return &File{ BlockMode: true, dataSources: dataSources, @@ -230,10 +233,10 @@ func (f *File) Append(source interface{}, others ...interface{}) error { } func (f *File) writeToBuffer(indent string) (*bytes.Buffer, error) { - equalSign := DefaultFormatLeft + "=" + DefaultFormatRight + equalSign := DefaultFormatLeft + f.options.KeyValueDelimitersOutput + DefaultFormatRight if PrettyFormat || PrettyEqual { - equalSign = " = " + equalSign = fmt.Sprintf(" %s ", f.options.KeyValueDelimitersOutput) } // Use buffer to make sure target is safe until finish encoding. diff --git a/ini.go b/ini.go index 420f3db..ba69c8f 100644 --- a/ini.go +++ b/ini.go @@ -109,6 +109,8 @@ type LoadOptions struct { UnparseableSections []string // KeyValueDelimiters is the sequence of delimiters that are used to separate key and value. By default, it is "=:". KeyValueDelimiters string + // KeyValueDelimiters is the delimiter that are used to separate key and value output. By default, it is "=". + KeyValueDelimitersOutput string // PreserveSurroundedQuote indicates whether to preserve surrounded quote (single and double quotes). PreserveSurroundedQuote bool }