diff options
| author | 2026-03-06 10:52:02 +0800 | |
|---|---|---|
| committer | 2026-03-06 10:53:37 +0800 | |
| commit | f36918966727be99bfe9d461059269f36f92058a (patch) | |
| tree | ff2c6545d369a74c210574f821298181307c701a /config/section.go | |
| parent | objecttype: Split files (diff) | |
| signature | No signature | |
config: Split files
Diffstat (limited to 'config/section.go')
| -rw-r--r-- | config/section.go | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/config/section.go b/config/section.go new file mode 100644 index 00000000..66adf011 --- /dev/null +++ b/config/section.go @@ -0,0 +1,41 @@ +package config + +import ( + "bytes" + "errors" + "fmt" + "strings" +) + +func (p *configParser) parseSection() error { + var name bytes.Buffer + + for { + ch, err := p.nextChar() + if err != nil { + return errors.New("unexpected EOF in section header") + } + + if ch == ']' { + section := name.String() + if !isValidSection(section) { + return fmt.Errorf("invalid section name: %q", section) + } + + p.currentSection = strings.ToLower(section) + p.currentSubsec = "" + + return nil + } + + if isWhitespace(ch) { + return p.parseExtendedSection(&name) + } + + if !isKeyChar(ch) && ch != '.' { + return fmt.Errorf("invalid character in section name: %q", ch) + } + + name.WriteByte(toLower(ch)) + } +} |
