1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 15:57:45 +00:00

LibCore: Convert ConfigFile to east const

This commit is contained in:
networkException 2021-08-19 22:28:45 +02:00 committed by Andreas Kling
parent 2ea2d026c2
commit 54bbe52b51
2 changed files with 24 additions and 24 deletions

View file

@ -112,7 +112,7 @@ void ConfigFile::reparse()
} }
} }
String ConfigFile::read_entry(const String& group, const String& key, const String& default_value) const String ConfigFile::read_entry(String const& group, String const& key, String const& default_value) const
{ {
if (!has_key(group, key)) { if (!has_key(group, key)) {
return default_value; return default_value;
@ -122,7 +122,7 @@ String ConfigFile::read_entry(const String& group, const String& key, const Stri
return jt->value; return jt->value;
} }
int ConfigFile::read_num_entry(const String& group, const String& key, int default_value) const int ConfigFile::read_num_entry(String const& group, String const& key, int default_value) const
{ {
if (!has_key(group, key)) { if (!has_key(group, key)) {
return default_value; return default_value;
@ -131,7 +131,7 @@ int ConfigFile::read_num_entry(const String& group, const String& key, int defau
return read_entry(group, key).to_int().value_or(default_value); return read_entry(group, key).to_int().value_or(default_value);
} }
bool ConfigFile::read_bool_entry(const String& group, const String& key, bool default_value) const bool ConfigFile::read_bool_entry(String const& group, String const& key, bool default_value) const
{ {
auto value = read_entry(group, key, default_value ? "1" : "0"); auto value = read_entry(group, key, default_value ? "1" : "0");
if (value == "1" || value.to_lowercase() == "true") if (value == "1" || value.to_lowercase() == "true")
@ -139,21 +139,21 @@ bool ConfigFile::read_bool_entry(const String& group, const String& key, bool de
return 0; return 0;
} }
void ConfigFile::write_entry(const String& group, const String& key, const String& value) void ConfigFile::write_entry(String const& group, String const& key, String const& value)
{ {
m_groups.ensure(group).ensure(key) = value; m_groups.ensure(group).ensure(key) = value;
m_dirty = true; m_dirty = true;
} }
void ConfigFile::write_num_entry(const String& group, const String& key, int value) void ConfigFile::write_num_entry(String const& group, String const& key, int value)
{ {
write_entry(group, key, String::number(value)); write_entry(group, key, String::number(value));
} }
void ConfigFile::write_bool_entry(const String& group, const String& key, bool value) void ConfigFile::write_bool_entry(String const& group, String const& key, bool value)
{ {
write_entry(group, key, value ? "1" : "0"); write_entry(group, key, value ? "1" : "0");
} }
void ConfigFile::write_color_entry(const String& group, const String& key, Color value) void ConfigFile::write_color_entry(String const& group, String const& key, Color value)
{ {
write_entry(group, key, String::formatted("{},{},{},{}", value.red(), value.green(), value.blue(), value.alpha())); write_entry(group, key, String::formatted("{},{},{},{}", value.red(), value.green(), value.blue(), value.alpha()));
} }
@ -191,7 +191,7 @@ Vector<String> ConfigFile::groups() const
return m_groups.keys(); return m_groups.keys();
} }
Vector<String> ConfigFile::keys(const String& group) const Vector<String> ConfigFile::keys(String const& group) const
{ {
auto it = m_groups.find(group); auto it = m_groups.find(group);
if (it == m_groups.end()) if (it == m_groups.end())
@ -199,7 +199,7 @@ Vector<String> ConfigFile::keys(const String& group) const
return it->value.keys(); return it->value.keys();
} }
bool ConfigFile::has_key(const String& group, const String& key) const bool ConfigFile::has_key(String const& group, String const& key) const
{ {
auto it = m_groups.find(group); auto it = m_groups.find(group);
if (it == m_groups.end()) if (it == m_groups.end())
@ -207,18 +207,18 @@ bool ConfigFile::has_key(const String& group, const String& key) const
return it->value.contains(key); return it->value.contains(key);
} }
bool ConfigFile::has_group(const String& group) const bool ConfigFile::has_group(String const& group) const
{ {
return m_groups.contains(group); return m_groups.contains(group);
} }
void ConfigFile::remove_group(const String& group) void ConfigFile::remove_group(String const& group)
{ {
m_groups.remove(group); m_groups.remove(group);
m_dirty = true; m_dirty = true;
} }
void ConfigFile::remove_entry(const String& group, const String& key) void ConfigFile::remove_entry(String const& group, String const& key)
{ {
auto it = m_groups.find(group); auto it = m_groups.find(group);
if (it == m_groups.end()) if (it == m_groups.end())

View file

@ -31,22 +31,22 @@ public:
static NonnullRefPtr<ConfigFile> open(String const& filename, int fd); static NonnullRefPtr<ConfigFile> open(String const& filename, int fd);
~ConfigFile(); ~ConfigFile();
bool has_group(const String&) const; bool has_group(String const&) const;
bool has_key(const String& group, const String& key) const; bool has_key(String const& group, String const& key) const;
Vector<String> groups() const; Vector<String> groups() const;
Vector<String> keys(const String& group) const; Vector<String> keys(String const& group) const;
size_t num_groups() const { return m_groups.size(); } size_t num_groups() const { return m_groups.size(); }
String read_entry(const String& group, const String& key, const String& default_value = String()) const; String read_entry(String const& group, String const& key, String const& default_value = String()) const;
int read_num_entry(const String& group, const String& key, int default_value = 0) const; int read_num_entry(String const& group, String const& key, int default_value = 0) const;
bool read_bool_entry(const String& group, const String& key, bool default_value = false) const; bool read_bool_entry(String const& group, String const& key, bool default_value = false) const;
void write_entry(const String& group, const String& key, const String& value); void write_entry(String const& group, String const& key, String const& value);
void write_num_entry(const String& group, const String& key, int value); void write_num_entry(String const& group, String const& key, int value);
void write_bool_entry(const String& group, const String& key, bool value); void write_bool_entry(String const& group, String const& key, bool value);
void write_color_entry(const String& group, const String& key, Color value); void write_color_entry(String const& group, String const& key, Color value);
void dump() const; void dump() const;
@ -54,8 +54,8 @@ public:
bool sync(); bool sync();
void remove_group(const String& group); void remove_group(String const& group);
void remove_entry(const String& group, const String& key); void remove_entry(String const& group, String const& key);
String filename() const { return m_file->filename(); } String filename() const { return m_file->filename(); }