style(代码风格): 保持代码良好的可维护性

This commit is contained in:
2026-08-19 14:37:44 +08:00
parent 1f9d169cf1
commit c2ceb7dea7
+19 -19
View File
@@ -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)