36using std::stringstream;
146 std::transform(strLower.begin(), strLower.end(), strLower.begin(), ::tolower);
148 if (strLower ==
"true" || strLower ==
"yes" || strLower ==
"y" || strLower ==
"1")
150 else if (strLower ==
"false" || strLower ==
"no" || strLower ==
"n" || strLower ==
"0")
158 vector<string> vecResult;
161 vecResult.push_back(node.GetValue());
183 ifstream fileStream(strFileName);
184 if (! fileStream.is_open())
186 m_strError =
"Cannot open file: " + strFileName;
194 catch (std::exception
const& e)
222 for (
char c : strLine)
236 auto it = strLine.begin();
237 while (it != strLine.end() && isspace(*it))
239 return string(it, strLine.end());
244 auto it = strLine.rbegin();
245 while (it != strLine.rend() && isspace(*it))
247 return string(strLine.begin(), it.base());
258 return strTrimmed.empty() || strTrimmed[0] ==
'#';
263 return strTrim(strLine).empty();
272 if (strTrimmed.length() > 0 && strTrimmed[0] ==
'-')
276 strValue =
strTrim(strTrimmed.substr(1));
282 size_t nColonPos = strTrimmed.find(
':');
283 if (nColonPos == string::npos)
286 strKey =
strTrim(strTrimmed.substr(0, nColonPos));
287 if (nColonPos + 1 < strTrimmed.length())
288 strValue =
strTrim(strTrimmed.substr(nColonPos + 1));
300 string result = strValue;
303 if (result.length() >= 2 && result.front() ==
'"' && result.back() ==
'"')
305 result = result.substr(1, result.length() - 2);
308 else if (result.length() >= 2 && result.front() ==
'\'' && result.back() ==
'\'')
310 result = result.substr(1, result.length() - 2);
321 while (getline(fileStream, strLine))
332 if (nBaseIndent >= 0 && nIndent <= nBaseIndent)
335 fileStream.seekg(
static_cast<int>(fileStream.tellg()) -
static_cast<int>(strLine.length()) - 1);
340 string strKey, strValue;
343 if (
bParseLine(strLine, strKey, strValue, bIsSequence))
349 if (! strValue.empty())
364 if (! strValue.empty())
373 currentNode.
AddChild(strKey, childNode);
Simple YAML node class to represent parsed values.
map< string, CYamlNode > m_mapChildren
int GetSequenceSize() const
vector< string > GetStringSequence() const
vector< CYamlNode > m_vecChildren
vector< CYamlNode > GetSequence() const
bool HasChild(string const &strKey) const
void AddChild(string const &strKey, CYamlNode const &node)
bool GetBoolValue(bool bDefault=false) const
void AddSequenceItem(CYamlNode const &node)
double GetDoubleValue(double dDefault=0.0) const
CYamlNode GetChild(string const &strKey) const
unsigned long GetULongValue(unsigned long nDefault=0) const
int GetIntValue(int nDefault=0) const
void SetValue(string const &strValue)
string strRemoveQuotes(string const &strValue) const
string strTrim(string const &strLine) const
string strTrimRight(string const &strLine) const
bool bParseLine(string const &strLine, string &strKey, string &strValue, bool &bIsSequence) const
bool bIsComment(string const &strLine) const
string strTrimLeft(string const &strLine) const
CYamlNode ParseSection(ifstream &fileStream, int nBaseIndent)
bool bParseFile(string const &strFileName)
int nGetIndentLevel(string const &strLine) const
CYamlNode GetRoot() const
bool bIsEmpty(string const &strLine) const
Simple YAML parser for CoastalME configuration files.