Migrate Remaining Chat Settings Commands to Helix API (#4040)

This commit is contained in:
nerix
2022-10-03 19:42:02 +02:00
committed by GitHub
parent 4c2e97bea6
commit 25bccc90b4
7 changed files with 846 additions and 39 deletions
+74
View File
@@ -2,11 +2,54 @@
#include <QColor>
#include <QString>
#include <QStringRef>
#include <cmath>
namespace chatterino {
// only qualified for tests
namespace _helpers_internal {
/**
* 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.
*/
int skipSpace(const QStringRef &view, int 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(const QStringRef &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(const QStringRef &view,
int &pos);
} // namespace _helpers_internal
/**
* @brief startsWithOrContains is a wrapper for checking
* whether str1 starts with or contains str2 within itself
@@ -29,6 +72,37 @@ QString kFormatNumbers(const int &number);
QColor getRandomColor(const QString &userId);
/**
* Parses a duration.
* Spaces are allowed before and after a unit but not mandatory.
* Supported units are
* 'w[eek(s)]', 'd[ay(s)]',
* 'h[our(s)]', 'm[inute(s)]', 's[econd(s)]'.
* Units must be lowercase.
*
* If the entire input string is a number (e.g. "12345"),
* then it's multiplied by noUnitMultiplier.
*
* Examples:
*
* - "1w 2h"
* - "1w 1w 0s 4d" (2weeks, 4days)
* - "5s3h4w" (4weeks, 3hours, 5seconds)
* - "30m"
* - "1 week"
* - "5 days 12 hours"
* - "10" (10 * noUnitMultiplier seconds)
*
* @param inputString A non-empty string to parse
* @param noUnitMultiplier A multiplier if the input string only contains one number.
* For example, if a number without a unit should be interpreted
* as a minute, set this to 60. If it should be interpreted
* as a second, set it to 1 (default).
* @return The parsed duration in seconds, -1 if the input is invalid.
*/
int64_t parseDurationToSeconds(const QString &inputString,
uint64_t noUnitMultiplier = 1);
/**
* @brief Takes a user's name and some formatting parameter and spits out the standardized way to format it
*