Use StringViewMid adapter
This commit is contained in:
parent
64e40913df
commit
ee36b1f451
7 changed files with 34 additions and 26 deletions
|
|
@ -10,6 +10,7 @@
|
|||
#include "ui/text/text_entity.h"
|
||||
#include "ui/integration.h"
|
||||
#include "base/qthelp_url.h"
|
||||
#include "base/qt_adapters.h"
|
||||
|
||||
#include <QtCore/QUrl>
|
||||
#include <QtCore/QRegularExpression>
|
||||
|
|
@ -104,7 +105,7 @@ QString UrlClickHandler::ShowEncoded(const QString &url) {
|
|||
if (const auto u = QUrl(domain); u.isValid()) {
|
||||
return QString(
|
||||
).append(QString::fromUtf8(u.toEncoded())
|
||||
).append(QStringView(url).mid(match1.capturedEnd(2)));
|
||||
).append(base::StringViewMid(url, match1.capturedEnd(2)));
|
||||
}
|
||||
}
|
||||
return url;
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@
|
|||
|
||||
#include "base/basic_types.h"
|
||||
#include "base/binary_guard.h"
|
||||
#include "base/qt_adapters.h"
|
||||
#include "emoji.h"
|
||||
|
||||
#include <QtGui/QPainter>
|
||||
|
|
@ -118,7 +119,7 @@ private:
|
|||
[[nodiscard]] inline EmojiPtr FromUrl(const QString &url) {
|
||||
auto start = qstr("emoji://e.");
|
||||
if (url.startsWith(start)) {
|
||||
return internal::ByIndex(QStringView(url).mid(start.size()).toInt()); // skip emoji://e.
|
||||
return internal::ByIndex(base::StringViewMid(url, start.size()).toInt()); // skip emoji://e.
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@
|
|||
#include "ui/emoji_config.h"
|
||||
#include "ui/integration.h"
|
||||
#include "base/platform/base_platform_info.h"
|
||||
#include "base/qt_adapters.h"
|
||||
|
||||
#include <private/qfontengine_p.h>
|
||||
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
|
||||
|
|
@ -3164,7 +3165,7 @@ void String::enumerateText(TextSelection selection, AppendPartCallback appendPar
|
|||
auto rangeFrom = qMax(selection.from, lnkFrom);
|
||||
auto rangeTo = qMin(selection.to, blockFrom);
|
||||
if (rangeTo > rangeFrom) { // handle click handler
|
||||
const auto r = QStringView(_text).mid(rangeFrom, rangeTo - rangeFrom);
|
||||
const auto r = base::StringViewMid(_text, rangeFrom, rangeTo - rangeFrom);
|
||||
if (lnkFrom != rangeFrom || blockFrom != rangeTo) {
|
||||
// Ignore links that are partially copied.
|
||||
clickHandlerFinishCallback(r, nullptr);
|
||||
|
|
@ -3195,7 +3196,7 @@ void String::enumerateText(TextSelection selection, AppendPartCallback appendPar
|
|||
auto rangeFrom = qMax(selection.from, blockFrom);
|
||||
auto rangeTo = qMin(selection.to, uint16(blockFrom + countBlockLength(i, e)));
|
||||
if (rangeTo > rangeFrom) {
|
||||
appendPartCallback(QStringView(_text).mid(rangeFrom, rangeTo - rangeFrom));
|
||||
appendPartCallback(base::StringViewMid(_text, rangeFrom, rangeTo - rangeFrom));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@
|
|||
#include "ui/text/text.h"
|
||||
#include "ui/widgets/input_fields.h"
|
||||
#include "ui/emoji_config.h"
|
||||
#include "base/qt_adapters.h"
|
||||
|
||||
#include <QtCore/QStack>
|
||||
#include <QtCore/QMimeData>
|
||||
|
|
@ -1155,13 +1156,13 @@ const QRegularExpression &RegExpWordSplit() {
|
|||
for (const auto &entity : urls) {
|
||||
const auto till = entity.offset() + entity.length();
|
||||
if (till > offset) {
|
||||
result.append(QStringView(original).mid(offset, till - offset));
|
||||
result.append(base::StringViewMid(original, offset, till - offset));
|
||||
}
|
||||
result.append(qstr(" (")).append(entity.data()).append(')');
|
||||
offset = till;
|
||||
}
|
||||
if (original.size() > offset) {
|
||||
result.append(QStringView(original).mid(offset));
|
||||
result.append(base::StringViewMid(original, offset));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
|
@ -2051,7 +2052,7 @@ QString TagWithRemoved(const QString &tag, const QString &removed) {
|
|||
return QString();
|
||||
}
|
||||
auto list = QStringView(tag).split('|');
|
||||
list.erase(ranges::remove(list, QStringView(removed).mid(0)), list.end());
|
||||
list.erase(ranges::remove(list, QStringView(removed)), list.end());
|
||||
return JoinTag(list);
|
||||
}
|
||||
|
||||
|
|
@ -2060,7 +2061,7 @@ QString TagWithAdded(const QString &tag, const QString &added) {
|
|||
return added;
|
||||
}
|
||||
auto list = QStringView(tag).split('|');
|
||||
const auto ref = QStringView(added).mid(0);
|
||||
const auto ref = QStringView(added);
|
||||
if (list.contains(ref)) {
|
||||
return tag;
|
||||
}
|
||||
|
|
@ -2155,7 +2156,7 @@ EntitiesInText ConvertTextTagsToEntities(const TextWithTags::Tags &tags) {
|
|||
if (IsMentionLink(nextState.link)) {
|
||||
const auto match = qthelp::regex_match(
|
||||
"^(\\d+\\.\\d+)(/|$)",
|
||||
QStringView(nextState.link).mid(kMentionTagStart.size()));
|
||||
base::StringViewMid(nextState.link, kMentionTagStart.size()));
|
||||
if (match) {
|
||||
openType(EntityType::MentionName, match->captured(1));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@
|
|||
#include "ui/text/text_utilities.h"
|
||||
|
||||
#include "base/algorithm.h"
|
||||
#include "base/qt_adapters.h"
|
||||
|
||||
#include <QtCore/QRegularExpression>
|
||||
|
||||
|
|
@ -49,7 +50,7 @@ TextWithEntities RichLangValue(const QString &text) {
|
|||
while (offset < text.size()) {
|
||||
const auto m = kStart.match(text, offset);
|
||||
if (!m.hasMatch()) {
|
||||
result.text.append(QStringView(text).mid(offset));
|
||||
result.text.append(base::StringViewMid(text, offset));
|
||||
break;
|
||||
}
|
||||
const auto position = m.capturedStart();
|
||||
|
|
@ -61,13 +62,13 @@ TextWithEntities RichLangValue(const QString &text) {
|
|||
continue;
|
||||
}
|
||||
if (position > offset) {
|
||||
result.text.append(QStringView(text).mid(offset, position - offset));
|
||||
result.text.append(base::StringViewMid(text, offset, position - offset));
|
||||
}
|
||||
const auto type = (tag == qstr("__"))
|
||||
? EntityType::Italic
|
||||
: EntityType::Bold;
|
||||
result.entities.push_back({ type, int(result.text.size()), int(till - from) });
|
||||
result.text.append(QStringView(text).mid(from, till - from));
|
||||
result.text.append(base::StringViewMid(text, from, till - from));
|
||||
offset = till + tag.size();
|
||||
}
|
||||
return result;
|
||||
|
|
|
|||
|
|
@ -126,20 +126,20 @@ bool IsNewline(QChar ch) {
|
|||
}
|
||||
auto found = false;
|
||||
for (const auto &single : QStringView(existing.id).split('|')) {
|
||||
const auto normalized = (single == QStringView(kTagPre).mid(0))
|
||||
? QStringView(kTagCode).mid(0)
|
||||
const auto normalized = (single == QStringView(kTagPre))
|
||||
? QStringView(kTagCode)
|
||||
: single;
|
||||
if (checkingLink && IsValidMarkdownLink(single)) {
|
||||
if (resultLink.isEmpty()) {
|
||||
resultLink = single.toString();
|
||||
found = true;
|
||||
break;
|
||||
} else if (QStringView(resultLink).mid(0) == single) {
|
||||
} else if (QStringView(resultLink) == single) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
return QString();
|
||||
} else if (!checkingLink && QStringView(tag).mid(0) == normalized) {
|
||||
} else if (!checkingLink && QStringView(tag) == normalized) {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
|
|
@ -2566,7 +2566,7 @@ TextWithTags InputField::getTextWithAppliedMarkdown() const {
|
|||
auto from = 0;
|
||||
const auto addOriginalTextUpTill = [&](int offset) {
|
||||
if (offset > from) {
|
||||
result.text.append(QStringView(originalText).mid(from, offset - from));
|
||||
result.text.append(base::StringViewMid(originalText, from, offset - from));
|
||||
}
|
||||
};
|
||||
auto link = links.begin();
|
||||
|
|
@ -2622,7 +2622,8 @@ TextWithTags InputField::getTextWithAppliedMarkdown() const {
|
|||
int(result.text.size()),
|
||||
entityLength,
|
||||
tag.tag });
|
||||
result.text.append(QStringView(originalText).mid(
|
||||
result.text.append(base::StringViewMid(
|
||||
originalText,
|
||||
entityStart,
|
||||
entityLength));
|
||||
}
|
||||
|
|
@ -2898,7 +2899,7 @@ auto InputField::selectionEditLinkData(EditLinkSelection selection) const
|
|||
const auto stateTagHasLink = [&](const State &state) {
|
||||
const auto tag = stateTag(state);
|
||||
return (tag == link) || QStringView(tag).split('|').contains(
|
||||
QStringView(link).mid(0));
|
||||
QStringView(link));
|
||||
};
|
||||
const auto stateStart = [&](const State &state) {
|
||||
return state.i.fragment().position();
|
||||
|
|
@ -3107,8 +3108,8 @@ void InputField::commitInstantReplacement(
|
|||
kTagProperty
|
||||
).toString();
|
||||
const auto currentTags = QStringView(currentTag).split('|');
|
||||
if (currentTags.contains(QStringView(kTagPre).mid(0))
|
||||
|| currentTags.contains(QStringView(kTagCode).mid(0))) {
|
||||
if (currentTags.contains(QStringView(kTagPre))
|
||||
|| currentTags.contains(QStringView(kTagCode))) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
|
@ -3157,7 +3158,8 @@ bool InputField::commitMarkdownReplacement(
|
|||
const auto extended = getTextWithTagsPart(
|
||||
from - extendLeft,
|
||||
till + extendRight).text;
|
||||
const auto outer = QStringView(extended).mid(
|
||||
const auto outer = base::StringViewMid(
|
||||
extended,
|
||||
extendLeft,
|
||||
extended.size() - extendLeft - extendRight);
|
||||
if ((outer.size() <= 2 * edge.size())
|
||||
|
|
@ -3221,7 +3223,7 @@ bool InputField::commitMarkdownReplacement(
|
|||
if (tagTill > tagFrom) {
|
||||
_insertedTags.push_back({
|
||||
tagFrom,
|
||||
tagTill - tagFrom,
|
||||
int(tagTill - tagFrom),
|
||||
tag,
|
||||
});
|
||||
}
|
||||
|
|
@ -3333,7 +3335,7 @@ void InputField::commitMarkdownLinkEdit(
|
|||
return;
|
||||
}
|
||||
_insertedTags.clear();
|
||||
_insertedTags.push_back({ 0, text.size(), link });
|
||||
_insertedTags.push_back({ 0, int(text.size()), link });
|
||||
|
||||
auto cursor = textCursor();
|
||||
const auto editData = selectionEditLinkData(selection);
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@
|
|||
|
||||
#include "ui/widgets/input_fields.h"
|
||||
#include "ui/ui_utility.h"
|
||||
#include "base/qt_adapters.h"
|
||||
|
||||
#include <QtCore/QRegularExpression>
|
||||
#include <QTime>
|
||||
|
|
@ -24,7 +25,7 @@ QTime ValidateTime(const QString &value) {
|
|||
const auto readInt = [](const QString &value) {
|
||||
auto view = QStringView(value);
|
||||
while (!view.isEmpty() && view.at(0) == '0') {
|
||||
view = view.mid(1);
|
||||
view = base::StringViewMid(view, 1);
|
||||
}
|
||||
return view.toInt();
|
||||
};
|
||||
|
|
@ -80,7 +81,7 @@ std::optional<int> Number(not_null<TimePart*> field) {
|
|||
const auto text = field->getLastText();
|
||||
auto view = QStringView(text);
|
||||
while (view.size() > 1 && view.at(0) == '0') {
|
||||
view = view.mid(1);
|
||||
view = base::StringViewMid(view, 1);
|
||||
}
|
||||
return QRegularExpression("^\\d+$").match(view).hasMatch()
|
||||
? std::make_optional(view.toInt())
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue