MCPcopy Create free account
hub / github.com/Serial-Studio/Serial-Studio / formatDocument

Function formatDocument

app/src/DataModel/Editors/CodeFormatter.cpp:651–666  ·  view source on GitHub ↗

* @brief Reformats the entire source string with normalized indentation. */

Source from the content-addressed store, hash-verified

649 * @brief Reformats the entire source string with normalized indentation.
650 */
651QString formatDocument(const QString& source, Language language, int indentSpaces)
652{
653 if (source.isEmpty())
654 return source;
655
656 const QStringList lines = splitLines(source);
657 const ScanResult scan = scanAllLines(lines, language);
658
659 QStringList out;
660 out.reserve(lines.size());
661 for (int i = 0; i < lines.size(); ++i)
662 out.append(reformatOne(
663 lines[i], scan.infos[i], scan.depthAtStart[i], scan.hangAtStart[i], indentSpaces));
664
665 return out.join(QLatin1Char('\n'));
666}
667
668/**
669 * @brief Reformats only the given inclusive line range, preserving everything else.

Callers 6

onFormatMethod · 0.85
formatDocumentMethod · 0.85
formatDocumentMethod · 0.85
onFormatMethod · 0.85
formatDocumentMethod · 0.85
formatDocumentMethod · 0.85

Calls 6

splitLinesFunction · 0.85
scanAllLinesFunction · 0.85
reformatOneFunction · 0.85
isEmptyMethod · 0.80
sizeMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected