mirror of
https://github.com/qbittorrent/qBittorrent.git
synced 2026-01-01 05:08:05 -06:00
Change parseBool() to return optional bool value
This commit is contained in:
@@ -190,11 +190,14 @@ QString Utils::String::wildcardToRegex(const QString &pattern)
|
||||
return qt_regexp_toCanonical(pattern, QRegExp::Wildcard);
|
||||
}
|
||||
|
||||
bool Utils::String::parseBool(const QString &string, const bool defaultValue)
|
||||
std::optional<bool> Utils::String::parseBool(const QString &string)
|
||||
{
|
||||
if (defaultValue)
|
||||
return (string.compare("false", Qt::CaseInsensitive) == 0) ? false : true;
|
||||
return (string.compare("true", Qt::CaseInsensitive) == 0) ? true : false;
|
||||
if (string.compare("true", Qt::CaseInsensitive) == 0)
|
||||
return true;
|
||||
if (string.compare("false", Qt::CaseInsensitive) == 0)
|
||||
return false;
|
||||
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
QString Utils::String::join(const QVector<QStringRef> &strings, const QString &separator)
|
||||
|
||||
@@ -29,6 +29,8 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <optional>
|
||||
|
||||
#include <QChar>
|
||||
#include <QMetaEnum>
|
||||
#include <QString>
|
||||
@@ -64,7 +66,7 @@ namespace Utils::String
|
||||
return str;
|
||||
}
|
||||
|
||||
bool parseBool(const QString &string, bool defaultValue);
|
||||
std::optional<bool> parseBool(const QString &string);
|
||||
|
||||
QString join(const QVector<QStringRef> &strings, const QString &separator);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user