feat(eventsub): implement automod message hold (#6005)
This commit is contained in:
@@ -333,4 +333,39 @@ QDateTime chronoToQDateTime(std::chrono::system_clock::time_point time)
|
||||
return dt;
|
||||
}
|
||||
|
||||
QStringView codepointSlice(QStringView str, qsizetype begin, qsizetype end)
|
||||
{
|
||||
if (end <= begin || begin < 0)
|
||||
{
|
||||
return {};
|
||||
}
|
||||
|
||||
qsizetype n = 0;
|
||||
const QChar *pos = str.begin();
|
||||
const QChar *endPos = str.end();
|
||||
|
||||
const QChar *sliceBegin = nullptr;
|
||||
while (n < end)
|
||||
{
|
||||
if (pos >= endPos)
|
||||
{
|
||||
return {};
|
||||
}
|
||||
if (n == begin)
|
||||
{
|
||||
sliceBegin = pos;
|
||||
}
|
||||
|
||||
QChar cur = *pos++;
|
||||
if (cur.isHighSurrogate() && pos < endPos && pos->isLowSurrogate())
|
||||
{
|
||||
pos++;
|
||||
}
|
||||
n++;
|
||||
}
|
||||
assert(pos <= endPos);
|
||||
|
||||
return {sliceBegin, pos};
|
||||
}
|
||||
|
||||
} // namespace chatterino
|
||||
|
||||
@@ -199,4 +199,13 @@ QLocale getSystemLocale();
|
||||
/// Note: When running tests, this will always return a date-time in UTC.
|
||||
QDateTime chronoToQDateTime(std::chrono::system_clock::time_point time);
|
||||
|
||||
/// Slices a string based on codepoint indices.
|
||||
///
|
||||
/// If the specified range is outside the string, an empty string view is
|
||||
/// returned.
|
||||
///
|
||||
/// @param begin Start index (inclusive, in codepoints)
|
||||
/// @param end End index (exclusive, in codepoints)
|
||||
QStringView codepointSlice(QStringView str, qsizetype begin, qsizetype end);
|
||||
|
||||
} // namespace chatterino
|
||||
|
||||
Reference in New Issue
Block a user