summaryrefslogtreecommitdiffstats
path: root/vendor/github.com/magiconair/properties/properties.go
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/magiconair/properties/properties.go')
-rw-r--r--vendor/github.com/magiconair/properties/properties.go31
1 files changed, 26 insertions, 5 deletions
diff --git a/vendor/github.com/magiconair/properties/properties.go b/vendor/github.com/magiconair/properties/properties.go
index cb3d1a33..1529e722 100644
--- a/vendor/github.com/magiconair/properties/properties.go
+++ b/vendor/github.com/magiconair/properties/properties.go
@@ -8,11 +8,13 @@ package properties
// BUG(frank): Write() does not allow to configure the newline character. Therefore, on Windows LF is used.
import (
+ "bytes"
"fmt"
"io"
"log"
"os"
"regexp"
+ "sort"
"strconv"
"strings"
"time"
@@ -69,6 +71,9 @@ type Properties struct {
// Stores the keys in order of appearance.
k []string
+
+ // WriteSeparator specifies the separator of key and value while writing the properties.
+ WriteSeparator string
}
// NewProperties creates a new Properties struct with the default
@@ -111,7 +116,7 @@ func (p *Properties) Get(key string) (value string, ok bool) {
// circular references and malformed expressions
// so we panic if we still get an error here.
if err != nil {
- ErrorHandler(fmt.Errorf("%s in %q", err, key+" = "+v))
+ ErrorHandler(err)
}
return expanded, true
@@ -586,6 +591,12 @@ func (p *Properties) String() string {
return s
}
+// Sort sorts the properties keys in alphabetical order.
+// This is helpfully before writing the properties.
+func (p *Properties) Sort() {
+ sort.Strings(p.k)
+}
+
// Write writes all unexpanded 'key = value' pairs to the given writer.
// Write returns the number of bytes written and any write error encountered.
func (p *Properties) Write(w io.Writer, enc Encoding) (n int, err error) {
@@ -626,7 +637,7 @@ func (p *Properties) WriteComment(w io.Writer, prefix string, enc Encoding) (n i
}
for _, c := range comments {
- x, err = fmt.Fprintf(w, "%s%s\n", prefix, encode(c, "", enc))
+ x, err = fmt.Fprintf(w, "%s%s\n", prefix, c)
if err != nil {
return
}
@@ -635,8 +646,11 @@ func (p *Properties) WriteComment(w io.Writer, prefix string, enc Encoding) (n i
}
}
}
-
- x, err = fmt.Fprintf(w, "%s = %s\n", encode(key, " :", enc), encode(value, "", enc))
+ sep := " = "
+ if p.WriteSeparator != "" {
+ sep = p.WriteSeparator
+ }
+ x, err = fmt.Fprintf(w, "%s%s%s\n", encode(key, " :", enc), sep, encode(value, "", enc))
if err != nil {
return
}
@@ -753,7 +767,12 @@ func expand(s string, keys []string, prefix, postfix string, values map[string]s
for _, k := range keys {
if key == k {
- return "", fmt.Errorf("circular reference")
+ var b bytes.Buffer
+ b.WriteString("circular reference in:\n")
+ for _, k1 := range keys {
+ fmt.Fprintf(&b, "%s=%s\n", k1, values[k1])
+ }
+ return "", fmt.Errorf(b.String())
}
}
@@ -820,6 +839,8 @@ func escape(r rune, special string) string {
return "\\r"
case '\t':
return "\\t"
+ case '\\':
+ return "\\\\"
default:
if strings.ContainsRune(special, r) {
return "\\" + string(r)