aboutsummaryrefslogtreecommitdiff
path: root/config/section.go
diff options
context:
space:
mode:
authorGravatar Runxi Yu2026-03-06 10:52:02 +0800
committerGravatar Runxi Yu2026-03-06 10:53:37 +0800
commitf36918966727be99bfe9d461059269f36f92058a (patch)
treeff2c6545d369a74c210574f821298181307c701a /config/section.go
parentobjecttype: Split files (diff)
signatureNo signature
config: Split files
Diffstat (limited to 'config/section.go')
-rw-r--r--config/section.go41
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))
+ }
+}