Skip to content

Commit

Permalink
More qt6 fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Ri0n committed Mar 14, 2024
1 parent 9c74f6c commit 4feb01d
Show file tree
Hide file tree
Showing 14 changed files with 36 additions and 36 deletions.
2 changes: 1 addition & 1 deletion src/chatview_webkit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ class ChatViewPrivate {
auto match = it.next();
auto idStr = match.captured(1);
auto text = match.captured(2);
auto id = XMPP::Hash::from(QStringRef(&idStr));
auto id = XMPP::Hash::from(idStr);
auto item = account_->psi()->fileSharingManager()->item(id);

ret.append(QStringView{msg}.mid(post, match.capturedStart(0) - post));
Expand Down
2 changes: 1 addition & 1 deletion src/filecache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ FileCache::FileCache(const QString &cacheDir, QObject *parent) :
if (id.isEmpty())
continue;
auto hAlgo = _registry->getOption(prefix + ".ha", QString()).toString();
auto hash = XMPP::Hash(QStringRef(&hAlgo));
auto hash = XMPP::Hash(hAlgo);
if (!hash.isValid()) {
needCleanup = true;
continue;
Expand Down
2 changes: 1 addition & 1 deletion src/filesharinghttpproxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
FileSharingHttpProxy::FileSharingHttpProxy(PsiAccount *acc, const QString &sourceIdHex,
qhttp::server::QHttpRequest *req, qhttp::server::QHttpResponse *res) :
QObject(res),
item(acc->psi()->fileSharingManager()->item(XMPP::Hash::from(QStringRef(&sourceIdHex)))), acc(acc), request(req),
item(acc->psi()->fileSharingManager()->item(XMPP::Hash::from(sourceIdHex))), acc(acc), request(req),
response(res)
{
auto baseUrl = acc->psi()->webServer()->serverUrl().toString();
Expand Down
4 changes: 2 additions & 2 deletions src/filesharingmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ XMPP::Hash FileSharingDeviceOpener::urlToSourceId(const QUrl &url)
return XMPP::Hash();

QString path = url.path();
QStringRef sourceId(&path);
auto sourceId = QStringView{path};
if (sourceId.startsWith('/'))
sourceId = sourceId.mid(1);
return XMPP::Hash::from(sourceId);
Expand Down Expand Up @@ -389,5 +389,5 @@ QVariant FileSharingDeviceOpener::metadata(const QUrl &url)

FileSharingItem *FileSharingDeviceOpener::sharedItem(const QString &id)
{
return acc->psi()->fileSharingManager()->item(XMPP::Hash::from(QStringRef(&id)));
return acc->psi()->fileSharingManager()->item(XMPP::Hash::from(id));
}
2 changes: 1 addition & 1 deletion src/filesharingnamproxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
#include <tuple>

FileSharingNAMReply::FileSharingNAMReply(PsiAccount *acc, const QString &sourceIdHex, const QNetworkRequest &req) :
item(acc->psi()->fileSharingManager()->item(XMPP::Hash::from(QStringRef(&sourceIdHex)))), acc(acc)
item(acc->psi()->fileSharingManager()->item(XMPP::Hash::from(sourceIdHex))), acc(acc)
{
setRequest(req);
setOperation(QNetworkAccessManager::GetOperation); // TODO rewrite when we have others
Expand Down
2 changes: 1 addition & 1 deletion src/libpsi
4 changes: 2 additions & 2 deletions src/rtparse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ QString RTParse::next()

// if we're at a tag, append it to the output
if (in.at(v_at) == '<') {
QStringRef s;
QStringView s;
int n = in.indexOf('>', v_at);
if (n == -1) {
s = QStringView{in}.mid(v_at);
Expand All @@ -57,7 +57,7 @@ QString RTParse::next()
}

// now find the next tag, and grab the text in between
QStringRef s;
QStringView s;
int x = in.indexOf('<', v_at);
if (x == -1) {
s = QStringView{in}.mid(v_at);
Expand Down
6 changes: 3 additions & 3 deletions src/textutil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ QString TextUtil::rich2plain(const QString &in, bool collapseSpaces)
return out;
}

QString TextUtil::resolveEntities(const QStringRef &in)
QString TextUtil::resolveEntities(const QStringView &in)
{
QString out;

Expand All @@ -203,7 +203,7 @@ QString TextUtil::resolveEntities(const QStringRef &in)
int n = in.indexOf(';', i);
if (n == -1)
break;
QStringRef type = in.mid(i, (n - i));
auto type = in.mid(i, (n - i));

i = n; // should be n+1, but we'll let the loop increment do it

Expand Down Expand Up @@ -290,7 +290,7 @@ static void emojiconifyPlainText(RTParse &p, const QString &in)
const auto &reg = EmojiRegistry::instance();
int idx = 0;
int emojisStartIdx = -1;
QStringRef ref;
QStringView ref;

auto dump_emoji = [&p, &emojisStartIdx, &in, &idx]() {
#if defined(WEBKIT) || defined(WEBENGINE)
Expand Down
4 changes: 2 additions & 2 deletions src/textutil.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include <QtGlobal>

class QString;
class QStringRef;
class QStringView;

namespace TextUtil {

Expand All @@ -14,7 +14,7 @@ QString unescape(const QString &escaped);
QString quote(const QString &, int width = 60, bool quoteEmpty = false);
QString plain2rich(const QString &);
QString rich2plain(const QString &, bool collapseSpaces = true);
QString resolveEntities(const QStringRef &);
QString resolveEntities(const QStringView &);
QString linkify(const QString &);
QString legacyFormat(const QString &);
QString emoticonify(const QString &in);
Expand Down
8 changes: 4 additions & 4 deletions src/widgets/emojiregistry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ bool EmojiRegistry::isEmoji(const QString &code) const
// TODO check the whole code is emoji. not just start
}

EmojiRegistry::Category EmojiRegistry::startCategory(QStringRef in) const
EmojiRegistry::Category EmojiRegistry::startCategory(QStringView in) const
{
if (in.isEmpty())
return Category::None;
Expand Down Expand Up @@ -85,15 +85,15 @@ int EmojiRegistry::count() const
return count;
}

QStringRef EmojiRegistry::findEmoji(const QString &in, int idx) const
QStringView EmojiRegistry::findEmoji(const QString &in, int idx) const
{
int emojiStart = -1;

bool gotEmoji = false;
bool gotSkin = false;
bool gotFQ = false;
for (; idx < in.size(); idx++) {
auto category = startCategory(QStringRef(&in, idx, in.size() - idx));
auto category = startCategory(QStringView{in}.mid(idx, in.size() - idx));
if (gotEmoji && category != Category::None) {
if (category == Category::ZWJ) { // zero-width joiner
gotEmoji = false;
Expand Down Expand Up @@ -130,7 +130,7 @@ QStringRef EmojiRegistry::findEmoji(const QString &in, int idx) const
if (in[idx].isHighSurrogate())
idx++;
}
return emojiStart == -1 ? QStringRef() : QStringRef(&in, emojiStart, idx - emojiStart);
return emojiStart == -1 ? QStringView() : QStringView{in}.mid(emojiStart, idx - emojiStart);
}

EmojiRegistry::EmojiRegistry() : groups(std::move(db)), ranges_(std::move(ranges)) { }
Expand Down
4 changes: 2 additions & 2 deletions src/widgets/emojiregistry.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,14 @@ class EmojiRegistry {
bool isEmoji(const QString &code) const;

/// Find emoji in a string starting from the specified position
QStringRef findEmoji(const QString &in, int startPos = 0) const;
QStringView findEmoji(const QString &in, int startPos = 0) const;

/*!
* \brief startCategory returns category of what the string starts with if the sequence looks valida for emoji
* \param in
* \return category
*/
Category startCategory(QStringRef in) const;
Category startCategory(QStringView in) const;
int count() const;

struct iterator {
Expand Down
24 changes: 12 additions & 12 deletions src/widgets/psirichtext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ typedef QQueue<QTextCharFormat *> TextCharFormatQueue;
* Adds null format to queue for all ObjectReplacementCharacters that were
* already in the text. Returns passed \param text to save some code.
*/
static QStringRef preserveOriginalObjectReplacementCharacters(const QStringRef &text, TextCharFormatQueue *queue)
static QStringView preserveOriginalObjectReplacementCharacters(const QStringView &text, TextCharFormatQueue *queue)
{
int objReplChars = 0;
objReplChars += text.count(QChar::ObjectReplacementCharacter);
Expand All @@ -267,7 +267,7 @@ static QStringRef preserveOriginalObjectReplacementCharacters(const QStringRef &
// But we must be careful if some other character instead of
// 0x20 is used immediately after tag opening, this could
// create a hole. ejabberd protects us from it though.
objReplChars += text.count("<img ");
objReplChars += text.count(QLatin1StringView{"<img "});
for (int i = objReplChars; i; i--) {
queue->enqueue(nullptr);
}
Expand All @@ -280,30 +280,30 @@ static QStringRef preserveOriginalObjectReplacementCharacters(const QStringRef &
* adds appropriate format to the \param queue. Returns processed
* \param text.
*/
static QString convertIconsToObjectReplacementCharacters(const QStringRef &text, TextCharFormatQueue *queue,
static QString convertIconsToObjectReplacementCharacters(const QStringView &text, TextCharFormatQueue *queue,
int insertedAfter, const PsiRichText::ParsersMap &parsers)
{
QString result;
QStringRef work(text);
QStringView work(text);

int start = -1;
forever
{
start = work.indexOf("<", start + 1);
start = work.indexOf(QLatin1Char('<'), start + 1);
if (start == -1)
break;
if (work.mid(start + 1, 4) == "icon") {
if (work.mid(start + 1, 4) == QLatin1StringView{"icon"}) {
// Format: <icon name="" text="">
static QRegularExpression rxName("name=\"([^\"]+)\"");
static QRegularExpression rxText("text=\"([^\"]+)\"");
static QRegularExpression rxSize("size=\"([^\"]+)\"");

result += preserveOriginalObjectReplacementCharacters(work.left(start), queue);

int end = work.indexOf(">", start);
int end = work.indexOf(QLatin1Char{'>'}, start);
Q_ASSERT(end != -1);

QStringRef fragment = work.mid(start, end - start);
QStringView fragment = work.mid(start, end - start);
auto matchName = rxName.match(fragment);
if (matchName.hasMatch()) {
#ifndef WIDGET_PLUGIN
Expand Down Expand Up @@ -341,17 +341,17 @@ static QString convertIconsToObjectReplacementCharacters(const QStringRef &text,
// if parsers key matches with html element name
result += preserveOriginalObjectReplacementCharacters(work.left(start), queue);

int end = work.indexOf(">", start);
int end = work.indexOf(QLatin1Char{'>'}, start);
Q_ASSERT(end != -1);

// take attributes part of the tag
QStringRef fragment = work.mid(start + it.key().length() + 1, end - start - it.key().length() - 1);
auto fragment = work.mid(start + it.key().length() + 1, end - start - it.key().length() - 1);
QString replaceHtml;
QTextCharFormat charFormat;

std::tie(charFormat, replaceHtml) = it.value()(fragment, insertedAfter);
if (replaceHtml.size()) {
result += convertIconsToObjectReplacementCharacters(QStringRef(&replaceHtml), queue,
result += convertIconsToObjectReplacementCharacters(replaceHtml, queue,
insertedAfter, parsers);
}
if (charFormat.isValid()) {
Expand Down Expand Up @@ -464,7 +464,7 @@ static void appendTextHelper(QTextDocument *doc, QString text, QTextCursor &curs
}

cursor.insertFragment(QTextDocumentFragment::fromHtml(
convertIconsToObjectReplacementCharacters(QStringRef(&text), &queue, cursor.position(), parsers)));
convertIconsToObjectReplacementCharacters(text, &queue, cursor.position(), parsers)));
cursor.setPosition(initialpos);

applyFormatToIcons(doc, &queue, cursor);
Expand Down
2 changes: 1 addition & 1 deletion src/widgets/psirichtext.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class ITEMediaOpener;
class PsiRichText {
public:
using ParserRet = std::pair<QTextCharFormat, QString>;
using Parser = std::function<ParserRet(const QStringRef &htmlElement, int insertAfter)>;
using Parser = std::function<ParserRet(const QStringView &htmlElement, int insertAfter)>;
using ParsersMap = QMap<QString, Parser>;

static void install(QTextDocument *doc);
Expand Down
6 changes: 3 additions & 3 deletions src/widgets/psitextview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class PsiTextView::Private : public QObject {
// handler function accepts everything after tag name upto but exluding final ">"
PsiRichText::ParsersMap objectParsers;

QMap<QString, QString> parseHtmlAttrs(const QStringRef &html)
QMap<QString, QString> parseHtmlAttrs(const QStringView &html)
{
static QRegularExpression attrStart("([a-zA-Z0-9]+)=([\"'])((.(?!\\2))*.)\\2");
// static QRegularExpression attrStart("([a-zA-Z0-9]+)=([\"'])([^\"']*)\\2");
Expand Down Expand Up @@ -108,7 +108,7 @@ span.emojis {

d->objectParsers = PsiRichText::ParsersMap {
{ "share",
[this](const QStringRef &html, int insertAfter) -> PsiRichText::ParserRet {
[this](const QStringView &html, int insertAfter) -> PsiRichText::ParserRet {
if (!d->mediaOpener)
return { QTextCharFormat(), "" };
auto attrs = d->parseHtmlAttrs(html);
Expand Down Expand Up @@ -199,7 +199,7 @@ span.emojis {
return { QTextCharFormat(), "" };
} },
{ "marker",
[this](const QStringRef &html, int) -> PsiRichText::ParserRet {
[this](const QStringView &html, int) -> PsiRichText::ParserRet {
auto attrs = d->parseHtmlAttrs(html);
auto id = attrs.value("id");
return { PsiRichText::markerFormat(id), QString() };
Expand Down

0 comments on commit 4feb01d

Please sign in to comment.