Skip to content

Commit

Permalink
QString: toward UTF-8 arg() support [2/4]: port pattern to QAnyString…
Browse files Browse the repository at this point in the history
…View

The implementation of the pattern parser was already a template, and
the escape sequences are US-ASCII, so we can just reuse the
implementation 1:1. Just need to call it from QAnyStringView::visit().

Task-number: QTBUG-124365
Change-Id: Ifd7b7b73429ab04a13b9ee69e93763a995b1728b
Reviewed-by: Fabian Kosmale <[email protected]>
Reviewed-by: Thiago Macieira <[email protected]>
  • Loading branch information
marcmutz committed Nov 1, 2024
1 parent 28eefb0 commit cf8b9c1
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 9 deletions.
14 changes: 14 additions & 0 deletions src/corelib/compat/removed_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1273,6 +1273,20 @@ QByteArray QMetaEnum::valueToKeys(int value) const
return valueToKeys(quint64(uint(value)));
}


#include "qstring.h"

QString QtPrivate::argToQString(QStringView pattern, size_t n, const ArgBase **args)
{
return argToQString(QAnyStringView{pattern}, n, args);
}

QString QtPrivate::argToQString(QLatin1StringView pattern, size_t n, const ArgBase **args)
{
return argToQString(QAnyStringView{pattern}, n, args);
}


#include "quuid.h"

bool QUuid::isNull() const noexcept
Expand Down
11 changes: 4 additions & 7 deletions src/corelib/text/qstring.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9340,14 +9340,11 @@ static QString argToQStringImpl(StringView pattern, size_t numArgs, const QtPriv
return result;
}

QString QtPrivate::argToQString(QStringView pattern, size_t n, const ArgBase **args)
QString QtPrivate::argToQString(QAnyStringView pattern, size_t n, const ArgBase **args)
{
return argToQStringImpl(pattern, n, args);
}

QString QtPrivate::argToQString(QLatin1StringView pattern, size_t n, const ArgBase **args)
{
return argToQStringImpl(pattern, n, args);
return pattern.visit([n, args](auto pattern) {
return argToQStringImpl(pattern, n, args);
});
}

/*! \fn bool QString::isRightToLeft() const
Expand Down
7 changes: 5 additions & 2 deletions src/corelib/text/qstring.h
Original file line number Diff line number Diff line change
Expand Up @@ -1587,11 +1587,14 @@ struct QLatin1StringArg : ArgBase {
constexpr explicit QLatin1StringArg(QLatin1StringView v) noexcept : ArgBase{L1}, string{v} {}
};

#if QT_CORE_REMOVED_SINCE(6, 9)
[[nodiscard]] Q_CORE_EXPORT QString argToQString(QStringView pattern, size_t n, const ArgBase **args);
[[nodiscard]] Q_CORE_EXPORT QString argToQString(QLatin1StringView pattern, size_t n, const ArgBase **args);
#endif
[[nodiscard]] Q_CORE_EXPORT QString argToQString(QAnyStringView pattern, size_t n, const ArgBase **args);

template <typename StringView, typename...Args>
[[nodiscard]] Q_ALWAYS_INLINE QString argToQStringDispatch(StringView pattern, const Args &...args)
template <typename...Args>
[[nodiscard]] Q_ALWAYS_INLINE QString argToQStringDispatch(QAnyStringView pattern, const Args &...args)
{
const ArgBase *argBases[] = {&args..., /* avoid zero-sized array */ nullptr};
return QtPrivate::argToQString(pattern, sizeof...(Args), argBases);
Expand Down

0 comments on commit cf8b9c1

Please sign in to comment.