Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update section.go. SetName changes section name. #334

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 21 additions & 0 deletions section.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,27 @@ func (s *Section) Name() string {
return s.name
}

// SetName changes section name.
func (s *Section) SetName(name string) {
if s.f.BlockMode {
s.f.lock.Lock()
defer s.f.lock.Unlock()
}

buf := s.f.sections[s.name]
delete(s.f.sections, s.name)
s.f.sections[name] = buf

for i := range s.f.sectionList {
if s.f.sectionList[i] == s.name {
s.f.sectionList[i] = name
break
}
}

s.name = name
}

// Body returns rawBody of Section if the section was marked as unparseable.
// It still follows the other rules of the INI format surrounding leading/trailing whitespace.
func (s *Section) Body() string {
Expand Down