5#include <QtCore/QCoreApplication>
6#include <QtCore/QRegularExpression>
26 if (change < 0 && offset - change >=
utf16Start()) {
35 value.offset += change;
36 value.startColumn += colChange;
37 value.startLine += lineChange;
39 if (change < 0 && offset - change >
utf16End())
41 value.length += change;
55 int lineNr,
int columnNr,
int utf16Offset,
const QString ¤tLine)
56 : m_innerSinks({ innerSink }),
60 m_currentColumnNr(columnNr),
61 m_utf16Offset(utf16Offset),
62 m_currentLine(currentLine),
69 int nToAdd = nNewline;
78 for (
int i = 0;
i < nToAdd; ++
i)
106 int trailingSpaceStartColumn =
108 IndentInfo indExisting(trailingSpace, tabSize, trailingSpaceStartColumn);
109 if (trailingSpaceStartColumn != 0)
112 if (indExisting.column < ind.
column) {
120 }
else if (indExisting.column < ind.
column) {
141template<
typename String,
typename ...Args>
144 return re.matchView(
s,
args...);
156 auto i =
m.capturedStart(1);
157 auto iEnd =
m.capturedEnd(1);
161 if (iEnd <
v.size()) {
164 while (
m.hasMatch()) {
165 write(
v.mid(iEnd,
m.capturedEnd(1) - iEnd));
166 iEnd =
m.capturedEnd(1);
170 write(
v.mid(iEnd,
v.size() - iEnd));
174 if (!toAdd.trimmed().isEmpty())
182 if (!
v.trimmed().isEmpty())
205 if (shouldEnsureNewline)
220 res.toUpdate = toUpdate;
230 res.updater = updater;
240 qWarning() <<
"Trying to close already closed PendingSourceLocation" << int(slId);
245 qWarning() <<
"Trying to close non existing PendingSourceLocation" << int(slId);
265 if (spaceOnly && !self.m_currentLine.
isEmpty())
266 spacesToPreserve = self.m_currentLine;
268 if (self.counter() !=
c && !spacesToPreserve.
isEmpty())
279 int startNonSpace = 0;
282 int oldColumn =
column(startNonSpace);
283 if (indentAmount >= 0) {
292 quint32 colChange = indentAmount - oldColumn;
294 qint32 oChange = indent.
size() - startNonSpace;
305 switch (trailingSpace) {
310 while (lastNonSpace > 0 &&
m_currentLine.
at(lastNonSpace - 1).isSpace())
344 i.value().changeAtOffset(
offset, change, colChange, lineChange);
369 if (!
it.value()(*
this,
t))
379 bool isEmptyNewline = !eol.
isEmpty() && isSpaceOnly;
391 int oldCol =
column(untilChar);
434 else if (!isSpaceOnly)
440 auto &pLoc =
i.value();
441 if (!pLoc.open && pLoc.utf16End() <= endCommit) {
456#include "moc_qqmldomlinewriter_p.cpp"
QStringView trailingString
FormatOptions formatOptions
TrailingSpace codeTrailingSpace
virtual void lineChanged()
LineWriter & write(QStringView v, TextAddType tType=TextAddType::Normal)
QAtomicInt m_lastCallbackId
void endSourceLocation(PendingSourceLocationId)
void handleTrailingSpace(LineWriterOptions::TrailingSpace s)
int column(int localIndex)
LineWriter & ensureNewline(int nNewlines=1, TextAddType t=TextAddType::Extra)
PendingSourceLocationId startSourceLocation(SourceLocation *)
QMap< PendingSourceLocationId, PendingSourceLocation > m_pendingSourceLocations
LineWriterOptions m_options
LineWriter & ensureSpace(TextAddType t=TextAddType::Extra)
QString eolToWrite() const
void eof(bool ensureNewline=true)
QList< SinkF > m_innerSinks
std::function< void(QStringView)> sink()
int addNewlinesAutospacerCallback(int nLines)
void changeAtOffset(quint32 offset, qint32 change, qint32 colChange, qint32 lineChange)
virtual void reindentAndSplit(const QString &eol, bool eof=false)
quint32 m_committedEmptyLines
void commitLine(const QString &eol, TextAddType t=TextAddType::Normal, int untilChar=-1)
SourceLocation currentSourceLocation() const
PendingSourceLocationIdAtomic m_lastSourceLocationId
virtual void willCommit()
SourceLocation committedLocation() const
QMap< int, std::function< bool(LineWriter &, TextAddType)> m_textAddCallbacks)
void setLineIndent(int indentAmount)
int addTextAddCallback(std::function< bool(LineWriter &, TextAddType)> callback)
void textAddCallback(TextAddType t)
LineWriter(const SinkF &innerSink, const QString &fileName, const LineWriterOptions &options=LineWriterOptions(), int lineNr=0, int columnNr=0, int utf16Offset=0, const QString ¤tLine=QString())
quint32 utf16Start() const
std::function< void(SourceLocation)> updater
void changeAtOffset(quint32 offset, qint32 change, qint32 colChange, qint32 lineChange)
SourceLocation * toUpdate
PendingSourceLocationId id
\inmodule QtCore \reentrant
\inmodule QtCore \reentrant
constexpr bool isEmpty() const noexcept
Returns whether this string view is empty - that is, whether {size() == 0}.
constexpr qsizetype size() const noexcept
Returns the size of this string view, in UTF-16 code units (that is, surrogate pairs count as two for...
QString toString() const
Returns a deep copy of this string view's data as a QString.
constexpr QStringView mid(qsizetype pos, qsizetype n=-1) const noexcept
Returns the substring of length length starting at position start in this object.
QStringView trimmed() const noexcept
Strips leading and trailing whitespace and returns the result.
\macro QT_RESTRICTED_CAST_FROM_ASCII
QString & replace(qsizetype i, qsizetype len, QChar after)
QString mid(qsizetype position, qsizetype n=-1) const &
bool isEmpty() const noexcept
Returns true if the string has no characters; otherwise returns false.
void clear()
Clears the contents of the string and makes it null.
qsizetype size() const noexcept
Returns the number of characters in this string.
const QChar at(qsizetype i) const
Returns the character at the given index position in the string.
QString & append(QChar c)
QString trimmed() const &
QSet< QString >::iterator it
std::function< void(QStringView)> SinkF
int PendingSourceLocationId
static QRegularExpressionMatch matchHelper(QRegularExpression &re, String &&s, Args &&...args)
Combined button and popup list for selecting options.
SharedPointerFileDialogOptions m_options
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
GLsizei const GLfloat * v
[13]
GLenum GLuint GLintptr offset
GLenum GLenum GLsizei void GLsizei void * column
GLsizei GLenum GLboolean sink
QLatin1StringView QLatin1String
#define QStringLiteral(str)