-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathscript.cpp
34 lines (29 loc) · 1.02 KB
/
script.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include "script.hpp"
#include <QtCore/QRegExp>
#include <QtCore/QStringList>
using qt_monkey_agent::Private::Script;
std::list<Script> Script::splitToExecutableParts(const QString &fileName,
const QString &scriptCode)
{
std::list<Script> res;
QRegExp rxSplitOrNewLine(
QRegExp::escape(QLatin1String("<<<RESTART FROM HERE>>>")) + "|\n");
int pos = 0;
int prevPos = 0;
int lineno = 1;
int curLine = 1;
while ((pos = rxSplitOrNewLine.indexIn(scriptCode, pos)) != -1) {
if (scriptCode[pos] == '\n') {
++curLine;
} else {
res.emplace_back(fileName, lineno,
scriptCode.mid(prevPos, pos - prevPos));
lineno = curLine;
prevPos = pos + rxSplitOrNewLine.matchedLength();
}
pos = pos + rxSplitOrNewLine.matchedLength();
}
if (prevPos < scriptCode.length())
res.emplace_back(fileName, lineno, scriptCode.mid(prevPos));
return res;
}