From caff3525b8be16957a2abb6bd1006b1714885751 Mon Sep 17 00:00:00 2001 From: Aleksandr Lesik <[email protected]> Date: Thu, 26 Jan 2023 10:48:29 +0300 Subject: [PATCH] Update section.go SetName changes section name. --- section.go | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/section.go b/section.go index a3615d8..81d0a1e 100644 --- a/section.go +++ b/section.go @@ -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 {