- use a proper FString to hold the name of config sections instead of a buffer tacked onto the actual structure. This is necessary if we want to be able to rename a section.

This commit is contained in:
Christoph Oelckers 2015-04-06 10:51:28 +02:00
parent b300cfaf62
commit cac634567b
2 changed files with 8 additions and 11 deletions

View File

@ -138,7 +138,7 @@ FConfigFile &FConfigFile::operator = (const FConfigFile &other)
while (fromsection != NULL) while (fromsection != NULL)
{ {
fromentry = fromsection->RootEntry; fromentry = fromsection->RootEntry;
tosection = NewConfigSection (fromsection->Name); tosection = NewConfigSection (fromsection->SectionName);
while (fromentry != NULL) while (fromentry != NULL)
{ {
NewConfigEntry (tosection, fromentry->Key, fromentry->Value); NewConfigEntry (tosection, fromentry->Key, fromentry->Value);
@ -309,7 +309,7 @@ const char *FConfigFile::GetCurrentSection () const
{ {
if (CurrentSection != NULL) if (CurrentSection != NULL)
{ {
return CurrentSection->Name; return CurrentSection->SectionName.GetChars();
} }
return NULL; return NULL;
} }
@ -506,7 +506,7 @@ FConfigFile::FConfigSection *FConfigFile::FindSection (const char *name) const
{ {
FConfigSection *section = Sections; FConfigSection *section = Sections;
while (section != NULL && stricmp (section->Name, name) != 0) while (section != NULL && section->SectionName.CompareNoCase(name) != 0)
{ {
section = section->Next; section = section->Next;
} }
@ -540,19 +540,15 @@ FConfigFile::FConfigEntry *FConfigFile::FindEntry (
FConfigFile::FConfigSection *FConfigFile::NewConfigSection (const char *name) FConfigFile::FConfigSection *FConfigFile::NewConfigSection (const char *name)
{ {
FConfigSection *section; FConfigSection *section;
char *memblock;
section = FindSection (name); section = FindSection (name);
if (section == NULL) if (section == NULL)
{ {
size_t namelen = strlen (name); section = new FConfigSection;
memblock = new char[sizeof(*section)+namelen];
section = ::new(memblock) FConfigSection;
section->RootEntry = NULL; section->RootEntry = NULL;
section->LastEntryPtr = &section->RootEntry; section->LastEntryPtr = &section->RootEntry;
section->Next = NULL; section->Next = NULL;
memcpy (section->Name, name, namelen); section->SectionName = name;
section->Name[namelen] = 0;
*LastSectionPtr = section; *LastSectionPtr = section;
LastSectionPtr = &section->Next; LastSectionPtr = &section->Next;
} }
@ -777,7 +773,7 @@ bool FConfigFile::WriteConfigFile () const
{ {
fputs (section->Note.GetChars(), file); fputs (section->Note.GetChars(), file);
} }
fprintf (file, "[%s]\n", section->Name); fprintf (file, "[%s]\n", section->SectionName.GetChars());
while (entry != NULL) while (entry != NULL)
{ {
if (strpbrk(entry->Value, "\r\n") == NULL) if (strpbrk(entry->Value, "\r\n") == NULL)

View File

@ -93,11 +93,12 @@ private:
}; };
struct FConfigSection struct FConfigSection
{ {
FString SectionName;
FConfigEntry *RootEntry; FConfigEntry *RootEntry;
FConfigEntry **LastEntryPtr; FConfigEntry **LastEntryPtr;
FConfigSection *Next; FConfigSection *Next;
FString Note; FString Note;
char Name[1]; // + length of name //char Name[1]; // + length of name
}; };
FConfigSection *Sections; FConfigSection *Sections;