MCPcopy Create free account
hub / github.com/KDE/kdevelop / zeroIndentation

Function zeroIndentation

plugins/clang/codegen/sourcemanipulation.cpp:68–93  ·  view source on GitHub ↗

Re-indents the code so the leftmost line starts at zero

Source from the content-addressed store, hash-verified

66
67// Re-indents the code so the leftmost line starts at zero
68QString 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
96DocumentChangeSet SourceCodeInsertion::changes()

Callers 1

Calls 6

midMethod · 0.80
joinMethod · 0.80
splitMethod · 0.45
sizeMethod · 0.45
indexOfMethod · 0.45
reserveMethod · 0.45

Tested by

no test coverage detected