36using std::stringstream;
132 std::transform(strLower.begin(), strLower.end(), strLower.begin(), ::tolower);
134 if (strLower ==
"true" || strLower ==
"yes" || strLower ==
"y" || strLower ==
"1")
136 else if (strLower ==
"false" || strLower ==
"no" || strLower ==
"n" || strLower ==
"0")
144 vector<string> vecResult;
147 vecResult.push_back(node.GetValue());
169 ifstream fileStream(strFileName);
170 if (! fileStream.is_open())
172 m_strError =
"Cannot open file: " + strFileName;
180 catch (std::exception
const& e)
208 for (
char c : strLine)
222 auto it = strLine.begin();
223 while (it != strLine.end() && isspace(*it))
225 return string(it, strLine.end());
230 auto it = strLine.rbegin();
231 while (it != strLine.rend() && isspace(*it))
233 return string(strLine.begin(), it.base());
244 return strTrimmed.empty() || strTrimmed[0] ==
'#';
249 return strTrim(strLine).empty();
258 if (strTrimmed.length() > 0 && strTrimmed[0] ==
'-')
262 strValue =
strTrim(strTrimmed.substr(1));
268 size_t nColonPos = strTrimmed.find(
':');
269 if (nColonPos == string::npos)
272 strKey =
strTrim(strTrimmed.substr(0, nColonPos));
273 if (nColonPos + 1 < strTrimmed.length())
274 strValue =
strTrim(strTrimmed.substr(nColonPos + 1));
286 string result = strValue;
289 if (result.length() >= 2 && result.front() ==
'"' && result.back() ==
'"')
291 result = result.substr(1, result.length() - 2);
294 else if (result.length() >= 2 && result.front() ==
'\'' && result.back() ==
'\'')
296 result = result.substr(1, result.length() - 2);
307 while (getline(fileStream, strLine))
318 if (nBaseIndent >= 0 && nIndent <= nBaseIndent)
321 fileStream.seekg(
static_cast<int>(fileStream.tellg()) -
static_cast<int>(strLine.length()) - 1);
326 string strKey, strValue;
329 if (
bParseLine(strLine, strKey, strValue, bIsSequence))
335 if (! strValue.empty())
350 if (! strValue.empty())
359 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
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.