diff --git a/Common/Data/Format/IniFile.cpp b/Common/Data/Format/IniFile.cpp index 49c38f8120..4b728c78fa 100644 --- a/Common/Data/Format/IniFile.cpp +++ b/Common/Data/Format/IniFile.cpp @@ -416,22 +416,22 @@ bool Section::Delete(std::string_view key) { // IniFile -const Section* IniFile::GetSection(const char* sectionName) const { +const Section* IniFile::GetSection(std::string_view sectionName) const { for (const auto &iter : sections) - if (!strcasecmp(iter->name().c_str(), sectionName)) + if (equalsNoCase(iter->name(), sectionName)) return iter.get(); return nullptr; } -Section* IniFile::GetSection(const char* sectionName) { +Section* IniFile::GetSection(std::string_view sectionName) { for (const auto &iter : sections) - if (!strcasecmp(iter->name().c_str(), sectionName)) + if (equalsNoCase(iter->name(), sectionName)) return iter.get(); return nullptr; } -Section* IniFile::GetOrCreateSection(const char* sectionName) { - Section* section = GetSection(sectionName); +Section* IniFile::GetOrCreateSection(std::string_view sectionName) { + Section *section = GetSection(sectionName); if (!section) { sections.push_back(std::make_unique
(sectionName)); section = sections.back().get(); @@ -439,7 +439,7 @@ Section* IniFile::GetOrCreateSection(const char* sectionName) { return section; } -bool IniFile::DeleteSection(const char* sectionName) { +bool IniFile::DeleteSection(std::string_view sectionName) { Section* s = GetSection(sectionName); if (!s) return false; @@ -453,14 +453,14 @@ bool IniFile::DeleteSection(const char* sectionName) { return false; } -bool IniFile::Exists(const char* sectionName, std::string_view key) const { +bool IniFile::Exists(std::string_view sectionName, std::string_view key) const { const Section* section = GetSection(sectionName); if (!section) return false; return section->Exists(key); } -bool IniFile::DeleteKey(const char* sectionName, std::string_view key) { +bool IniFile::DeleteKey(std::string_view sectionName, std::string_view key) { Section* section = GetSection(sectionName); if (!section) return false; @@ -475,15 +475,14 @@ bool IniFile::DeleteKey(const char* sectionName, std::string_view key) { } // Return a list of all keys in a section -bool IniFile::GetKeys(const char* sectionName, std::vector& keys) const { +bool IniFile::GetKeys(std::string_view sectionName, std::vector& keys) const { const Section *section = GetSection(sectionName); if (!section) return false; return section->GetKeys(keys); } -void IniFile::SortSections() -{ +void IniFile::SortSections() { std::sort(sections.begin(), sections.end()); } @@ -583,8 +582,7 @@ bool IniFile::Save(const Path &filename) return true; } -bool IniFile::Get(const char* sectionName, const char* key, std::string* value, const char* defaultValue) -{ +bool IniFile::Get(std::string_view sectionName, std::string_view key, std::string* value, const char *defaultValue) { Section* section = GetSection(sectionName); if (!section) { if (defaultValue) { @@ -595,16 +593,14 @@ bool IniFile::Get(const char* sectionName, const char* key, std::string* value, return section->Get(key, value, defaultValue); } -bool IniFile::Get(const char *sectionName, const char* key, std::vector *values, const std::vector *defaultValues) -{ +bool IniFile::Get(std::string_view sectionName, std::string_view key, std::vector *values, const std::vector *defaultValues) { Section *section = GetSection(sectionName); if (!section) return false; return section->Get(key, values, defaultValues); } -bool IniFile::Get(const char* sectionName, const char* key, int* value, int defaultValue) -{ +bool IniFile::Get(std::string_view sectionName, std::string_view key, int *value, int defaultValue) { Section *section = GetSection(sectionName); if (!section) { *value = defaultValue; @@ -614,8 +610,7 @@ bool IniFile::Get(const char* sectionName, const char* key, int* value, int defa } } -bool IniFile::Get(const char* sectionName, const char* key, uint32_t* value, uint32_t defaultValue) -{ +bool IniFile::Get(std::string_view sectionName, std::string_view key, uint32_t *value, uint32_t defaultValue) { Section *section = GetSection(sectionName); if (!section) { *value = defaultValue; @@ -625,8 +620,7 @@ bool IniFile::Get(const char* sectionName, const char* key, uint32_t* value, uin } } -bool IniFile::Get(const char* sectionName, const char* key, uint64_t* value, uint64_t defaultValue) -{ +bool IniFile::Get(std::string_view sectionName, std::string_view key, uint64_t *value, uint64_t defaultValue) { Section *section = GetSection(sectionName); if (!section) { *value = defaultValue; @@ -636,8 +630,7 @@ bool IniFile::Get(const char* sectionName, const char* key, uint64_t* value, uin } } -bool IniFile::Get(const char* sectionName, const char* key, bool* value, bool defaultValue) -{ +bool IniFile::Get(std::string_view sectionName, std::string_view key, bool *value, bool defaultValue) { Section *section = GetSection(sectionName); if (!section) { *value = defaultValue; diff --git a/Common/Data/Format/IniFile.h b/Common/Data/Format/IniFile.h index 952a280a06..08f4a9e2b1 100644 --- a/Common/Data/Format/IniFile.h +++ b/Common/Data/Format/IniFile.h @@ -135,30 +135,30 @@ public: bool Save(const Path &path); // Returns true if key exists in section - bool Exists(const char* sectionName, std::string_view key) const; + bool Exists(std::string_view sectionName, std::string_view key) const; // These will not create the section if it doesn't exist. - bool Get(const char* sectionName, const char* key, std::string* value, const char* defaultValue = ""); - bool Get(const char* sectionName, const char* key, int* value, int defaultValue = 0); - bool Get(const char* sectionName, const char* key, uint32_t* value, uint32_t defaultValue = 0); - bool Get(const char* sectionName, const char* key, uint64_t* value, uint64_t defaultValue = 0); - bool Get(const char* sectionName, const char* key, bool* value, bool defaultValue = false); - bool Get(const char* sectionName, const char* key, std::vector *values, const std::vector *defaultValues = nullptr); + bool Get(std::string_view sectionName, std::string_view key, std::string* value, const char* defaultValue = ""); + bool Get(std::string_view sectionName, std::string_view key, int* value, int defaultValue = 0); + bool Get(std::string_view sectionName, std::string_view key, uint32_t* value, uint32_t defaultValue = 0); + bool Get(std::string_view sectionName, std::string_view key, uint64_t* value, uint64_t defaultValue = 0); + bool Get(std::string_view sectionName, std::string_view key, bool* value, bool defaultValue = false); + bool Get(std::string_view sectionName, std::string_view key, std::vector *values, const std::vector *defaultValues = nullptr); - bool GetKeys(const char* sectionName, std::vector& keys) const; + bool GetKeys(std::string_view sectionName, std::vector& keys) const; - bool DeleteKey(const char* sectionName, std::string_view key); - bool DeleteSection(const char* sectionName); + bool DeleteKey(std::string_view sectionName, std::string_view key); + bool DeleteSection(std::string_view sectionName); void SortSections(); std::vector> &Sections() { return sections; } - bool HasSection(const char *section) { return GetSection(section) != nullptr; } - const Section* GetSection(const char* section) const; - Section* GetSection(const char* section); + bool HasSection(std::string_view section) { return GetSection(section) != nullptr; } + const Section* GetSection(std::string_view section) const; + Section* GetSection(std::string_view section); - Section* GetOrCreateSection(const char* section); + Section* GetOrCreateSection(std::string_view section); private: std::vector> sections;