mirror of
https://github.com/xiaoqidun/goini.git
synced 2026-08-23 06:14:41 +08:00
style(代码风格): 保持代码良好的可维护性
This commit is contained in:
+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 {
|
||||
formattedLines := make([]string, 0, len(ini.fileLines))
|
||||
pendingComments := make([]string, 0)
|
||||
@@ -393,25 +412,6 @@ func formatINIComment(comment string) string {
|
||||
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 {
|
||||
if match == "" {
|
||||
return cloneStrings(items)
|
||||
|
||||
Reference in New Issue
Block a user