| 1 | // Copyright (C) 2023 The Qt Company Ltd. |
|---|---|
| 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
| 3 | |
| 4 | #include "qqmldom_utils_p.h" |
| 5 | #include <QtCore/qdir.h> |
| 6 | #include <QtCore/qdiriterator.h> |
| 7 | #include <QtCore/qstring.h> |
| 8 | #include <QtCore/qmetaobject.h> |
| 9 | #include <QtCore/qcbormap.h> |
| 10 | #include <QtCore/qvarlengtharray.h> |
| 11 | |
| 12 | QT_BEGIN_NAMESPACE |
| 13 | |
| 14 | Q_LOGGING_CATEGORY(QQmlJSDomImporting, "qt.qqmljsdom.importing") |
| 15 | |
| 16 | namespace QQmlJS { |
| 17 | namespace Dom { |
| 18 | |
| 19 | using namespace Qt::StringLiterals; |
| 20 | |
| 21 | static QMetaEnum regionEnum = QMetaEnum::fromType<FileLocationRegion>(); |
| 22 | |
| 23 | QString fileLocationRegionName(FileLocationRegion region) |
| 24 | { |
| 25 | return QString::fromLatin1(ba: regionEnum.key(index: region)); |
| 26 | } |
| 27 | |
| 28 | FileLocationRegion fileLocationRegionValue(QStringView region) |
| 29 | { |
| 30 | return static_cast<FileLocationRegion>(regionEnum.keyToValue(key: region.toLatin1())); |
| 31 | } |
| 32 | |
| 33 | QCborValue sourceLocationToQCborValue(QQmlJS::SourceLocation loc) |
| 34 | { |
| 35 | QCborMap res({ |
| 36 | {QStringLiteral(u"offset"), loc.offset}, |
| 37 | {QStringLiteral(u"length"), loc.length}, |
| 38 | {QStringLiteral(u"startLine"), loc.startLine}, |
| 39 | {QStringLiteral(u"startColumn"), loc.startColumn} |
| 40 | }); |
| 41 | return res; |
| 42 | } |
| 43 | |
| 44 | } // namespace Dom |
| 45 | }; // namespace QQmlJS |
| 46 | |
| 47 | QT_END_NAMESPACE |
| 48 |
