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

View File

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