feat(清理代码): 清理非必要的代码

This commit is contained in:
2026-07-09 20:02:35 +08:00
parent 2c7697f6e5
commit f5ed0941bf
2 changed files with 13 additions and 16 deletions
+1 -4
View File
@@ -87,9 +87,6 @@ func (ini *GoINI) SaveFile(filename string) error {
// String 获取GoINI对象的字符串形式
// 返回: string 配置文件内容
func (ini *GoINI) String() string {
if len(ini.fileLines) == 0 {
return ""
}
renderedLines := make([]string, len(ini.fileLines))
for i, line := range ini.fileLines {
renderedLines[i] = renderLine(line)
@@ -113,7 +110,7 @@ func (ini *GoINI) SetString(name string, key string, value string) {
return
}
ini.ensureSectionLine(name)
ini.insertLine(ini.findSectionInsertIndex(name), iniLine{kind: lineKeyValue, sectionName: name, keyName: key, keyValue: value, separator: defaultSeparator, modified: true})
ini.insertLine(ini.findSectionInsertIndex(name), iniLine{kind: lineKeyValue, sectionName: name, keyName: key, keyValue: value, separator: defaultSeparator})
}
// SetBool 设置单个配置项的布尔值
+12 -12
View File
@@ -29,7 +29,7 @@ type iniLine struct {
modified bool
}
type keyValueParts struct {
type parsedKeyValue struct {
key string
value string
indent string
@@ -68,12 +68,12 @@ func parseRawLine(rawLine string, sectionName string) (iniLine, string) {
line.sectionName = nextSection
return line, nextSection
}
if parts, ok := parseKeyValue(rawLine); ok {
if parsed, ok := parseKeyValue(rawLine); ok {
line.kind = lineKeyValue
line.keyName = parts.key
line.keyValue = trimSurroundingQuotes(parts.value)
line.indent = parts.indent
line.separator = parts.separator
line.keyName = parsed.key
line.keyValue = trimSurroundingQuotes(parsed.value)
line.indent = parsed.indent
line.separator = parsed.separator
return line, sectionName
}
return line, sectionName
@@ -91,7 +91,7 @@ func parseSection(line string) (string, bool) {
return name, name != ""
}
func parseKeyValue(line string) (keyValueParts, bool) {
func parseKeyValue(line string) (parsedKeyValue, bool) {
indentLen := leadingSpaceLen(line)
indent := line[:indentLen]
body := line[indentLen:]
@@ -101,19 +101,19 @@ func parseKeyValue(line string) (keyValueParts, bool) {
if split := strings.IndexFunc(body, unicode.IsSpace); split >= 0 {
return parseKeyValueParts(body, split, split, indent)
}
return keyValueParts{}, false
return parsedKeyValue{}, false
}
func parseKeyValueParts(body string, keyEnd int, valueStart int, indent string) (keyValueParts, bool) {
func parseKeyValueParts(body string, keyEnd int, valueStart int, indent string) (parsedKeyValue, bool) {
keyPart := body[:keyEnd]
valuePart := body[valueStart:]
key := strings.TrimSpace(keyPart)
if key == "" {
return keyValueParts{}, false
return parsedKeyValue{}, false
}
separatorStart := len(strings.TrimRightFunc(keyPart, unicode.IsSpace))
separatorEnd := valueStart + leadingSpaceLen(valuePart)
return keyValueParts{
return parsedKeyValue{
key: key,
value: strings.TrimSpace(valuePart),
indent: indent,
@@ -222,7 +222,7 @@ func (ini *GoINI) ensureSectionLine(sectionName string) {
if len(ini.fileLines) > 0 && renderLine(ini.fileLines[len(ini.fileLines)-1]) != "" {
ini.fileLines = append(ini.fileLines, iniLine{kind: lineBlank})
}
ini.fileLines = append(ini.fileLines, iniLine{kind: lineSection, sectionName: sectionName, text: "[" + sectionName + "]"})
ini.fileLines = append(ini.fileLines, iniLine{kind: lineSection, sectionName: sectionName})
ini.rebuildIndexes()
}