diff options
Diffstat (limited to 'src/corelib/io/qresource.cpp')
-rw-r--r-- | src/corelib/io/qresource.cpp | 50 |
1 files changed, 24 insertions, 26 deletions
diff --git a/src/corelib/io/qresource.cpp b/src/corelib/io/qresource.cpp index 4e7120a3b8..c1187e5145 100644 --- a/src/corelib/io/qresource.cpp +++ b/src/corelib/io/qresource.cpp @@ -67,10 +67,9 @@ QT_BEGIN_NAMESPACE class QStringSplitter { public: - QStringSplitter(const QString &s) - : m_string(s), m_data(m_string.constData()), m_len(s.length()), m_pos(0) + explicit QStringSplitter(QStringView sv) + : m_data(sv.data()), m_len(sv.size()) { - m_splitChar = QLatin1Char('/'); } inline bool hasNext() { @@ -79,18 +78,17 @@ public: return m_pos < m_len; } - inline QStringRef next() { + inline QStringView next() { int start = m_pos; while (m_pos < m_len && m_data[m_pos] != m_splitChar) ++m_pos; - return QStringRef(&m_string, start, m_pos - start); + return QStringView(m_data + start, m_pos - start); } - QString m_string; const QChar *m_data; - QChar m_splitChar; - int m_len; - int m_pos; + qssize_t m_len; + qssize_t m_pos = 0; + QChar m_splitChar = QLatin1Char('/'); }; @@ -679,7 +677,7 @@ int QResourceRoot::findNode(const QString &_path, const QLocale &locale) const QStringSplitter splitter(path); while (child_count && splitter.hasNext()) { - QStringRef segment = splitter.next(); + QStringView segment = splitter.next(); #ifdef DEBUG_RESOURCE_MATCH qDebug() << " CHILDREN" << segment; @@ -836,24 +834,24 @@ QStringList QResourceRoot::children(int node) const bool QResourceRoot::mappingRootSubdir(const QString &path, QString *match) const { const QString root = mappingRoot(); - if(!root.isEmpty()) { - const QVector<QStringRef> root_segments = root.splitRef(QLatin1Char('/'), QString::SkipEmptyParts), - path_segments = path.splitRef(QLatin1Char('/'), QString::SkipEmptyParts); - if(path_segments.size() <= root_segments.size()) { - int matched = 0; - for(int i = 0; i < path_segments.size(); ++i) { - if(root_segments[i] != path_segments[i]) - break; - ++matched; - } - if(matched == path_segments.size()) { - if(match && root_segments.size() > matched) - *match = root_segments.at(matched).toString(); - return true; - } + if (root.isEmpty()) + return false; + + QStringSplitter rootIt(root); + QStringSplitter pathIt(path); + while (rootIt.hasNext()) { + if (pathIt.hasNext()) { + if (rootIt.next() != pathIt.next()) // mismatch + return false; + } else { + // end of path, but not of root: + if (match) + *match = rootIt.next().toString(); + return true; } } - return false; + // end of root + return !pathIt.hasNext(); } Q_CORE_EXPORT bool qRegisterResourceData(int version, const unsigned char *tree, |