Re-indents the code so the leftmost line starts at zero
| 66 | |
| 67 | // Re-indents the code so the leftmost line starts at zero |
| 68 | QString zeroIndentation(const QString& str, int fromLine = 0) |
| 69 | { |
| 70 | QStringList lines = str.split(QLatin1Char('\n')); |
| 71 | QStringList ret; |
| 72 | |
| 73 | if (fromLine < lines.size()) { |
| 74 | ret = lines.mid(0, fromLine); |
| 75 | lines = lines.mid(fromLine); |
| 76 | } |
| 77 | |
| 78 | static const QRegularExpression nonWhiteSpace(QStringLiteral("\\S")); |
| 79 | int minLineStart = 10000; |
| 80 | for (const auto& line : std::as_const(lines)) { |
| 81 | int lineStart = line.indexOf(nonWhiteSpace); |
| 82 | if (lineStart < minLineStart) { |
| 83 | minLineStart = lineStart; |
| 84 | } |
| 85 | } |
| 86 | |
| 87 | ret.reserve(ret.size() + lines.size()); |
| 88 | for (const auto& line : std::as_const(lines)) { |
| 89 | ret << line.mid(minLineStart); |
| 90 | } |
| 91 | |
| 92 | return ret.join(QLatin1Char('\n')); |
| 93 | } |
| 94 | } |
| 95 | |
| 96 | DocumentChangeSet SourceCodeInsertion::changes() |