aboutsummaryrefslogtreecommitdiff
path: root/config/extended_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/extended_section.go
parentobjecttype: Split files (diff)
signatureNo signature
config: Split files
Diffstat (limited to 'config/extended_section.go')
-rw-r--r--config/extended_section.go76
1 files changed, 76 insertions, 0 deletions
diff --git a/config/extended_section.go b/config/extended_section.go
new file mode 100644
index 00000000..410009e7
--- /dev/null
+++ b/config/extended_section.go
@@ -0,0 +1,76 @@
+package config
+
+import (
+ "bytes"
+ "errors"
+ "fmt"
+ "strings"
+)
+
+func (p *configParser) parseExtendedSection(sectionName *bytes.Buffer) error {
+ for {
+ ch, err := p.nextChar()
+ if err != nil {
+ return errors.New("unexpected EOF in section header")
+ }
+
+ if !isWhitespace(ch) {
+ if ch != '"' {
+ return errors.New("expected quote after section name")
+ }
+
+ break
+ }
+ }
+
+ var subsec bytes.Buffer
+
+ for {
+ ch, err := p.nextChar()
+ if err != nil {
+ return errors.New("unexpected EOF in subsection")
+ }
+
+ if ch == '\n' {
+ return errors.New("newline in subsection")
+ }
+
+ if ch == '"' {
+ break
+ }
+
+ if ch == '\\' {
+ next, err := p.nextChar()
+ if err != nil {
+ return errors.New("unexpected EOF after backslash in subsection")
+ }
+
+ if next == '\n' {
+ return errors.New("newline after backslash in subsection")
+ }
+
+ subsec.WriteByte(next)
+ } else {
+ subsec.WriteByte(ch)
+ }
+ }
+
+ ch, err := p.nextChar()
+ if err != nil {
+ return errors.New("unexpected EOF after subsection")
+ }
+
+ if ch != ']' {
+ return fmt.Errorf("expected ']' after subsection, got %q", ch)
+ }
+
+ section := sectionName.String()
+ if !isValidSection(section) {
+ return fmt.Errorf("invalid section name: %q", section)
+ }
+
+ p.currentSection = strings.ToLower(section)
+ p.currentSubsec = subsec.String()
+
+ return nil
+}