diff options
| author | Friedemann Kleint <friedemann.kleint@qt.io> | 2023-05-10 13:50:56 +0200 |
|---|---|---|
| committer | Cristián Maureira-Fredes <cristian.maureira-fredes@qt.io> | 2025-11-24 12:06:06 +0100 |
| commit | 845630ad239c4b37ff37e49ef5bb969a8946744b (patch) | |
| tree | 5c65f2e270511459d346c14f0ad8d01f5e6e39a0 /sources/shiboken6/ApiExtractor/codesniphelpers.cpp | |
| parent | 3cf2077a1b060bbea3419ccde23c5da6485a2e24 (diff) | |
Move the shiboken-generator source around
THIS COMMIT WAS GENERATED BY A SCRIPT
Task-number: PYSIDE-962
Task-number: PYSIDE-1587
Change-Id: I58b05c3d05606efb6303193f2d7f907a0ab5741b
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
Diffstat (limited to 'sources/shiboken6/ApiExtractor/codesniphelpers.cpp')
| -rw-r--r-- | sources/shiboken6/ApiExtractor/codesniphelpers.cpp | 77 |
1 files changed, 0 insertions, 77 deletions
diff --git a/sources/shiboken6/ApiExtractor/codesniphelpers.cpp b/sources/shiboken6/ApiExtractor/codesniphelpers.cpp deleted file mode 100644 index 9d16cb44f..000000000 --- a/sources/shiboken6/ApiExtractor/codesniphelpers.cpp +++ /dev/null @@ -1,77 +0,0 @@ -// Copyright (C) 2021 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 - -#include "codesniphelpers.h" - -#include <QtCore/qstringlist.h> - -#include <algorithm> - -static inline int firstNonBlank(QStringView s) -{ - const auto it = std::find_if(s.cbegin(), s.cend(), - [] (QChar c) { return !c.isSpace(); }); - return int(it - s.cbegin()); -} - -static inline bool isEmpty(QStringView s) -{ - return s.isEmpty() - || std::all_of(s.cbegin(), s.cend(), - [] (QChar c) { return c.isSpace(); }); -} - -QString CodeSnipHelpers::dedent(const QString &code) -{ - if (code.isEmpty()) - return code; - // Right trim if indent=0, or trim if single line - if (!code.at(0).isSpace() || !code.contains(u'\n')) - return code.trimmed(); - const auto lines = QStringView{code}.split(u'\n'); - int spacesToRemove = std::numeric_limits<int>::max(); - for (const auto &line : lines) { - if (!isEmpty(line)) { - const int nonSpacePos = firstNonBlank(line); - if (nonSpacePos < spacesToRemove) - spacesToRemove = nonSpacePos; - if (spacesToRemove == 0) - return code; - } - } - QString result; - for (const auto &line : lines) { - if (!isEmpty(line) && spacesToRemove < line.size()) - result += line.mid(spacesToRemove).toString(); - result += u'\n'; - } - return result; -} - -QString CodeSnipHelpers::fixSpaces(QString code) -{ - code.remove(u'\r'); - // Check for XML <tag>\n<space>bla... - if (code.startsWith(u"\n ")) - code.remove(0, 1); - while (!code.isEmpty() && code.back().isSpace()) - code.chop(1); - code = dedent(code); - if (!code.isEmpty() && !code.endsWith(u'\n')) - code.append(u'\n'); - return code; -} - -// Prepend a line to the code, observing indentation -void CodeSnipHelpers::prependCode(QString *code, QString firstLine) -{ - while (!code->isEmpty() && code->front() == u'\n') - code->remove(0, 1); - if (!code->isEmpty() && code->front().isSpace()) { - const int indent = firstNonBlank(*code); - firstLine.prepend(QString(indent, u' ')); - } - if (!firstLine.endsWith(u'\n')) - firstLine += u'\n'; - code->prepend(firstLine); -} |
