| 1 | // Copyright (C) 2021 The Qt Company Ltd. |
| 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 |
| 3 | |
| 4 | #ifndef QUOTER_H |
| 5 | #define QUOTER_H |
| 6 | |
| 7 | #include "location.h" |
| 8 | |
| 9 | #include <QtCore/qhash.h> |
| 10 | #include <QtCore/qstringlist.h> |
| 11 | |
| 12 | #include <limits> |
| 13 | |
| 14 | QT_BEGIN_NAMESPACE |
| 15 | |
| 16 | class Quoter |
| 17 | { |
| 18 | public: |
| 19 | Quoter(); |
| 20 | |
| 21 | void reset(); |
| 22 | void quoteFromFile(const QString &userFriendlyFileName, const QString &plainCode, |
| 23 | const QString &markedCode); |
| 24 | QString quoteLine(const Location &docLocation, const QString &command, const QString &pattern); |
| 25 | QString quoteTo(const Location &docLocation, const QString &command, const QString &pattern); |
| 26 | QString quoteUntil(const Location &docLocation, const QString &command, const QString &pattern); |
| 27 | QString quoteSnippet(const Location &docLocation, const QString &identifier); |
| 28 | |
| 29 | static QStringList splitLines(const QString &line); |
| 30 | |
| 31 | private: |
| 32 | struct SnippetIndentation { |
| 33 | int minContentIndent = std::numeric_limits<int>::max(); |
| 34 | bool hasNonEmptyContent = false; |
| 35 | }; |
| 36 | |
| 37 | int calculateIndentation(const QString &line) const; |
| 38 | SnippetIndentation analyzeContentIndentation(const Location &docLocation, |
| 39 | const QString &delimiter); |
| 40 | |
| 41 | QString getLine(int unindent = 0); |
| 42 | void failedAtEnd(const Location &docLocation, const QString &command); |
| 43 | bool match(const Location &docLocation, const QString &pattern, const QString &line); |
| 44 | [[nodiscard]] QString () const; |
| 45 | QString removeSpecialLines(const QString &line, const QString &, int unindent = 0); |
| 46 | |
| 47 | bool m_silent {}; |
| 48 | QStringList m_plainLines {}; |
| 49 | QStringList m_markedLines {}; |
| 50 | Location m_codeLocation {}; |
| 51 | static QHash<QString, QString> ; |
| 52 | }; |
| 53 | |
| 54 | QT_END_NAMESPACE |
| 55 | |
| 56 | #endif |
| 57 | |