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))
|
if (!d || !d->connection || !object || !options || !QDBusUtil::isValidObjectPath(path))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
auto pathComponents = path.splitRef(QLatin1Char('/'));
|
auto pathComponents = QStringView{path}.split(QLatin1Char('/'));
|
||||||
if (pathComponents.constLast().isEmpty())
|
if (pathComponents.constLast().isEmpty())
|
||||||
pathComponents.removeLast();
|
pathComponents.removeLast();
|
||||||
QDBusWriteLocker locker(RegisterObjectAction, d);
|
QDBusWriteLocker locker(RegisterObjectAction, d);
|
||||||
@ -998,7 +998,7 @@ QObject *QDBusConnection::objectRegisteredAt(const QString &path) const
|
|||||||
if (!d || !d->connection || !QDBusUtil::isValidObjectPath(path))
|
if (!d || !d->connection || !QDBusUtil::isValidObjectPath(path))
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
||||||
auto pathComponents = path.splitRef(QLatin1Char('/'));
|
auto pathComponents = QStringView{path}.split(QLatin1Char('/'));
|
||||||
if (pathComponents.constLast().isEmpty())
|
if (pathComponents.constLast().isEmpty())
|
||||||
pathComponents.removeLast();
|
pathComponents.removeLast();
|
||||||
|
|
||||||
|
@ -156,8 +156,8 @@ public:
|
|||||||
: name(n), obj(nullptr), flags(0) { }
|
: name(n), obj(nullptr), flags(0) { }
|
||||||
inline bool operator<(const QString &other) const
|
inline bool operator<(const QString &other) const
|
||||||
{ return name < other; }
|
{ return name < other; }
|
||||||
inline bool operator<(const QStringRef &other) const
|
inline bool operator<(QStringView other) const
|
||||||
{ return QStringRef(&name) < other; }
|
{ return name < other; }
|
||||||
inline bool isActive() const
|
inline bool isActive() const
|
||||||
{ return obj || !children.isEmpty(); }
|
{ return obj || !children.isEmpty(); }
|
||||||
|
|
||||||
|
@ -392,7 +392,7 @@ static bool findObject(const QDBusConnectionPrivate::ObjectTreeNode *root,
|
|||||||
break;
|
break;
|
||||||
int end = fullpath.indexOf(QLatin1Char('/'), start);
|
int end = fullpath.indexOf(QLatin1Char('/'), start);
|
||||||
end = (end == -1 ? length : end);
|
end = (end == -1 ? length : end);
|
||||||
QStringRef pathComponent(&fullpath, start, end - start);
|
QStringView pathComponent = QStringView{fullpath}.mid(start, end - start);
|
||||||
|
|
||||||
QDBusConnectionPrivate::ObjectTreeNode::DataList::ConstIterator it =
|
QDBusConnectionPrivate::ObjectTreeNode::DataList::ConstIterator it =
|
||||||
std::lower_bound(node->children.constBegin(), node->children.constEnd(), pathComponent);
|
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);
|
int pos = fullpath.indexOf(QLatin1Char('/'), start);
|
||||||
pos = (pos == -1 ? length : pos);
|
pos = (pos == -1 ? length : pos);
|
||||||
QStringRef pathComponent(&fullpath, start, pos - start);
|
auto pathComponent = QStringView{fullpath}.mid(start, pos - start);
|
||||||
|
|
||||||
const QObjectList children = obj->children();
|
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)
|
QDBusConnectionPrivate::ObjectTreeNode *node)
|
||||||
{
|
{
|
||||||
if (pathComponents.count() == i) {
|
if (pathComponents.count() == i) {
|
||||||
@ -2410,12 +2410,12 @@ void QDBusConnectionPrivate::registerObject(const ObjectTreeNode *node)
|
|||||||
void QDBusConnectionPrivate::unregisterObject(const QString &path, QDBusConnection::UnregisterMode mode)
|
void QDBusConnectionPrivate::unregisterObject(const QString &path, QDBusConnection::UnregisterMode mode)
|
||||||
{
|
{
|
||||||
QDBusConnectionPrivate::ObjectTreeNode *node = &rootNode;
|
QDBusConnectionPrivate::ObjectTreeNode *node = &rootNode;
|
||||||
QVector<QStringRef> pathComponents;
|
QVector<QStringView> pathComponents;
|
||||||
int i;
|
int i;
|
||||||
if (path == QLatin1String("/")) {
|
if (path == QLatin1String("/")) {
|
||||||
i = 0;
|
i = 0;
|
||||||
} else {
|
} else {
|
||||||
pathComponents = path.splitRef(QLatin1Char('/'));
|
pathComponents = QStringView{path}.split(QLatin1Char('/'));
|
||||||
i = 1;
|
i = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -95,7 +95,7 @@ QString qDBusInterfaceFromMetaObject(const QMetaObject *mo)
|
|||||||
} else {
|
} else {
|
||||||
interface.prepend(QLatin1Char('.')).prepend(QCoreApplication::instance()->applicationName());
|
interface.prepend(QLatin1Char('.')).prepend(QCoreApplication::instance()->applicationName());
|
||||||
const QString organizationDomain = QCoreApplication::instance()->organizationDomain();
|
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()) {
|
if (domainName.isEmpty()) {
|
||||||
interface.prepend(QLatin1String("local."));
|
interface.prepend(QLatin1String("local."));
|
||||||
} else {
|
} else {
|
||||||
|
@ -331,15 +331,15 @@ namespace QDBusUtil
|
|||||||
|
|
||||||
/*!
|
/*!
|
||||||
\internal
|
\internal
|
||||||
\fn bool isValidPartOfObjectPath(const QStringRef &part)
|
\fn bool isValidPartOfObjectPath(QStringView part)
|
||||||
See isValidObjectPath
|
See isValidObjectPath
|
||||||
*/
|
*/
|
||||||
bool isValidPartOfObjectPath(const QStringRef &part)
|
bool isValidPartOfObjectPath(QStringView part)
|
||||||
{
|
{
|
||||||
if (part.isEmpty())
|
if (part.isEmpty())
|
||||||
return false; // can't be valid if it's empty
|
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)
|
for (int i = 0; i < part.length(); ++i)
|
||||||
if (!isValidCharacterNoDash(c[i]))
|
if (!isValidCharacterNoDash(c[i]))
|
||||||
return false;
|
return false;
|
||||||
@ -372,11 +372,11 @@ namespace QDBusUtil
|
|||||||
if (ifaceName.isEmpty() || ifaceName.length() > DBUS_MAXIMUM_NAME_LENGTH)
|
if (ifaceName.isEmpty() || ifaceName.length() > DBUS_MAXIMUM_NAME_LENGTH)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
const auto parts = ifaceName.splitRef(QLatin1Char('.'));
|
const auto parts = QStringView{ifaceName}.split(QLatin1Char('.'));
|
||||||
if (parts.count() < 2)
|
if (parts.count() < 2)
|
||||||
return false; // at least two parts
|
return false; // at least two parts
|
||||||
|
|
||||||
for (const QStringRef &part : parts)
|
for (auto part : parts)
|
||||||
if (!isValidMemberName(part))
|
if (!isValidMemberName(part))
|
||||||
return false;
|
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.
|
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
|
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.
|
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 ||
|
if (connName.isEmpty() || connName.length() > DBUS_MAXIMUM_NAME_LENGTH ||
|
||||||
!connName.startsWith(QLatin1Char(':')))
|
!connName.startsWith(QLatin1Char(':')))
|
||||||
@ -400,11 +400,11 @@ namespace QDBusUtil
|
|||||||
if (parts.count() < 1)
|
if (parts.count() < 1)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
for (const QStringRef &part : parts) {
|
for (QStringView part : parts) {
|
||||||
if (part.isEmpty())
|
if (part.isEmpty())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
const QChar* c = part.unicode();
|
const QChar* c = part.data();
|
||||||
for (int j = 0; j < part.length(); ++j)
|
for (int j = 0; j < part.length(); ++j)
|
||||||
if (!isValidCharacter(c[j]))
|
if (!isValidCharacter(c[j]))
|
||||||
return false;
|
return false;
|
||||||
@ -442,15 +442,15 @@ namespace QDBusUtil
|
|||||||
if (busName.startsWith(QLatin1Char(':')))
|
if (busName.startsWith(QLatin1Char(':')))
|
||||||
return isValidUniqueConnectionName(busName);
|
return isValidUniqueConnectionName(busName);
|
||||||
|
|
||||||
const auto parts = busName.splitRef(QLatin1Char('.'));
|
const auto parts = QStringView{busName}.split(QLatin1Char('.'));
|
||||||
if (parts.count() < 1)
|
if (parts.count() < 1)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
for (const QStringRef &part : parts) {
|
for (QStringView part : parts) {
|
||||||
if (part.isEmpty())
|
if (part.isEmpty())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
const QChar *c = part.unicode();
|
const QChar *c = part.data();
|
||||||
if (isValidNumber(c[0]))
|
if (isValidNumber(c[0]))
|
||||||
return false;
|
return false;
|
||||||
for (int j = 0; j < part.length(); ++j)
|
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
|
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
|
255 characters in length, is not empty, is composed only of ASCII letters, digits and
|
||||||
underscores, but does not start with a digit.
|
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)
|
if (memberName.isEmpty() || memberName.length() > DBUS_MAXIMUM_NAME_LENGTH)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
const QChar* c = memberName.unicode();
|
const QChar* c = memberName.data();
|
||||||
if (isValidNumber(c[0]))
|
if (isValidNumber(c[0]))
|
||||||
return false;
|
return false;
|
||||||
for (int j = 0; j < memberName.length(); ++j)
|
for (int j = 0; j < memberName.length(); ++j)
|
||||||
@ -520,8 +520,8 @@ namespace QDBusUtil
|
|||||||
return false;
|
return false;
|
||||||
|
|
||||||
// it starts with /, so we skip the empty first part
|
// it starts with /, so we skip the empty first part
|
||||||
const auto parts = path.midRef(1).split(QLatin1Char('/'));
|
const auto parts = QStringView{path}.mid(1).split(QLatin1Char('/'));
|
||||||
for (const QStringRef &part : parts)
|
for (QStringView part : parts)
|
||||||
if (!isValidPartOfObjectPath(part))
|
if (!isValidPartOfObjectPath(part))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
@ -68,18 +68,15 @@ namespace Q_DBUS_NO_EXPORT QDBusUtil
|
|||||||
{
|
{
|
||||||
Q_DBUS_EXPORT bool isValidInterfaceName(const QString &ifaceName);
|
Q_DBUS_EXPORT bool isValidInterfaceName(const QString &ifaceName);
|
||||||
|
|
||||||
Q_DBUS_EXPORT bool isValidUniqueConnectionName(const QStringRef &busName);
|
Q_DBUS_EXPORT bool isValidUniqueConnectionName(QStringView busName);
|
||||||
inline bool isValidUniqueConnectionName(const QString &busName) { return isValidUniqueConnectionName(QStringRef(&busName)); }
|
|
||||||
|
|
||||||
Q_DBUS_EXPORT bool isValidBusName(const QString &busName);
|
Q_DBUS_EXPORT bool isValidBusName(const QString &busName);
|
||||||
|
|
||||||
Q_DBUS_EXPORT bool isValidMemberName(const QStringRef &memberName);
|
Q_DBUS_EXPORT bool isValidMemberName(QStringView memberName);
|
||||||
inline bool isValidMemberName(const QString &memberName) { return isValidMemberName(QStringRef(&memberName)); }
|
|
||||||
|
|
||||||
Q_DBUS_EXPORT bool isValidErrorName(const QString &errorName);
|
Q_DBUS_EXPORT bool isValidErrorName(const QString &errorName);
|
||||||
|
|
||||||
Q_DBUS_EXPORT bool isValidPartOfObjectPath(const QStringRef &path);
|
Q_DBUS_EXPORT bool isValidPartOfObjectPath(QStringView path);
|
||||||
inline bool isValidPartOfObjectPath(const QString &path) { return isValidPartOfObjectPath(QStringRef(&path)); }
|
|
||||||
|
|
||||||
Q_DBUS_EXPORT bool isValidObjectPath(const QString &path);
|
Q_DBUS_EXPORT bool isValidObjectPath(const QString &path);
|
||||||
|
|
||||||
|
@ -186,12 +186,14 @@ static QString classNameForInterface(const QString &interface, ClassType classTy
|
|||||||
if (!globalClassName.isEmpty())
|
if (!globalClassName.isEmpty())
|
||||||
return globalClassName;
|
return globalClassName;
|
||||||
|
|
||||||
const auto parts = interface.splitRef(QLatin1Char('.'));
|
const auto parts = QStringView{interface}.split(QLatin1Char('.'));
|
||||||
|
|
||||||
QString retval;
|
QString retval;
|
||||||
if (classType == Proxy) {
|
if (classType == Proxy) {
|
||||||
for (const auto &part : parts)
|
for (const auto &part : parts) {
|
||||||
retval += part[0].toUpper() + part.mid(1);
|
retval += part[0].toUpper();
|
||||||
|
retval += part.mid(1);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
retval += parts.last()[0].toUpper() + parts.last().mid(1);
|
retval += parts.last()[0].toUpper() + parts.last().mid(1);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user