fix: don't indent inner namespaces (#6235)
This commit is contained in:
@@ -7,15 +7,15 @@ namespace chatterino {
|
||||
|
||||
namespace {
|
||||
|
||||
void appendDuration(int count, QChar &&suffix, QString &out)
|
||||
void appendDuration(int count, QChar &&suffix, QString &out)
|
||||
{
|
||||
if (!out.isEmpty())
|
||||
{
|
||||
if (!out.isEmpty())
|
||||
{
|
||||
out.append(' ');
|
||||
}
|
||||
out.append(QString::number(count));
|
||||
out.append(suffix);
|
||||
out.append(' ');
|
||||
}
|
||||
out.append(QString::number(count));
|
||||
out.append(suffix);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
|
||||
+86
-86
@@ -33,105 +33,105 @@ namespace chatterino {
|
||||
|
||||
namespace helpers::detail {
|
||||
|
||||
SizeType skipSpace(QStringView view, SizeType startPos)
|
||||
SizeType skipSpace(QStringView view, SizeType startPos)
|
||||
{
|
||||
while (startPos < view.length() && view.at(startPos).isSpace())
|
||||
{
|
||||
while (startPos < view.length() && view.at(startPos).isSpace())
|
||||
{
|
||||
startPos++;
|
||||
}
|
||||
return startPos - 1;
|
||||
startPos++;
|
||||
}
|
||||
return startPos - 1;
|
||||
}
|
||||
|
||||
bool matchesIgnorePlural(QStringView word, const QString &expected)
|
||||
bool matchesIgnorePlural(QStringView word, const QString &expected)
|
||||
{
|
||||
if (!word.startsWith(expected))
|
||||
{
|
||||
if (!word.startsWith(expected))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (word.length() == expected.length())
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return word.length() == expected.length() + 1 &&
|
||||
word.at(word.length() - 1).toLatin1() == 's';
|
||||
return false;
|
||||
}
|
||||
|
||||
std::pair<uint64_t, bool> findUnitMultiplierToSec(QStringView view,
|
||||
SizeType &pos)
|
||||
if (word.length() == expected.length())
|
||||
{
|
||||
// Step 1. find end of unit
|
||||
auto startIdx = pos;
|
||||
auto endIdx = view.length();
|
||||
for (; pos < view.length(); pos++)
|
||||
{
|
||||
auto c = view.at(pos);
|
||||
if (c.isSpace() || c.isDigit())
|
||||
{
|
||||
endIdx = pos;
|
||||
break;
|
||||
}
|
||||
}
|
||||
pos--;
|
||||
return true;
|
||||
}
|
||||
return word.length() == expected.length() + 1 &&
|
||||
word.at(word.length() - 1).toLatin1() == 's';
|
||||
}
|
||||
|
||||
// TODO(QT6): use sliced (more readable)
|
||||
auto unit = view.mid(startIdx, endIdx - startIdx);
|
||||
if (unit.isEmpty())
|
||||
std::pair<uint64_t, bool> findUnitMultiplierToSec(QStringView view,
|
||||
SizeType &pos)
|
||||
{
|
||||
// Step 1. find end of unit
|
||||
auto startIdx = pos;
|
||||
auto endIdx = view.length();
|
||||
for (; pos < view.length(); pos++)
|
||||
{
|
||||
auto c = view.at(pos);
|
||||
if (c.isSpace() || c.isDigit())
|
||||
{
|
||||
return std::make_pair(0, false);
|
||||
endIdx = pos;
|
||||
break;
|
||||
}
|
||||
}
|
||||
pos--;
|
||||
|
||||
auto first = unit.at(0).toLatin1();
|
||||
switch (first)
|
||||
{
|
||||
case 's': {
|
||||
if (unit.length() == 1 ||
|
||||
matchesIgnorePlural(unit, QStringLiteral("second")))
|
||||
{
|
||||
return std::make_pair(1, true);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 'm': {
|
||||
if (unit.length() == 1 ||
|
||||
matchesIgnorePlural(unit, QStringLiteral("minute")))
|
||||
{
|
||||
return std::make_pair(60, true);
|
||||
}
|
||||
if ((unit.length() == 2 && unit.at(1).toLatin1() == 'o') ||
|
||||
matchesIgnorePlural(unit, QStringLiteral("month")))
|
||||
{
|
||||
return std::make_pair(60 * 60 * 24 * 30, true);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 'h': {
|
||||
if (unit.length() == 1 ||
|
||||
matchesIgnorePlural(unit, QStringLiteral("hour")))
|
||||
{
|
||||
return std::make_pair(60 * 60, true);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 'd': {
|
||||
if (unit.length() == 1 ||
|
||||
matchesIgnorePlural(unit, QStringLiteral("day")))
|
||||
{
|
||||
return std::make_pair(60 * 60 * 24, true);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 'w': {
|
||||
if (unit.length() == 1 ||
|
||||
matchesIgnorePlural(unit, QStringLiteral("week")))
|
||||
{
|
||||
return std::make_pair(60 * 60 * 24 * 7, true);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
// TODO(QT6): use sliced (more readable)
|
||||
auto unit = view.mid(startIdx, endIdx - startIdx);
|
||||
if (unit.isEmpty())
|
||||
{
|
||||
return std::make_pair(0, false);
|
||||
}
|
||||
|
||||
auto first = unit.at(0).toLatin1();
|
||||
switch (first)
|
||||
{
|
||||
case 's': {
|
||||
if (unit.length() == 1 ||
|
||||
matchesIgnorePlural(unit, QStringLiteral("second")))
|
||||
{
|
||||
return std::make_pair(1, true);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 'm': {
|
||||
if (unit.length() == 1 ||
|
||||
matchesIgnorePlural(unit, QStringLiteral("minute")))
|
||||
{
|
||||
return std::make_pair(60, true);
|
||||
}
|
||||
if ((unit.length() == 2 && unit.at(1).toLatin1() == 'o') ||
|
||||
matchesIgnorePlural(unit, QStringLiteral("month")))
|
||||
{
|
||||
return std::make_pair(60 * 60 * 24 * 30, true);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 'h': {
|
||||
if (unit.length() == 1 ||
|
||||
matchesIgnorePlural(unit, QStringLiteral("hour")))
|
||||
{
|
||||
return std::make_pair(60 * 60, true);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 'd': {
|
||||
if (unit.length() == 1 ||
|
||||
matchesIgnorePlural(unit, QStringLiteral("day")))
|
||||
{
|
||||
return std::make_pair(60 * 60 * 24, true);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 'w': {
|
||||
if (unit.length() == 1 ||
|
||||
matchesIgnorePlural(unit, QStringLiteral("week")))
|
||||
{
|
||||
return std::make_pair(60 * 60 * 24 * 7, true);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
return std::make_pair(0, false);
|
||||
}
|
||||
|
||||
} // namespace helpers::detail
|
||||
using namespace helpers::detail;
|
||||
|
||||
|
||||
+35
-35
@@ -18,44 +18,44 @@ namespace chatterino {
|
||||
// only qualified for tests
|
||||
namespace helpers::detail {
|
||||
|
||||
using SizeType = QStringView::size_type;
|
||||
using SizeType = QStringView::size_type;
|
||||
|
||||
/**
|
||||
* Skips all spaces.
|
||||
* The caller must guarantee view.at(startPos).isSpace().
|
||||
*
|
||||
* @param view The string to skip spaces in.
|
||||
* @param startPos The starting position (there must be a space in the view).
|
||||
* @return The position of the last space.
|
||||
*/
|
||||
SizeType skipSpace(QStringView view, SizeType startPos);
|
||||
/**
|
||||
* Skips all spaces.
|
||||
* The caller must guarantee view.at(startPos).isSpace().
|
||||
*
|
||||
* @param view The string to skip spaces in.
|
||||
* @param startPos The starting position (there must be a space in the view).
|
||||
* @return The position of the last space.
|
||||
*/
|
||||
SizeType skipSpace(QStringView view, SizeType startPos);
|
||||
|
||||
/**
|
||||
* Checks if `word` equals `expected` (singular) or `expected` + 's' (plural).
|
||||
*
|
||||
* @param word Word to test. Must not be empty.
|
||||
* @param expected Singular of the expected word.
|
||||
* @return true if `word` is singular or plural of `expected`.
|
||||
*/
|
||||
bool matchesIgnorePlural(QStringView word, const QString &expected);
|
||||
/**
|
||||
* Checks if `word` equals `expected` (singular) or `expected` + 's' (plural).
|
||||
*
|
||||
* @param word Word to test. Must not be empty.
|
||||
* @param expected Singular of the expected word.
|
||||
* @return true if `word` is singular or plural of `expected`.
|
||||
*/
|
||||
bool matchesIgnorePlural(QStringView word, const QString &expected);
|
||||
|
||||
/**
|
||||
* Tries to find the unit starting at `pos` and returns its multiplier so
|
||||
* `valueInUnit * multiplier = valueInSeconds` (e.g. 60 for minutes).
|
||||
*
|
||||
* Supported units are
|
||||
* 'w[eek(s)]', 'd[ay(s)]',
|
||||
* 'h[our(s)]', 'm[inute(s)]', 's[econd(s)]'.
|
||||
* The unit must be in lowercase.
|
||||
*
|
||||
* @param view A view into a string
|
||||
* @param pos The starting position.
|
||||
* This is set to the last position of the unit
|
||||
* if it's a valid unit, undefined otherwise.
|
||||
* @return (multiplier, ok)
|
||||
*/
|
||||
std::pair<uint64_t, bool> findUnitMultiplierToSec(QStringView view,
|
||||
SizeType &pos);
|
||||
/**
|
||||
* Tries to find the unit starting at `pos` and returns its multiplier so
|
||||
* `valueInUnit * multiplier = valueInSeconds` (e.g. 60 for minutes).
|
||||
*
|
||||
* Supported units are
|
||||
* 'w[eek(s)]', 'd[ay(s)]',
|
||||
* 'h[our(s)]', 'm[inute(s)]', 's[econd(s)]'.
|
||||
* The unit must be in lowercase.
|
||||
*
|
||||
* @param view A view into a string
|
||||
* @param pos The starting position.
|
||||
* This is set to the last position of the unit
|
||||
* if it's a valid unit, undefined otherwise.
|
||||
* @return (multiplier, ok)
|
||||
*/
|
||||
std::pair<uint64_t, bool> findUnitMultiplierToSec(QStringView view,
|
||||
SizeType &pos);
|
||||
|
||||
} // namespace helpers::detail
|
||||
|
||||
|
||||
@@ -5,45 +5,43 @@
|
||||
namespace chatterino {
|
||||
namespace rj {
|
||||
|
||||
void addMember(rapidjson::Value &obj, const char *key,
|
||||
rapidjson::Value &&value,
|
||||
rapidjson::Document::AllocatorType &a)
|
||||
void addMember(rapidjson::Value &obj, const char *key, rapidjson::Value &&value,
|
||||
rapidjson::Document::AllocatorType &a)
|
||||
{
|
||||
obj.AddMember(rapidjson::Value(key, a).Move(), value, a);
|
||||
}
|
||||
|
||||
void addMember(rapidjson::Value &obj, const char *key, rapidjson::Value &value,
|
||||
rapidjson::Document::AllocatorType &a)
|
||||
{
|
||||
obj.AddMember(rapidjson::Value(key, a).Move(), value.Move(), a);
|
||||
}
|
||||
|
||||
QString stringify(const rapidjson::Value &value)
|
||||
{
|
||||
rapidjson::StringBuffer buffer;
|
||||
rapidjson::Writer<rapidjson::StringBuffer> writer(buffer);
|
||||
value.Accept(writer);
|
||||
|
||||
return buffer.GetString();
|
||||
}
|
||||
|
||||
bool getSafeObject(rapidjson::Value &obj, const char *key,
|
||||
rapidjson::Value &out)
|
||||
{
|
||||
if (!checkJsonValue(obj, key))
|
||||
{
|
||||
obj.AddMember(rapidjson::Value(key, a).Move(), value, a);
|
||||
return false;
|
||||
}
|
||||
|
||||
void addMember(rapidjson::Value &obj, const char *key,
|
||||
rapidjson::Value &value,
|
||||
rapidjson::Document::AllocatorType &a)
|
||||
{
|
||||
obj.AddMember(rapidjson::Value(key, a).Move(), value.Move(), a);
|
||||
}
|
||||
out = obj[key].Move();
|
||||
return true;
|
||||
}
|
||||
|
||||
QString stringify(const rapidjson::Value &value)
|
||||
{
|
||||
rapidjson::StringBuffer buffer;
|
||||
rapidjson::Writer<rapidjson::StringBuffer> writer(buffer);
|
||||
value.Accept(writer);
|
||||
|
||||
return buffer.GetString();
|
||||
}
|
||||
|
||||
bool getSafeObject(rapidjson::Value &obj, const char *key,
|
||||
rapidjson::Value &out)
|
||||
{
|
||||
if (!checkJsonValue(obj, key))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
out = obj[key].Move();
|
||||
return true;
|
||||
}
|
||||
|
||||
bool checkJsonValue(const rapidjson::Value &obj, const char *key)
|
||||
{
|
||||
return obj.IsObject() && !obj.IsNull() && obj.HasMember(key);
|
||||
}
|
||||
bool checkJsonValue(const rapidjson::Value &obj, const char *key)
|
||||
{
|
||||
return obj.IsObject() && !obj.IsNull() && obj.HasMember(key);
|
||||
}
|
||||
|
||||
} // namespace rj
|
||||
} // namespace chatterino
|
||||
|
||||
@@ -11,91 +11,89 @@
|
||||
namespace chatterino {
|
||||
namespace rj {
|
||||
|
||||
void addMember(rapidjson::Value &obj, const char *key,
|
||||
rapidjson::Value &&value,
|
||||
rapidjson::Document::AllocatorType &a);
|
||||
void addMember(rapidjson::Value &obj, const char *key,
|
||||
rapidjson::Value &value,
|
||||
rapidjson::Document::AllocatorType &a);
|
||||
void addMember(rapidjson::Value &obj, const char *key, rapidjson::Value &&value,
|
||||
rapidjson::Document::AllocatorType &a);
|
||||
void addMember(rapidjson::Value &obj, const char *key, rapidjson::Value &value,
|
||||
rapidjson::Document::AllocatorType &a);
|
||||
|
||||
template <typename Type>
|
||||
void set(rapidjson::Value &obj, const char *key, const Type &value,
|
||||
rapidjson::Document::AllocatorType &a)
|
||||
template <typename Type>
|
||||
void set(rapidjson::Value &obj, const char *key, const Type &value,
|
||||
rapidjson::Document::AllocatorType &a)
|
||||
{
|
||||
assert(obj.IsObject());
|
||||
|
||||
addMember(obj, key, pajlada::Serialize<Type>::get(value, a), a);
|
||||
}
|
||||
|
||||
template <>
|
||||
inline void set(rapidjson::Value &obj, const char *key,
|
||||
const rapidjson::Value &value,
|
||||
rapidjson::Document::AllocatorType &a)
|
||||
{
|
||||
assert(obj.IsObject());
|
||||
|
||||
addMember(obj, key, const_cast<rapidjson::Value &>(value), a);
|
||||
}
|
||||
|
||||
template <typename Type>
|
||||
void set(rapidjson::Document &obj, const char *key, const Type &value)
|
||||
{
|
||||
assert(obj.IsObject());
|
||||
|
||||
auto &a = obj.GetAllocator();
|
||||
|
||||
addMember(obj, key, pajlada::Serialize<Type>::get(value, a), a);
|
||||
}
|
||||
|
||||
template <>
|
||||
inline void set(rapidjson::Document &obj, const char *key,
|
||||
const rapidjson::Value &value)
|
||||
{
|
||||
assert(obj.IsObject());
|
||||
|
||||
auto &a = obj.GetAllocator();
|
||||
|
||||
addMember(obj, key, const_cast<rapidjson::Value &>(value), a);
|
||||
}
|
||||
|
||||
template <typename Type>
|
||||
void add(rapidjson::Value &arr, const Type &value,
|
||||
rapidjson::Document::AllocatorType &a)
|
||||
{
|
||||
assert(arr.IsArray());
|
||||
|
||||
arr.PushBack(pajlada::Serialize<Type>::get(value, a), a);
|
||||
}
|
||||
|
||||
bool checkJsonValue(const rapidjson::Value &obj, const char *key);
|
||||
|
||||
template <typename Type>
|
||||
bool getSafe(const rapidjson::Value &obj, const char *key, Type &out)
|
||||
{
|
||||
if (!checkJsonValue(obj, key))
|
||||
{
|
||||
assert(obj.IsObject());
|
||||
|
||||
addMember(obj, key, pajlada::Serialize<Type>::get(value, a), a);
|
||||
return false;
|
||||
}
|
||||
|
||||
template <>
|
||||
inline void set(rapidjson::Value &obj, const char *key,
|
||||
const rapidjson::Value &value,
|
||||
rapidjson::Document::AllocatorType &a)
|
||||
{
|
||||
assert(obj.IsObject());
|
||||
bool error = false;
|
||||
out = pajlada::Deserialize<Type>::get(obj[key], &error);
|
||||
|
||||
addMember(obj, key, const_cast<rapidjson::Value &>(value), a);
|
||||
}
|
||||
return !error;
|
||||
}
|
||||
|
||||
template <typename Type>
|
||||
void set(rapidjson::Document &obj, const char *key, const Type &value)
|
||||
{
|
||||
assert(obj.IsObject());
|
||||
template <typename Type>
|
||||
bool getSafe(const rapidjson::Value &value, Type &out)
|
||||
{
|
||||
bool error = false;
|
||||
out = pajlada::Deserialize<Type>::get(value, &error);
|
||||
|
||||
auto &a = obj.GetAllocator();
|
||||
return !error;
|
||||
}
|
||||
|
||||
addMember(obj, key, pajlada::Serialize<Type>::get(value, a), a);
|
||||
}
|
||||
bool getSafeObject(rapidjson::Value &obj, const char *key,
|
||||
rapidjson::Value &out);
|
||||
|
||||
template <>
|
||||
inline void set(rapidjson::Document &obj, const char *key,
|
||||
const rapidjson::Value &value)
|
||||
{
|
||||
assert(obj.IsObject());
|
||||
|
||||
auto &a = obj.GetAllocator();
|
||||
|
||||
addMember(obj, key, const_cast<rapidjson::Value &>(value), a);
|
||||
}
|
||||
|
||||
template <typename Type>
|
||||
void add(rapidjson::Value &arr, const Type &value,
|
||||
rapidjson::Document::AllocatorType &a)
|
||||
{
|
||||
assert(arr.IsArray());
|
||||
|
||||
arr.PushBack(pajlada::Serialize<Type>::get(value, a), a);
|
||||
}
|
||||
|
||||
bool checkJsonValue(const rapidjson::Value &obj, const char *key);
|
||||
|
||||
template <typename Type>
|
||||
bool getSafe(const rapidjson::Value &obj, const char *key, Type &out)
|
||||
{
|
||||
if (!checkJsonValue(obj, key))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool error = false;
|
||||
out = pajlada::Deserialize<Type>::get(obj[key], &error);
|
||||
|
||||
return !error;
|
||||
}
|
||||
|
||||
template <typename Type>
|
||||
bool getSafe(const rapidjson::Value &value, Type &out)
|
||||
{
|
||||
bool error = false;
|
||||
out = pajlada::Deserialize<Type>::get(value, &error);
|
||||
|
||||
return !error;
|
||||
}
|
||||
|
||||
bool getSafeObject(rapidjson::Value &obj, const char *key,
|
||||
rapidjson::Value &out);
|
||||
|
||||
QString stringify(const rapidjson::Value &value);
|
||||
QString stringify(const rapidjson::Value &value);
|
||||
|
||||
} // namespace rj
|
||||
} // namespace chatterino
|
||||
|
||||
@@ -11,7 +11,7 @@ namespace chatterino {
|
||||
|
||||
#ifdef Q_OS_WIN
|
||||
namespace windows::detail {
|
||||
void renameThread(void *hThread, const QString &name);
|
||||
void renameThread(void *hThread, const QString &name);
|
||||
} // namespace windows::detail
|
||||
#endif
|
||||
|
||||
|
||||
+9
-9
@@ -11,16 +11,16 @@ namespace chatterino {
|
||||
|
||||
namespace {
|
||||
|
||||
const auto TWITCH_USER_LOGIN_PATTERN = R"(^[a-z0-9]\w{0,24}$)";
|
||||
const auto TWITCH_USER_LOGIN_PATTERN = R"(^[a-z0-9]\w{0,24}$)";
|
||||
|
||||
// Remember to keep VALID_HELIX_COLORS up-to-date if a new color is implemented to keep naming for users consistent
|
||||
const std::unordered_map<QString, QString> HELIX_COLOR_REPLACEMENTS{
|
||||
{"blueviolet", "blue_violet"}, {"cadetblue", "cadet_blue"},
|
||||
{"dodgerblue", "dodger_blue"}, {"goldenrod", "golden_rod"},
|
||||
{"hotpink", "hot_pink"}, {"orangered", "orange_red"},
|
||||
{"seagreen", "sea_green"}, {"springgreen", "spring_green"},
|
||||
{"yellowgreen", "yellow_green"},
|
||||
};
|
||||
// Remember to keep VALID_HELIX_COLORS up-to-date if a new color is implemented to keep naming for users consistent
|
||||
const std::unordered_map<QString, QString> HELIX_COLOR_REPLACEMENTS{
|
||||
{"blueviolet", "blue_violet"}, {"cadetblue", "cadet_blue"},
|
||||
{"dodgerblue", "dodger_blue"}, {"goldenrod", "golden_rod"},
|
||||
{"hotpink", "hot_pink"}, {"orangered", "orange_red"},
|
||||
{"seagreen", "sea_green"}, {"springgreen", "spring_green"},
|
||||
{"yellowgreen", "yellow_green"},
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
|
||||
Reference in New Issue
Block a user