mirror of
https://github.com/xiaoqidun/goini.git
synced 2026-08-23 06:14:41 +08:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c2ceb7dea7 |
+19
-19
@@ -358,6 +358,25 @@ func renderLine(line iniLine) string {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func renderKeyValue(line iniLine) string {
|
||||||
|
separator := line.separator
|
||||||
|
if separator == "" {
|
||||||
|
separator = defaultSeparator
|
||||||
|
}
|
||||||
|
return line.indent + line.keyName + separator + formatValue(line.keyValue)
|
||||||
|
}
|
||||||
|
|
||||||
|
func formatValue(value string) string {
|
||||||
|
if strings.TrimSpace(value) == value && !hasSurroundingQuotes(value) {
|
||||||
|
return value
|
||||||
|
}
|
||||||
|
quote := `"`
|
||||||
|
if strings.HasPrefix(value, `"`) && strings.HasSuffix(value, `"`) {
|
||||||
|
quote = "`"
|
||||||
|
}
|
||||||
|
return quote + value + quote
|
||||||
|
}
|
||||||
|
|
||||||
func (ini *GoINI) formatString() string {
|
func (ini *GoINI) formatString() string {
|
||||||
formattedLines := make([]string, 0, len(ini.fileLines))
|
formattedLines := make([]string, 0, len(ini.fileLines))
|
||||||
pendingComments := make([]string, 0)
|
pendingComments := make([]string, 0)
|
||||||
@@ -393,25 +412,6 @@ func formatINIComment(comment string) string {
|
|||||||
return "# " + comment
|
return "# " + comment
|
||||||
}
|
}
|
||||||
|
|
||||||
func renderKeyValue(line iniLine) string {
|
|
||||||
separator := line.separator
|
|
||||||
if separator == "" {
|
|
||||||
separator = defaultSeparator
|
|
||||||
}
|
|
||||||
return line.indent + line.keyName + separator + formatValue(line.keyValue)
|
|
||||||
}
|
|
||||||
|
|
||||||
func formatValue(value string) string {
|
|
||||||
if strings.TrimSpace(value) == value && !hasSurroundingQuotes(value) {
|
|
||||||
return value
|
|
||||||
}
|
|
||||||
quote := `"`
|
|
||||||
if strings.HasPrefix(value, `"`) && strings.HasSuffix(value, `"`) {
|
|
||||||
quote = "`"
|
|
||||||
}
|
|
||||||
return quote + value + quote
|
|
||||||
}
|
|
||||||
|
|
||||||
func matchStrings(items []string, match string) []string {
|
func matchStrings(items []string, match string) []string {
|
||||||
if match == "" {
|
if match == "" {
|
||||||
return cloneStrings(items)
|
return cloneStrings(items)
|
||||||
|
|||||||
Reference in New Issue
Block a user