From 822cf2bcbfa1e412f02144453a266ec37f360c52 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Wed, 19 Aug 2015 22:22:28 -0400 Subject: IniFile: Mark getter functions as const --- Source/Core/Common/IniFile.cpp | 43 ++++++++++++++++++++++++++++-------------- 1 file changed, 29 insertions(+), 14 deletions(-) (limited to 'Source/Core/Common/IniFile.cpp') diff --git a/Source/Core/Common/IniFile.cpp b/Source/Core/Common/IniFile.cpp index 9ea8f50533..0c53d9569e 100644 --- a/Source/Core/Common/IniFile.cpp +++ b/Source/Core/Common/IniFile.cpp @@ -72,7 +72,7 @@ void IniFile::Section::Set(const std::string& key, const std::vector* out) +bool IniFile::Section::Get(const std::string& key, std::vector* out) const { std::string temp; bool retval = Get(key, &temp); @@ -97,69 +97,84 @@ bool IniFile::Section::Get(const std::string& key, std::vector* out { return false; } - // ignore starting , if any + + // ignore starting comma, if any size_t subStart = temp.find_first_not_of(","); - // split by , + // split by comma while (subStart != std::string::npos) { - // Find next , + // Find next comma size_t subEnd = temp.find(',', subStart); if (subStart != subEnd) - // take from first char until next , + { + // take from first char until next comma out->push_back(StripSpaces(temp.substr(subStart, subEnd - subStart))); - // Find the next non , char + } + + // Find the next non-comma char subStart = temp.find_first_not_of(",", subEnd); } + return true; } -bool IniFile::Section::Get(const std::string& key, int* value, int defaultValue) +bool IniFile::Section::Get(const std::string& key, int* value, int defaultValue) const { std::string temp; bool retval = Get(key, &temp); + if (retval && TryParse(temp, value)) return true; + *value = defaultValue; return false; } -bool IniFile::Section::Get(const std::string& key, u32* value, u32 defaultValue) +bool IniFile::Section::Get(const std::string& key, u32* value, u32 defaultValue) const { std::string temp; bool retval = Get(key, &temp); + if (retval && TryParse(temp, value)) return true; + *value = defaultValue; return false; } -bool IniFile::Section::Get(const std::string& key, bool* value, bool defaultValue) +bool IniFile::Section::Get(const std::string& key, bool* value, bool defaultValue) const { std::string temp; bool retval = Get(key, &temp); + if (retval && TryParse(temp, value)) return true; + *value = defaultValue; return false; } -bool IniFile::Section::Get(const std::string& key, float* value, float defaultValue) +bool IniFile::Section::Get(const std::string& key, float* value, float defaultValue) const { std::string temp; bool retval = Get(key, &temp); + if (retval && TryParse(temp, value)) return true; + *value = defaultValue; return false; } -bool IniFile::Section::Get(const std::string& key, double* value, double defaultValue) +bool IniFile::Section::Get(const std::string& key, double* value, double defaultValue) const { std::string temp; bool retval = Get(key, &temp); + if (retval && TryParse(temp, value)) return true; + *value = defaultValue; return false; } -- cgit v1.2.3