update ConfigIni

This commit is contained in:
Nomango 2020-05-28 11:40:51 +08:00
parent f5c9e5e226
commit bd8b328d01
2 changed files with 22 additions and 10 deletions

View File

@ -261,9 +261,9 @@ bool ConfigIni::GetBool(const String& section, const String& key, bool default_v
String str = GetString(section, key);
if (!str.empty())
{
if (str == "true")
if (str == "true" || str == "1")
return true;
else if (str == "false")
else if (str == "false" || str == "0")
return false;
}
return default_value;
@ -324,6 +324,24 @@ void ConfigIni::SetBool(const String& section, const String& key, bool value)
SetString(section, key, value ? "true" : "false");
}
ConfigIni::ValueMap& ConfigIni::operator[](const String& section)
{
if (!HasSection(section))
{
sections_.insert(std::make_pair(section, ValueMap()));
}
return sections_[section];
}
const ConfigIni::ValueMap& ConfigIni::operator[](const String& section) const
{
if (!HasSection(section))
{
const_cast<SectionMap&>(sections_).insert(std::make_pair(section, ValueMap()));
}
return sections_.at(section);
}
void ConfigIni::ParseLine(StringView line, String* section)
{
line = Trim(line);

View File

@ -165,15 +165,9 @@ public:
/// @param value ֵ
void SetBool(const String& section, const String& key, bool value);
inline ValueMap& operator[](const String& section)
{
return sections_[section];
}
ValueMap& operator[](const String& section);
inline const ValueMap& operator[](const String& section) const
{
return sections_.at(section);
}
const ValueMap& operator[](const String& section) const;
private:
void ParseLine(StringView line, String* section);