More cleanup. Fix some warnings.

This commit is contained in:
Henrik Rydgård 2025-10-31 22:37:28 +01:00
parent 14ddad5ce3
commit 4ec26d5002
5 changed files with 28 additions and 12 deletions

View File

@ -308,13 +308,10 @@ void Section::Set(std::string_view key, const std::vector<std::string> &newValue
Set(key, temp.c_str());
}
bool Section::Get(std::string_view key, std::vector<std::string> *values, const std::vector<std::string_view> *defaultValues) const {
bool Section::Get(std::string_view key, std::vector<std::string> *values) const {
std::string temp;
bool retval = Get(key, &temp);
if (!retval) {
if (defaultValues) {
CopyStrings(values, *defaultValues);
}
return false;
}
SplitString(temp, ',', *values, true);

View File

@ -93,7 +93,7 @@ public:
bool Get(std::string_view key, bool* value) const;
bool Get(std::string_view key, float* value) const;
bool Get(std::string_view key, double* value) const;
bool Get(std::string_view key, std::vector<std::string> *values, const std::vector<std::string_view> *defaultValue = nullptr) const;
bool Get(std::string_view key, std::vector<std::string> *values) const;
// Return a list of all keys in this section
bool GetKeys(std::vector<std::string> &keys) const;

View File

@ -70,6 +70,8 @@ inline bool equals(std::string_view str, std::string_view key) {
inline bool equalsNoCase(std::string_view str, std::string_view key) {
if (str.size() != key.size())
return false;
if (str.empty())
return true; // due to the check above, the other one is also empty.
return strncasecmp(str.data(), key.data(), key.size()) == 0;
}
@ -134,6 +136,14 @@ inline size_t truncate_cpy(char(&out)[Count], std::string_view src) {
return truncate_cpy(out, Count, src);
}
inline std::string join(std::string_view a, std::string_view b) {
std::string result;
result.reserve(a.size() + b.size());
result.append(a);
result.append(b);
return result;
}
inline const char *safe_string(const char *s) {
return s ? s : "(null)";
}

View File

@ -70,7 +70,13 @@ bool ConfigSetting::ReadFromIniSection(char *owner, const Section *section) cons
{
std::string *target = (std::string *)(owner + offset_);
if (!section->Get(iniKey_, target)) {
*target = cb_.s ? cb_.s().c_str() : default_.s;
if (cb_.s) {
*target = cb_.s();
} else if (default_.s) {
*target = default_.s;
} else {
target->clear();
}
return false;
}
return true;
@ -79,11 +85,14 @@ bool ConfigSetting::ReadFromIniSection(char *owner, const Section *section) cons
{
// No support for callbacks for these yet. that's not an issue.
std::vector<std::string> *ptr = (std::vector<std::string> *)(owner + offset_);
bool success = section->Get(iniKey_, ptr, default_.v);
if (success) {
MakeUnique(*ptr);
if (!section->Get(iniKey_, ptr)) {
if (default_.v) {
CopyStrings(ptr, *default_.v);
}
return false;
}
return success;
MakeUnique(*ptr);
return true;
}
case Type::TYPE_TOUCH_POS:
{
@ -341,7 +350,7 @@ void ConfigSetting::ReportSetting(const char *owner, UrlEncoder &data, const std
if (!Report())
return;
const std::string key = prefix + std::string(iniKey_);
const std::string key = join(prefix, std::string(iniKey_));
switch (type_) {
case Type::TYPE_BOOL: return data.Add(key, (const bool *)(owner + offset_));

View File

@ -103,7 +103,7 @@ void LoadPostShaderInfo(Draw::DrawContext *draw, const std::vector<Path> &direct
section.Get("Type", &shaderType);
std::vector<std::string> vendorBlacklist;
section.Get("VendorBlacklist", &vendorBlacklist, nullptr);
section.Get("VendorBlacklist", &vendorBlacklist);
bool skipped = false;
for (auto &item : vendorBlacklist) {
Draw::GPUVendor blacklistedVendor = Draw::GPUVendor::VENDOR_UNKNOWN;