2019-07-23 22:18:36 +02:00
|
|
|
#include "FuzzyConvert.hpp"
|
2019-09-08 22:27:57 +02:00
|
|
|
|
2019-07-23 22:18:36 +02:00
|
|
|
#include <QRegularExpression>
|
2019-09-08 22:27:57 +02:00
|
|
|
|
2019-07-23 22:18:36 +02:00
|
|
|
namespace chatterino {
|
2019-09-08 22:27:57 +02:00
|
|
|
|
2019-07-23 22:18:36 +02:00
|
|
|
int fuzzyToInt(const QString &str, int default_)
|
|
|
|
{
|
|
|
|
static auto intFinder = QRegularExpression("[0-9]+");
|
2019-09-08 22:27:57 +02:00
|
|
|
|
2019-07-23 22:18:36 +02:00
|
|
|
auto match = intFinder.match(str);
|
|
|
|
if (match.hasMatch())
|
|
|
|
{
|
|
|
|
return match.captured().toInt();
|
|
|
|
}
|
2019-09-08 22:27:57 +02:00
|
|
|
|
2019-07-23 22:18:36 +02:00
|
|
|
return default_;
|
|
|
|
}
|
2019-09-08 22:27:57 +02:00
|
|
|
|
2019-07-23 22:18:36 +02:00
|
|
|
float fuzzyToFloat(const QString &str, float default_)
|
|
|
|
{
|
|
|
|
static auto floatFinder = QRegularExpression("[0-9]+(\\.[0-9]+)?");
|
2019-09-08 22:27:57 +02:00
|
|
|
|
2019-07-23 22:18:36 +02:00
|
|
|
auto match = floatFinder.match(str);
|
|
|
|
if (match.hasMatch())
|
|
|
|
{
|
|
|
|
return match.captured().toFloat();
|
|
|
|
}
|
2019-09-08 22:27:57 +02:00
|
|
|
|
2019-07-23 22:18:36 +02:00
|
|
|
return default_;
|
|
|
|
}
|
2019-09-08 22:27:57 +02:00
|
|
|
|
2019-07-23 22:18:36 +02:00
|
|
|
} // namespace chatterino
|