Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Adding hasKeyNonEmpty function to IniFile and IniGroup.
  • Loading branch information
MainMemory committed Feb 6, 2015
1 parent e0efe88 commit 7177147
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
29 changes: 29 additions & 0 deletions src/SADXModLoader/IniFile.cpp
Expand Up @@ -27,6 +27,20 @@ bool IniGroup::hasKey(const string &key) const
return (m_data.find(key) != m_data.end());
}

/**
* Check if the INI group has the specified key with a non-empty value.
* @param key Key.
* @return True if the key exists; false if not or value is empty.
*/
bool IniGroup::hasKeyNonEmpty(const string &key) const
{
auto iter = m_data.find(key);
if (iter == m_data.end())
return false;

return !iter->second.empty();
}

const unordered_map<string, string> *IniGroup::data(void) const
{
return &m_data;
Expand Down Expand Up @@ -163,6 +177,21 @@ bool IniFile::hasKey(const string &section, const string &key) const
return iter->second->hasKey(key);
}

/**
* Check if the INI file has the specified key with a non-empty value.
* @param section Section.
* @param key Key.
* @return True if the key exists; false if not or value is empty.
*/
bool IniFile::hasKeyNonEmpty(const string &section, const string &key) const
{
auto iter = m_groups.find(section);
if (iter == m_groups.end())
return false;

return iter->second->hasKeyNonEmpty(key);
}

/**
* Get a string value from the INI file.
* @param section Section.
Expand Down
2 changes: 2 additions & 0 deletions src/SADXModLoader/IniFile.hpp
Expand Up @@ -19,6 +19,7 @@ class IniGroup
{
public:
bool hasKey(const std::string &key) const;
bool hasKeyNonEmpty(const std::string &key) const;

const std::unordered_map<std::string, std::string> *data(void) const;

Expand Down Expand Up @@ -54,6 +55,7 @@ class IniFile

bool hasGroup(const std::string &section) const;
bool hasKey(const std::string &section, const std::string &key) const;
bool hasKeyNonEmpty(const std::string &section, const std::string &key) const;

std::string getString(const std::string &section, const std::string &key, const std::string &def = "") const;
std::wstring getWString(const std::string &section, const std::string &key, const std::wstring &def = L"") const;
Expand Down

0 comments on commit 7177147

Please sign in to comment.