Port dbus from QStringRef to QStringView
Task-number: QTBUG-84319 Change-Id: Ifdfad6b7ac8b61ead71382e5ae3cb22b50b2504c Reviewed-by: Karsten Heimrich <karsten.heimrich@qt.io>
This commit is contained in:
parent
2393432cd0
commit
6bbfae9457
@ -890,7 +890,7 @@ bool QDBusConnection::registerObject(const QString &path, const QString &interfa
|
||||
if (!d || !d->connection || !object || !options || !QDBusUtil::isValidObjectPath(path))
|
||||
return false;
|
||||
|
||||
auto pathComponents = path.splitRef(QLatin1Char('/'));
|
||||
auto pathComponents = QStringView{path}.split(QLatin1Char('/'));
|
||||
if (pathComponents.constLast().isEmpty())
|
||||
pathComponents.removeLast();
|
||||
QDBusWriteLocker locker(RegisterObjectAction, d);
|
||||
@ -998,7 +998,7 @@ QObject *QDBusConnection::objectRegisteredAt(const QString &path) const
|
||||
if (!d || !d->connection || !QDBusUtil::isValidObjectPath(path))
|
||||
return nullptr;
|
||||
|
||||
auto pathComponents = path.splitRef(QLatin1Char('/'));
|
||||
auto pathComponents = QStringView{path}.split(QLatin1Char('/'));
|
||||
if (pathComponents.constLast().isEmpty())
|
||||
pathComponents.removeLast();
|
||||
|
||||
|
@ -156,8 +156,8 @@ public:
|
||||
: name(n), obj(nullptr), flags(0) { }
|
||||
inline bool operator<(const QString &other) const
|
||||
{ return name < other; }
|
||||
inline bool operator<(const QStringRef &other) const
|
||||
{ return QStringRef(&name) < other; }
|
||||
inline bool operator<(QStringView other) const
|
||||
{ return name < other; }
|
||||
inline bool isActive() const
|
||||
{ return obj || !children.isEmpty(); }
|
||||
|
||||
|
@ -392,7 +392,7 @@ static bool findObject(const QDBusConnectionPrivate::ObjectTreeNode *root,
|
||||
break;
|
||||
int end = fullpath.indexOf(QLatin1Char('/'), start);
|
||||
end = (end == -1 ? length : end);
|
||||
QStringRef pathComponent(&fullpath, start, end - start);
|
||||
QStringView pathComponent = QStringView{fullpath}.mid(start, end - start);
|
||||
|
||||
QDBusConnectionPrivate::ObjectTreeNode::DataList::ConstIterator it =
|
||||
std::lower_bound(node->children.constBegin(), node->children.constEnd(), pathComponent);
|
||||
@ -435,7 +435,7 @@ static QObject *findChildObject(const QDBusConnectionPrivate::ObjectTreeNode *ro
|
||||
|
||||
int pos = fullpath.indexOf(QLatin1Char('/'), start);
|
||||
pos = (pos == -1 ? length : pos);
|
||||
QStringRef pathComponent(&fullpath, start, pos - start);
|
||||
auto pathComponent = QStringView{fullpath}.mid(start, pos - start);
|
||||
|
||||
const QObjectList children = obj->children();
|
||||
|
||||
@ -604,7 +604,7 @@ static void huntAndDestroy(QObject *needle, QDBusConnectionPrivate::ObjectTreeNo
|
||||
}
|
||||
}
|
||||
|
||||
static void huntAndUnregister(const QVector<QStringRef> &pathComponents, int i, QDBusConnection::UnregisterMode mode,
|
||||
static void huntAndUnregister(const QVector<QStringView> &pathComponents, int i, QDBusConnection::UnregisterMode mode,
|
||||
QDBusConnectionPrivate::ObjectTreeNode *node)
|
||||
{
|
||||
if (pathComponents.count() == i) {
|
||||
@ -2410,12 +2410,12 @@ void QDBusConnectionPrivate::registerObject(const ObjectTreeNode *node)
|
||||
void QDBusConnectionPrivate::unregisterObject(const QString &path, QDBusConnection::UnregisterMode mode)
|
||||
{
|
||||
QDBusConnectionPrivate::ObjectTreeNode *node = &rootNode;
|
||||
QVector<QStringRef> pathComponents;
|
||||
QVector<QStringView> pathComponents;
|
||||
int i;
|
||||
if (path == QLatin1String("/")) {
|
||||
i = 0;
|
||||
} else {
|
||||
pathComponents = path.splitRef(QLatin1Char('/'));
|
||||
pathComponents = QStringView{path}.split(QLatin1Char('/'));
|
||||
i = 1;
|
||||
}
|
||||
|
||||
|
@ -95,7 +95,7 @@ QString qDBusInterfaceFromMetaObject(const QMetaObject *mo)
|
||||
} else {
|
||||
interface.prepend(QLatin1Char('.')).prepend(QCoreApplication::instance()->applicationName());
|
||||
const QString organizationDomain = QCoreApplication::instance()->organizationDomain();
|
||||
const auto domainName = organizationDomain.splitRef(QLatin1Char('.'), Qt::SkipEmptyParts);
|
||||
const auto domainName = QStringView{organizationDomain}.split(QLatin1Char('.'), Qt::SkipEmptyParts);
|
||||
if (domainName.isEmpty()) {
|
||||
interface.prepend(QLatin1String("local."));
|
||||
} else {
|
||||
|
@ -331,15 +331,15 @@ namespace QDBusUtil
|
||||
|
||||
/*!
|
||||
\internal
|
||||
\fn bool isValidPartOfObjectPath(const QStringRef &part)
|
||||
\fn bool isValidPartOfObjectPath(QStringView part)
|
||||
See isValidObjectPath
|
||||
*/
|
||||
bool isValidPartOfObjectPath(const QStringRef &part)
|
||||
bool isValidPartOfObjectPath(QStringView part)
|
||||
{
|
||||
if (part.isEmpty())
|
||||
return false; // can't be valid if it's empty
|
||||
|
||||
const QChar *c = part.unicode();
|
||||
const QChar *c = part.data();
|
||||
for (int i = 0; i < part.length(); ++i)
|
||||
if (!isValidCharacterNoDash(c[i]))
|
||||
return false;
|
||||
@ -372,11 +372,11 @@ namespace QDBusUtil
|
||||
if (ifaceName.isEmpty() || ifaceName.length() > DBUS_MAXIMUM_NAME_LENGTH)
|
||||
return false;
|
||||
|
||||
const auto parts = ifaceName.splitRef(QLatin1Char('.'));
|
||||
const auto parts = QStringView{ifaceName}.split(QLatin1Char('.'));
|
||||
if (parts.count() < 2)
|
||||
return false; // at least two parts
|
||||
|
||||
for (const QStringRef &part : parts)
|
||||
for (auto part : parts)
|
||||
if (!isValidMemberName(part))
|
||||
return false;
|
||||
|
||||
@ -384,13 +384,13 @@ namespace QDBusUtil
|
||||
}
|
||||
|
||||
/*!
|
||||
\fn bool isValidUniqueConnectionName(const QStringRef &connName)
|
||||
\fn bool isValidUniqueConnectionName(QStringView connName)
|
||||
Returns \c true if \a connName is a valid unique connection name.
|
||||
|
||||
Unique connection names start with a colon (":") and are followed by a list of dot-separated
|
||||
components composed of ASCII letters, digits, the hyphen or the underscore ("_") character.
|
||||
*/
|
||||
bool isValidUniqueConnectionName(const QStringRef &connName)
|
||||
bool isValidUniqueConnectionName(QStringView connName)
|
||||
{
|
||||
if (connName.isEmpty() || connName.length() > DBUS_MAXIMUM_NAME_LENGTH ||
|
||||
!connName.startsWith(QLatin1Char(':')))
|
||||
@ -400,11 +400,11 @@ namespace QDBusUtil
|
||||
if (parts.count() < 1)
|
||||
return false;
|
||||
|
||||
for (const QStringRef &part : parts) {
|
||||
for (QStringView part : parts) {
|
||||
if (part.isEmpty())
|
||||
return false;
|
||||
|
||||
const QChar* c = part.unicode();
|
||||
const QChar* c = part.data();
|
||||
for (int j = 0; j < part.length(); ++j)
|
||||
if (!isValidCharacter(c[j]))
|
||||
return false;
|
||||
@ -442,15 +442,15 @@ namespace QDBusUtil
|
||||
if (busName.startsWith(QLatin1Char(':')))
|
||||
return isValidUniqueConnectionName(busName);
|
||||
|
||||
const auto parts = busName.splitRef(QLatin1Char('.'));
|
||||
const auto parts = QStringView{busName}.split(QLatin1Char('.'));
|
||||
if (parts.count() < 1)
|
||||
return false;
|
||||
|
||||
for (const QStringRef &part : parts) {
|
||||
for (QStringView part : parts) {
|
||||
if (part.isEmpty())
|
||||
return false;
|
||||
|
||||
const QChar *c = part.unicode();
|
||||
const QChar *c = part.data();
|
||||
if (isValidNumber(c[0]))
|
||||
return false;
|
||||
for (int j = 0; j < part.length(); ++j)
|
||||
@ -462,17 +462,17 @@ namespace QDBusUtil
|
||||
}
|
||||
|
||||
/*!
|
||||
\fn bool isValidMemberName(const QStringRef &memberName)
|
||||
\fn bool isValidMemberName(QStringView memberName)
|
||||
Returns \c true if \a memberName is a valid member name. A valid member name does not exceed
|
||||
255 characters in length, is not empty, is composed only of ASCII letters, digits and
|
||||
underscores, but does not start with a digit.
|
||||
*/
|
||||
bool isValidMemberName(const QStringRef &memberName)
|
||||
bool isValidMemberName(QStringView memberName)
|
||||
{
|
||||
if (memberName.isEmpty() || memberName.length() > DBUS_MAXIMUM_NAME_LENGTH)
|
||||
return false;
|
||||
|
||||
const QChar* c = memberName.unicode();
|
||||
const QChar* c = memberName.data();
|
||||
if (isValidNumber(c[0]))
|
||||
return false;
|
||||
for (int j = 0; j < memberName.length(); ++j)
|
||||
@ -520,8 +520,8 @@ namespace QDBusUtil
|
||||
return false;
|
||||
|
||||
// it starts with /, so we skip the empty first part
|
||||
const auto parts = path.midRef(1).split(QLatin1Char('/'));
|
||||
for (const QStringRef &part : parts)
|
||||
const auto parts = QStringView{path}.mid(1).split(QLatin1Char('/'));
|
||||
for (QStringView part : parts)
|
||||
if (!isValidPartOfObjectPath(part))
|
||||
return false;
|
||||
|
||||
|
@ -68,18 +68,15 @@ namespace Q_DBUS_NO_EXPORT QDBusUtil
|
||||
{
|
||||
Q_DBUS_EXPORT bool isValidInterfaceName(const QString &ifaceName);
|
||||
|
||||
Q_DBUS_EXPORT bool isValidUniqueConnectionName(const QStringRef &busName);
|
||||
inline bool isValidUniqueConnectionName(const QString &busName) { return isValidUniqueConnectionName(QStringRef(&busName)); }
|
||||
Q_DBUS_EXPORT bool isValidUniqueConnectionName(QStringView busName);
|
||||
|
||||
Q_DBUS_EXPORT bool isValidBusName(const QString &busName);
|
||||
|
||||
Q_DBUS_EXPORT bool isValidMemberName(const QStringRef &memberName);
|
||||
inline bool isValidMemberName(const QString &memberName) { return isValidMemberName(QStringRef(&memberName)); }
|
||||
Q_DBUS_EXPORT bool isValidMemberName(QStringView memberName);
|
||||
|
||||
Q_DBUS_EXPORT bool isValidErrorName(const QString &errorName);
|
||||
|
||||
Q_DBUS_EXPORT bool isValidPartOfObjectPath(const QStringRef &path);
|
||||
inline bool isValidPartOfObjectPath(const QString &path) { return isValidPartOfObjectPath(QStringRef(&path)); }
|
||||
Q_DBUS_EXPORT bool isValidPartOfObjectPath(QStringView path);
|
||||
|
||||
Q_DBUS_EXPORT bool isValidObjectPath(const QString &path);
|
||||
|
||||
|
@ -186,12 +186,14 @@ static QString classNameForInterface(const QString &interface, ClassType classTy
|
||||
if (!globalClassName.isEmpty())
|
||||
return globalClassName;
|
||||
|
||||
const auto parts = interface.splitRef(QLatin1Char('.'));
|
||||
const auto parts = QStringView{interface}.split(QLatin1Char('.'));
|
||||
|
||||
QString retval;
|
||||
if (classType == Proxy) {
|
||||
for (const auto &part : parts)
|
||||
retval += part[0].toUpper() + part.mid(1);
|
||||
for (const auto &part : parts) {
|
||||
retval += part[0].toUpper();
|
||||
retval += part.mid(1);
|
||||
}
|
||||
} else {
|
||||
retval += parts.last()[0].toUpper() + parts.last().mid(1);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user