mirror of
https://github.com/Xahau/xahaud.git
synced 2025-12-06 17:27:52 +00:00
Add helpers for parsing section files.
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user