aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/qml/qqmlfile.cpp
blob: bac70e69bb4b77b6b8bc1fd71c31341ecc5b90f0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only

#include "qqmlfile.h"

#include <QtCore/qurl.h>
#include <QtCore/qobject.h>
#include <QtCore/qmetaobject.h>
#include <QtCore/qfile.h>
#include <private/qqmlengine_p.h>
#include <private/qqmlglobal_p.h>

QT_BEGIN_NAMESPACE

/*!
    \class QQmlFile
    \inmodule QtQml
    \since 5.0
    \brief The QQmlFile class provides static utility methods to categorize URLs.

    QQmlFile provides some static utility methods to categorize URLs
    and file names the way \l{QQmlEngine} does when loading content from them.
*/

/*!
    \internal

    \enum QQmlFile::Status
    \value Null
    \value Ready
    \value Error
    \value Loading
 */

static char qrc_string[] = "qrc";
static char file_string[] = "file";

#if defined(Q_OS_ANDROID)
static char assets_string[] = "assets";
static char content_string[] = "content";
static char authority_externalstorage[] = "com.android.externalstorage.documents";
static char authority_downloads_documents[] = "com.android.providers.downloads.documents";
static char authority_media_documents[] = "com.android.providers.media.documents";
#endif

class QQmlFilePrivate;

#if QT_CONFIG(qml_network)
class QQmlFileNetworkReply : public QObject
{
Q_OBJECT
public:
    QQmlFileNetworkReply(QQmlEngine *, QQmlFilePrivate *, const QUrl &);
    ~QQmlFileNetworkReply();

signals:
    void finished();
    void downloadProgress(qint64, qint64);

public slots:
    void networkFinished();
    void networkDownloadProgress(qint64, qint64);

public:
    static int finishedIndex;
    static int downloadProgressIndex;
    static int networkFinishedIndex;
    static int networkDownloadProgressIndex;
    static int replyFinishedIndex;
    static int replyDownloadProgressIndex;

private:
    QQmlEngine *m_engine;
    QQmlFilePrivate *m_p;

    QNetworkReply *m_reply;
};
#endif

class QQmlFilePrivate
{
public:
    QQmlFilePrivate();

    mutable QUrl url;
    mutable QString urlString;

    QByteArray data;

    enum Error {
        None, NotFound, CaseMismatch, Network
    };

    Error error;
    QString errorString;
#if QT_CONFIG(qml_network)
    QQmlFileNetworkReply *reply;
#endif
};

#if QT_CONFIG(qml_network)
int QQmlFileNetworkReply::finishedIndex = -1;
int QQmlFileNetworkReply::downloadProgressIndex = -1;
int QQmlFileNetworkReply::networkFinishedIndex = -1;
int QQmlFileNetworkReply::networkDownloadProgressIndex = -1;
int QQmlFileNetworkReply::replyFinishedIndex = -1;
int QQmlFileNetworkReply::replyDownloadProgressIndex = -1;

QQmlFileNetworkReply::QQmlFileNetworkReply(QQmlEngine *e, QQmlFilePrivate *p, const QUrl &url)
: m_engine(e), m_p(p), m_reply(nullptr)
{
    if (finishedIndex == -1) {
        finishedIndex = QMetaMethod::fromSignal(&QQmlFileNetworkReply::finished).methodIndex();
        downloadProgressIndex = QMetaMethod::fromSignal(&QQmlFileNetworkReply::downloadProgress).methodIndex();
        const QMetaObject *smo = &staticMetaObject;
        networkFinishedIndex = smo->indexOfMethod("networkFinished()");
        networkDownloadProgressIndex = smo->indexOfMethod("networkDownloadProgress(qint64,qint64)");

        replyFinishedIndex = QMetaMethod::fromSignal(&QNetworkReply::finished).methodIndex();
        replyDownloadProgressIndex = QMetaMethod::fromSignal(&QNetworkReply::downloadProgress).methodIndex();
    }
    Q_ASSERT(finishedIndex != -1 && downloadProgressIndex != -1 &&
             networkFinishedIndex != -1 && networkDownloadProgressIndex != -1 &&
             replyFinishedIndex != -1 && replyDownloadProgressIndex != -1);

    QNetworkRequest req(url);
    req.setAttribute(QNetworkRequest::HttpPipeliningAllowedAttribute, true);

    m_reply = m_engine->networkAccessManager()->get(req);
    QMetaObject::connect(m_reply, replyFinishedIndex, this, networkFinishedIndex);
    QMetaObject::connect(m_reply, replyDownloadProgressIndex, this, networkDownloadProgressIndex);
}

QQmlFileNetworkReply::~QQmlFileNetworkReply()
{
    if (m_reply) {
        m_reply->disconnect();
        m_reply->deleteLater();
    }
}

void QQmlFileNetworkReply::networkFinished()
{
    if (m_reply->error()) {
        m_p->errorString = m_reply->errorString();
        m_p->error = QQmlFilePrivate::Network;
    } else {
        m_p->data = m_reply->readAll();
    }

    m_reply->deleteLater();
    m_reply = nullptr;

    m_p->reply = nullptr;
    emit finished();
    delete this;
}

void QQmlFileNetworkReply::networkDownloadProgress(qint64 a, qint64 b)
{
    emit downloadProgress(a, b);
}
#endif // qml_network

QQmlFilePrivate::QQmlFilePrivate()
: error(None)
#if QT_CONFIG(qml_network)
, reply(nullptr)
#endif
{
}

/*!
    \internal
 */
QQmlFile::QQmlFile()
: d(new QQmlFilePrivate)
{
}

/*!
    \internal
    Constructs a QQmlFile for content at \a url, using \a engine to retrieve it.
 */
QQmlFile::QQmlFile(QQmlEngine *engine, const QUrl &url)
: d(new QQmlFilePrivate)
{
    load(engine, url);
}

/*!
    \internal
    Constructs a QQmlFile for content at \a url, using \a engine to retrieve it.
 */
QQmlFile::QQmlFile(QQmlEngine *engine, const QString &url)
    : QQmlFile(engine, QUrl(url))
{
}

/*!
    \internal
 */
QQmlFile::~QQmlFile()
{
#if QT_CONFIG(qml_network)
    delete d->reply;
#endif
    delete d;
    d = nullptr;
}

/*!
    \internal
 */
bool QQmlFile::isNull() const
{
    return status() == Null;
}

/*!
    \internal
 */
bool QQmlFile::isReady() const
{
    return status() == Ready;
}

/*!
    \internal
 */
bool QQmlFile::isError() const
{
    return status() == Error;
}

/*!
    \internal
 */
bool QQmlFile::isLoading() const
{
    return status() == Loading;
}

/*!
    \internal
 */
QUrl QQmlFile::url() const
{
    if (!d->urlString.isEmpty()) {
        d->url = QUrl(d->urlString);
        d->urlString = QString();
    }
    return d->url;
}

/*!
    \internal
 */
QQmlFile::Status QQmlFile::status() const
{
    if (d->url.isEmpty() && d->urlString.isEmpty())
        return Null;
#if QT_CONFIG(qml_network)
    else if (d->reply)
        return Loading;
#endif
    else if (d->error != QQmlFilePrivate::None)
        return Error;
    else
        return Ready;
}

/*!
    \internal
 */
QString QQmlFile::error() const
{
    switch (d->error) {
    default:
    case QQmlFilePrivate::None:
        return QString();
    case QQmlFilePrivate::NotFound:
        return QLatin1String("File not found");
    case QQmlFilePrivate::CaseMismatch:
        return QLatin1String("File name case mismatch");
    }
}

/*!
    \internal
 */
qint64 QQmlFile::size() const
{
    return d->data.size();
}

/*!
    \internal
 */
const char *QQmlFile::data() const
{
    return d->data.constData();
}

/*!
    \internal
 */
QByteArray QQmlFile::dataByteArray() const
{
    return d->data;
}

/*!
    \internal
    Loads content at \a url using \a engine.
 */
void QQmlFile::load(QQmlEngine *engine, const QUrl &url)
{
    Q_ASSERT(engine);

    clear();
    d->url = url;

    if (isLocalFile(url)) {
        QString lf = urlToLocalFileOrQrc(url);

        if (!QQml_isFileCaseCorrect(lf)) {
            d->error = QQmlFilePrivate::CaseMismatch;
            return;
        }

        QFile file(lf);
        if (file.open(QFile::ReadOnly)) {
            d->data = file.readAll();
        } else {
            d->error = QQmlFilePrivate::NotFound;
        }
    } else {
#if QT_CONFIG(qml_network)
        d->reply = new QQmlFileNetworkReply(engine, d, url);
#else
        d->error = QQmlFilePrivate::NotFound;
#endif
    }
}

/*!
    \internal
    Loads content at \a url using \a engine.
 */
void QQmlFile::load(QQmlEngine *engine, const QString &url)
{
    Q_ASSERT(engine);

    clear();

    d->urlString = url;

    if (isLocalFile(url)) {
        QString lf = urlToLocalFileOrQrc(url);

        if (!QQml_isFileCaseCorrect(lf)) {
            d->error = QQmlFilePrivate::CaseMismatch;
            return;
        }

        QFile file(lf);
        if (file.open(QFile::ReadOnly)) {
            d->data = file.readAll();
        } else {
            d->error = QQmlFilePrivate::NotFound;
        }
    } else {
#if QT_CONFIG(qml_network)
        QUrl qurl(url);
        d->url = qurl;
        d->urlString = QString();
        d->reply = new QQmlFileNetworkReply(engine, d, qurl);
#else
        d->error = QQmlFilePrivate::NotFound;
#endif
    }
}

/*!
    \internal
 */
void QQmlFile::clear()
{
    d->url = QUrl();
    d->urlString = QString();
    d->data = QByteArray();
    d->error = QQmlFilePrivate::None;
}

/*!
    \internal
    Redirects to the other clear() overload, ignoring \a object.
 */
void QQmlFile::clear(QObject *object)
{
    Q_UNUSED(object);
    clear();
}

#if QT_CONFIG(qml_network)

/*!
    \internal
    Connects \a method of \a object to the internal \c{finished} signal.
 */
bool QQmlFile::connectFinished(QObject *object, const char *method)
{
    if (!d || !d->reply) {
        qWarning("QQmlFile: connectFinished() called when not loading.");
        return false;
    }

    return QObject::connect(d->reply, SIGNAL(finished()), object, method);
}

/*!
    \internal
    Connects \a method of \a object to the internal \c{finished} signal.
 */
bool QQmlFile::connectFinished(QObject *object, int method)
{
    if (!d || !d->reply) {
        qWarning("QQmlFile: connectFinished() called when not loading.");
        return false;
    }

    return QMetaObject::connect(d->reply, QQmlFileNetworkReply::finishedIndex,
                                object, method);
}

/*!
    \internal
    Connects \a method of \a object to the internal \c{downloadProgress} signal.
 */
bool QQmlFile::connectDownloadProgress(QObject *object, const char *method)
{
    if (!d || !d->reply) {
        qWarning("QQmlFile: connectDownloadProgress() called when not loading.");
        return false;
    }

    return QObject::connect(d->reply, SIGNAL(downloadProgress(qint64,qint64)),
                            object, method);
}

/*!
    \internal
    Connects \a method of \a object to the internal \c{downloadProgress} signal.
 */
bool QQmlFile::connectDownloadProgress(QObject *object, int method)
{
    if (!d || !d->reply) {
        qWarning("QQmlFile: connectDownloadProgress() called when not loading.");
        return false;
    }

    return QMetaObject::connect(d->reply, QQmlFileNetworkReply::downloadProgressIndex,
                                object, method);
}
#endif

/*!
    \internal

    Returns \c true if QQmlFile will open \a url synchronously.
    Otherwise returns \c false. Synchronous urls have a \c{qrc:} or \c{file:}
    scheme.

    \note On Android, urls with \c{assets:} or \c{content:} scheme are also
          considered synchronous.
*/
bool QQmlFile::isSynchronous(const QUrl &url)
{
    QString scheme = url.scheme();

    if ((scheme.size() == 4 && 0 == scheme.compare(QLatin1String(file_string), Qt::CaseInsensitive)) ||
        (scheme.size() == 3 && 0 == scheme.compare(QLatin1String(qrc_string), Qt::CaseInsensitive))) {
        return true;

#if defined(Q_OS_ANDROID)
    } else if (scheme.length() == 6 && 0 == scheme.compare(QLatin1String(assets_string), Qt::CaseInsensitive)) {
        return true;
    } else if (scheme.length() == 7 && 0 == scheme.compare(QLatin1String(content_string), Qt::CaseInsensitive)) {
        return true;
#endif

    } else {
        return false;
    }
}

/*!
    \internal

    Returns \c true if QQmlFile will open \a url synchronously.
    Otherwise returns \c false. Synchronous urls have a \c{qrc:} or \c{file:}
    scheme.

    \note On Android, urls with \c{assets:} or \c{content:} scheme are also
          considered synchronous.
*/
bool QQmlFile::isSynchronous(const QString &url)
{
    if (url.size() < 5 /* qrc:/ */)
        return false;

    QChar f = url[0];

    if (f == QLatin1Char('f') || f == QLatin1Char('F')) {

        return url.size() >= 7 /* file:// */ &&
               url.startsWith(QLatin1String(file_string), Qt::CaseInsensitive) &&
               url[4] == QLatin1Char(':') && url[5] == QLatin1Char('/') && url[6] == QLatin1Char('/');

    } else if (f == QLatin1Char('q') || f == QLatin1Char('Q')) {

        return url.size() >= 5 /* qrc:/ */ &&
               url.startsWith(QLatin1String(qrc_string), Qt::CaseInsensitive) &&
               url[3] == QLatin1Char(':') && url[4] == QLatin1Char('/');

    }

#if defined(Q_OS_ANDROID)
    else if (f == QLatin1Char('a') || f == QLatin1Char('A')) {
        return url.length() >= 8 /* assets:/ */ &&
               url.startsWith(QLatin1String(assets_string), Qt::CaseInsensitive) &&
               url[6] == QLatin1Char(':') && url[7] == QLatin1Char('/');
    } else if (f == QLatin1Char('c') || f == QLatin1Char('C')) {
        return url.length() >= 9 /* content:/ */ &&
               url.startsWith(QLatin1String(content_string), Qt::CaseInsensitive) &&
               url[7] == QLatin1Char(':') && url[8] == QLatin1Char('/');
    }
#endif

    return false;
}

#if defined(Q_OS_ANDROID)
static bool hasLocalContentAuthority(const QUrl &url)
{
    const QString authority = url.authority();
    return authority.isEmpty()
            || authority == QLatin1String(authority_externalstorage)
            || authority == QLatin1String(authority_downloads_documents)
            || authority == QLatin1String(authority_media_documents);
}
#endif

/*!
    Returns \c true if \a url is a local file that can be opened with \l{QFile}.
    Otherwise returns \c false. Local file urls have either a \c{qrc:} or
    \c{file:} scheme.

    \note On Android, urls with \c{assets:} or \c{content:} scheme are also
          considered local files.
*/
bool QQmlFile::isLocalFile(const QUrl &url)
{
    QString scheme = url.scheme();

    // file: URLs with two slashes following the scheme can be interpreted as local files
    // where the slashes are part of the path. Therefore, disregard the authority.
    // See QUrl::toLocalFile().
    if (scheme.size() == 4 && scheme.startsWith(QLatin1String(file_string), Qt::CaseInsensitive))
        return true;

    if (scheme.size() == 3 && scheme.startsWith(QLatin1String(qrc_string), Qt::CaseInsensitive))
        return url.authority().isEmpty();

#if defined(Q_OS_ANDROID)
    if (scheme.length() == 6
         && scheme.startsWith(QLatin1String(assets_string), Qt::CaseInsensitive))
        return url.authority().isEmpty();
    if (scheme.length() == 7
         && scheme.startsWith(QLatin1String(content_string), Qt::CaseInsensitive))
        return hasLocalContentAuthority(url);
#endif

    return false;
}

static bool hasScheme(const QString &url, const char *scheme, qsizetype schemeLength)
{
    const qsizetype urlLength = url.size();

    if (urlLength < schemeLength + 1)
        return false;

    if (!url.startsWith(QLatin1String(scheme, scheme + schemeLength), Qt::CaseInsensitive))
        return false;

    if (url[schemeLength] != QLatin1Char(':'))
        return false;

    return true;
}

static qsizetype authorityOffset(const QString &url, qsizetype schemeLength)
{
    const qsizetype urlLength = url.size();

    if (urlLength < schemeLength + 3)
        return -1;

    const QLatin1Char slash('/');
    if (url[schemeLength + 1] == slash && url[schemeLength + 2] == slash) {
        // Exactly two slashes denote an authority.
        if (urlLength < schemeLength + 4 || url[schemeLength + 3] != slash)
            return schemeLength + 3;
    }

    return -1;
}

#if defined(Q_OS_ANDROID)
static bool hasLocalContentAuthority(const QString &url, qsizetype schemeLength)
{
    const qsizetype offset = authorityOffset(url, schemeLength);
    if (offset == -1)
        return true; // no authority is a local authority.

    const QString authorityAndPath = url.sliced(offset);
    return authorityAndPath.startsWith(QLatin1String(authority_externalstorage))
         || authorityAndPath.startsWith(QLatin1String(authority_downloads_documents))
         || authorityAndPath.startsWith(QLatin1String(authority_media_documents));
}

#endif

/*!
    Returns \c true if \a url is a local file that can be opened with \l{QFile}.
    Otherwise returns \c false. Local file urls have either a \c{qrc:} or
    \c{file:} scheme.

    \note On Android, urls with \c{assets:} or \c{content:} scheme are also considered
          local files.
*/
bool QQmlFile::isLocalFile(const QString &url)
{
    if (url.size() < 4 /* qrc: */)
        return false;

    switch (url[0].toLatin1()) {
    case 'f':
    case 'F': {
        // file: URLs with two slashes following the scheme can be interpreted as local files
        // where the slashes are part of the path. Therefore, disregard the authority.
        // See QUrl::toLocalFile().
        const qsizetype fileLength = strlen(file_string);
        return url.startsWith(QLatin1String(file_string, file_string + fileLength),
                              Qt::CaseInsensitive)
                && url.size() > fileLength
                && url[fileLength] == QLatin1Char(':');
    }
    case 'q':
    case 'Q':
        return hasScheme(url, qrc_string, strlen(qrc_string))
            && authorityOffset(url, strlen(qrc_string)) == -1;
#if defined(Q_OS_ANDROID)
    case 'a':
    case 'A':
        return hasScheme(url, assets_string, strlen(assets_string))
            && authorityOffset(url, strlen(assets_string)) == -1;
    case 'c':
    case 'C':
        return hasScheme(url, content_string, strlen(content_string))
            && hasLocalContentAuthority(url, strlen(content_string));
#endif
    default:
        break;
    }

    return false;
}

/*!
    If \a url is a local file returns a path suitable for passing to \l{QFile}.
    Otherwise returns an empty string.

    \sa isLocalFile
*/
QString QQmlFile::urlToLocalFileOrQrc(const QUrl& url)
{
    if (url.scheme().compare(QLatin1String("qrc"), Qt::CaseInsensitive) == 0) {
        if (url.authority().isEmpty())
            return QLatin1Char(':') + url.path();
        return QString();
    }

#if defined(Q_OS_ANDROID)
    if (url.scheme().compare(QLatin1String("assets"), Qt::CaseInsensitive) == 0)
        return url.authority().isEmpty() ? url.toString() : QString();
    if (url.scheme().compare(QLatin1String("content"), Qt::CaseInsensitive) == 0) {
        if (hasLocalContentAuthority(url))
            return url.toString();
        return QString();
    }
#endif
    return url.toLocalFile();
}

static QString toLocalFile(const QString &url)
{
    const QUrl file(url);
    if (!file.isLocalFile())
        return QString();

    // QUrl::toLocalFile() interprets two slashes as part of the path.
    // Therefore windows hostnames like "//servername/path/to/file.txt" are preserved.

    return file.toLocalFile();
}

static bool isDoubleSlashed(const QString &url, qsizetype offset)
{
    const qsizetype urlLength = url.size();
    if (urlLength < offset + 2)
        return false;

    const QLatin1Char slash('/');
    if (url[offset] != slash || url[offset + 1] != slash)
        return false;

    if (urlLength < offset + 3)
        return true;

    return url[offset + 2] != slash;
}

/*!
    If \a url is a local file returns a path suitable for passing to \l{QFile}.
    Otherwise returns an empty string.

    \sa isLocalFile
*/
QString QQmlFile::urlToLocalFileOrQrc(const QString& url)
{
    if (url.startsWith(QLatin1String("qrc://"), Qt::CaseInsensitive)) {
        // Exactly two slashes are bad because that's a URL authority.
        // One slash is fine and >= 3 slashes are file.
        if (url.size() == 6 || url[6] != QLatin1Char('/')) {
            Q_ASSERT(isDoubleSlashed(url, strlen("qrc:")));
            return QString();
        }
        Q_ASSERT(!isDoubleSlashed(url, strlen("qrc:")));
        return QLatin1Char(':') + QStringView{url}.mid(6);
    }

    if (url.startsWith(QLatin1String("qrc:"), Qt::CaseInsensitive)) {
        Q_ASSERT(!isDoubleSlashed(url, strlen("qrc:")));
        if (url.size() > 4)
            return QLatin1Char(':') + QStringView{url}.mid(4);
        return QStringLiteral(":");
    }

#if defined(Q_OS_ANDROID)
    if (url.startsWith(QLatin1String("assets:"), Qt::CaseInsensitive))
        return isDoubleSlashed(url, strlen("assets:")) ? QString() : url;
    if (hasScheme(url, content_string, strlen(content_string)))
        return hasLocalContentAuthority(url, strlen(content_string)) ? url : QString();
#endif

    return toLocalFile(url);
}

QT_END_NAMESPACE

#include "qqmlfile.moc"