6#include <QtCore/qregularexpression.h>
12Text::Text() : m_first(
nullptr), m_last(
nullptr) { }
14Text::
Text(
const QString &str) : m_first(
nullptr), m_last(
nullptr)
40 return operator<<(Atom(atomType));
50 if (atom.count() < 2) {
51 if (m_first ==
nullptr) {
55 m_last =
new Atom(m_last, atom
.type(), atom.string());
57 if (m_first ==
nullptr) {
58 m_first =
new Atom(atom
.type(), atom.string(), atom.string(1));
61 m_last =
new Atom(m_last, atom
.type(), atom.string(), atom.string(1));
67
68
69
70
73 if (m_first ==
nullptr) {
84 while (atom !=
nullptr) {
93 if (m_first !=
nullptr) {
94 if (m_first == m_last)
96 Atom *oldFirst = m_first;
104 if (m_last !=
nullptr) {
105 Atom *oldLast = m_last;
106 if (m_first == m_last) {
120
121
122
123
128 while (atom !=
nullptr) {
131 str += atom->string();
138
139
143 while (atom !=
nullptr) {
146 if (atom->string().contains(str, Qt::CaseInsensitive))
154 bool inclusive)
const
159 while (begin !=
nullptr && begin
->type() != left)
161 if (begin !=
nullptr) {
167 while (end !=
nullptr && end
->type() != right)
178 if (sectionLeft !=
nullptr) {
179 const Atom *begin = sectionLeft;
182 if (begin !=
nullptr)
185 const Atom *end = begin;
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
227 constexpr int minimum_indentation_level { 1 };
228 int indentation_level { minimum_indentation_level };
229 int indentation_width { 4 };
232 while (atom !=
nullptr) {
233 QString str = atom->string();
234 str.replace(
"\\",
"\\\\");
235 str.replace(
"\"",
"\\\"");
236 str.replace(
"\n",
"\\n");
237 static const QRegularExpression re(R"([^ -~])");
238 str.replace(re,
"?");
240 str =
" \"" + str + QLatin1Char(
'"');
242 QString atom_type = atom->typeString();
243 if (atom_type.contains(
"Right"))
244 indentation_level =
std::max(minimum_indentation_level, indentation_level - 1);
246 fprintf(stderr,
"%s%s%s\n",
247 QString(indentation_level * indentation_width,
' ').toLatin1().data(),
248 atom_type.toLatin1().data(), str.toLatin1().data());
250 if (atom_type.contains(
"Left"))
251 indentation_level += 1;
260 if (begin !=
nullptr) {
261 while (begin != end) {
271 while (m_first !=
nullptr) {
272 Atom *atom = m_first;
293 int cmp = QString::compare(atom1->string(), atom2->string());
307
308
309
310
311
312
314 if (m_first ==
nullptr)
317 Atom *previous =
nullptr;
318 Atom *current = m_first;
320 while (current !=
nullptr) {
330 Text splitText =
Text(current, m_last);
334 m_first = previous ? m_first :
nullptr;
335 if (m_last = previous; m_last)
The Atom class is the fundamental unit for representing documents internally.
AtomType type() const
Return the type of this atom.
void setNext(Atom *newNext)
AtomType
\value AnnotatedList \value AutoLink \value BaseName \value BriefLeft \value BriefRight \value C \val...
Atom * next()
Return the next atom in the atom list.
const Atom * next() const
Return the next atom in the atom list.
LinkAtom(const LinkAtom &t)
Standard copy constructor of LinkAtom t.
LinkAtom(Atom *previous, const LinkAtom &t)
Special copy constructor of LinkAtom t, where where the new LinkAtom will not be the first one in the...
bool contains(const QString &str) const
Returns true if this Text contains the substring str.
static Text subText(const Atom *begin, const Atom *end=nullptr)
static Text sectionHeading(const Atom *sectionBegin)
void dump() const
Prints a human-readable version of the contained atoms to stderr.
const Atom * firstAtom() const
Text splitAtFirst(Atom::AtomType start)
Splits the current Text from start to end into a new Text object.
Text subText(Atom::AtomType left, Atom::AtomType right, const Atom *from=nullptr, bool inclusive=false) const
Text & operator=(const Text &text)
const Atom * lastAtom() const
QString toString() const
This function traverses the atom list of the Text object, extracting all the string parts.
static int compare(const Text &text1, const Text &text2)
Combined button and popup list for selecting options.