2019-07-23 22:18:36 +02:00
|
|
|
#pragma once
|
|
|
|
|
2021-07-08 19:09:31 +02:00
|
|
|
#include <QColor>
|
2019-08-10 13:47:17 +02:00
|
|
|
#include <QString>
|
2019-07-23 22:18:36 +02:00
|
|
|
|
2022-06-17 20:52:20 +02:00
|
|
|
#include <cmath>
|
|
|
|
|
2019-10-07 15:46:08 +02:00
|
|
|
namespace chatterino {
|
2019-07-23 22:18:36 +02:00
|
|
|
|
2021-12-26 14:21:52 +01:00
|
|
|
/**
|
|
|
|
* @brief startsWithOrContains is a wrapper for checking
|
|
|
|
* whether str1 starts with or contains str2 within itself
|
|
|
|
**/
|
|
|
|
bool startsWithOrContains(const QString &str1, const QString &str2,
|
|
|
|
Qt::CaseSensitivity caseSensitivity, bool startsWith);
|
|
|
|
|
2019-09-18 16:31:51 +02:00
|
|
|
QString generateUuid();
|
2019-07-23 22:18:36 +02:00
|
|
|
|
2019-09-18 16:31:51 +02:00
|
|
|
QString formatRichLink(const QString &url, bool file = false);
|
2019-07-23 22:18:36 +02:00
|
|
|
|
2019-09-18 16:31:51 +02:00
|
|
|
QString formatRichNamedLink(const QString &url, const QString &name,
|
|
|
|
bool file = false);
|
2019-07-23 22:18:36 +02:00
|
|
|
|
2019-08-10 13:47:17 +02:00
|
|
|
QString shortenString(const QString &str, unsigned maxWidth = 50);
|
2019-07-23 22:18:36 +02:00
|
|
|
|
2021-03-06 15:03:33 +01:00
|
|
|
QString localizeNumbers(const int &number);
|
|
|
|
|
2021-04-11 14:17:21 +02:00
|
|
|
QString kFormatNumbers(const int &number);
|
|
|
|
|
2021-07-08 19:09:31 +02:00
|
|
|
QColor getRandomColor(const QString &userId);
|
|
|
|
|
2021-07-24 12:01:50 +02:00
|
|
|
/**
|
|
|
|
* @brief Takes a user's name and some formatting parameter and spits out the standardized way to format it
|
|
|
|
*
|
|
|
|
* @param userName a user's name
|
|
|
|
* @param isFirstWord signifies whether this mention would be the first word in a message
|
|
|
|
* @param mentionUsersWithComma postfix mentions with a comma. generally powered by getSettings()->mentionUsersWithComma
|
|
|
|
**/
|
|
|
|
QString formatUserMention(const QString &userName, bool isFirstWord,
|
|
|
|
bool mentionUsersWithComma);
|
|
|
|
|
2022-06-17 20:52:20 +02:00
|
|
|
template <typename T>
|
|
|
|
std::vector<T> splitListIntoBatches(const T &list, int batchSize = 100)
|
|
|
|
{
|
|
|
|
std::vector<T> batches;
|
|
|
|
int batchCount = std::ceil(static_cast<double>(list.size()) / batchSize);
|
|
|
|
batches.reserve(batchCount);
|
|
|
|
|
|
|
|
auto it = list.cbegin();
|
|
|
|
|
|
|
|
for (int j = 0; j < batchCount; j++)
|
|
|
|
{
|
|
|
|
T batch;
|
|
|
|
|
|
|
|
for (int i = 0; i < batchSize && it != list.end(); i++)
|
|
|
|
{
|
|
|
|
batch.append(*it);
|
|
|
|
it++;
|
|
|
|
}
|
|
|
|
if (batch.empty())
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
batches.emplace_back(std::move(batch));
|
|
|
|
}
|
|
|
|
|
|
|
|
return batches;
|
|
|
|
}
|
|
|
|
|
2019-10-07 15:46:08 +02:00
|
|
|
} // namespace chatterino
|