Add helpers for parsing section files.

This commit is contained in:
Arthur Britto
2012-04-05 16:19:48 -07:00
parent 29afd2eeaf
commit 50621437e6
2 changed files with 46 additions and 0 deletions

View File

@@ -68,3 +68,46 @@ void PrintSection(section secInput)
}
std::cerr << "PrintSection<" << std::endl;
}
section::mapped_type* sectionEntries(section& secSource, std::string strSection)
{
section::iterator it;
section::mapped_type* smtResult;
it = secSource.find(strSection);
if (it == secSource.end())
{
smtResult = 0;
}
else
{
//section::mapped_type& vecEntries = it->second;
smtResult = &(it->second);
}
return smtResult;
}
int sectionCount(section& secSource, std::string strSection)
{
section::mapped_type* pmtEntries = sectionEntries(secSource, strSection);
return pmtEntries ? -1 : pmtEntries->size();
}
bool sectionSingleB(section& secSource, std::string strSection, std::string& strValue)
{
section::mapped_type* pmtEntries = sectionEntries(secSource, strSection);
bool bSingle = pmtEntries && 1 == pmtEntries->size();
if (bSingle)
{
strValue = (*pmtEntries)[0];
}
return bSingle;
}
// vim:ts=4

View File

@@ -9,5 +9,8 @@ typedef std::map<const std::string, std::vector<std::string> > section;
section ParseSection(const std::string strInput, const bool bTrim);
void PrintSection(section secInput);
bool sectionSingleB(section& secSource, std::string strSection, std::string& strValue);
int sectionCount(section& secSource, std::string strSection);
section::mapped_type* sectionEntries(section& secSource, std::string strSection);
#endif