forked from qt-creator/qt-creator
fix comment parsing wrt line continuations
This commit is contained in:
@@ -154,7 +154,7 @@ public:
|
|||||||
QString m_pendingComment;
|
QString m_pendingComment;
|
||||||
ushort *m_proitemPtr;
|
ushort *m_proitemPtr;
|
||||||
|
|
||||||
enum StrState { NotStarted, Started, PutSpace };
|
enum StrState { NeverStarted, NotStarted, Started, PutSpace };
|
||||||
|
|
||||||
/////////////// Evaluating pro file contents
|
/////////////// Evaluating pro file contents
|
||||||
|
|
||||||
@@ -289,33 +289,36 @@ bool ProFileEvaluator::Private::read(ProFile *pro, QTextStream *ts)
|
|||||||
|
|
||||||
int parens = 0;
|
int parens = 0;
|
||||||
bool inQuote = false;
|
bool inQuote = false;
|
||||||
bool escaped = false;
|
|
||||||
while (!ts->atEnd()) {
|
while (!ts->atEnd()) {
|
||||||
QString line = ts->readLine();
|
QString line = ts->readLine();
|
||||||
const ushort *cur = (const ushort *)line.unicode(),
|
const ushort *cur = (const ushort *)line.unicode(),
|
||||||
*end = cur + line.length();
|
*end = cur + line.length(),
|
||||||
|
*cmtptr = 0;
|
||||||
m_proitem.reserve(line.length());
|
m_proitem.reserve(line.length());
|
||||||
m_proitemPtr = (ushort *)m_proitem.unicode();
|
m_proitemPtr = (ushort *)m_proitem.unicode();
|
||||||
|
enum { NotEscaped, Escaped, PostEscaped } escaped = NotEscaped;
|
||||||
|
StrState sts = NeverStarted;
|
||||||
|
goto startItem;
|
||||||
nextItem:
|
nextItem:
|
||||||
|
escaped = NotEscaped;
|
||||||
|
nextItem1:
|
||||||
|
sts = NotStarted;
|
||||||
|
startItem:
|
||||||
ushort *ptr = m_proitemPtr;
|
ushort *ptr = m_proitemPtr;
|
||||||
StrState sts = NotStarted;
|
|
||||||
while (cur < end) {
|
while (cur < end) {
|
||||||
ushort c = *cur++;
|
ushort c = *cur++;
|
||||||
if (c == '#') { // Yep - no escaping possible
|
if (c == '#') { // Yep - no escaping possible
|
||||||
m_proitemPtr = ptr;
|
cmtptr = cur;
|
||||||
insertComment(line.right(end - cur).simplified());
|
break;
|
||||||
goto done;
|
|
||||||
}
|
}
|
||||||
if (!escaped) {
|
if (escaped != Escaped) {
|
||||||
if (c == '\\') {
|
if (c == '\\') {
|
||||||
escaped = true;
|
escaped = Escaped;
|
||||||
goto putch;
|
goto putch;
|
||||||
} else if (c == '"') {
|
} else if (c == '"') {
|
||||||
inQuote = !inQuote;
|
inQuote = !inQuote;
|
||||||
goto putch;
|
goto putch1;
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
escaped = false;
|
|
||||||
}
|
}
|
||||||
if (!inQuote) {
|
if (!inQuote) {
|
||||||
if (c == '(') {
|
if (c == '(') {
|
||||||
@@ -327,7 +330,9 @@ bool ProFileEvaluator::Private::read(ProFile *pro, QTextStream *ts)
|
|||||||
if (c == ' ' || c == '\t') {
|
if (c == ' ' || c == '\t') {
|
||||||
m_proitemPtr = ptr;
|
m_proitemPtr = ptr;
|
||||||
updateItem();
|
updateItem();
|
||||||
goto nextItem;
|
if (escaped == Escaped)
|
||||||
|
escaped = PostEscaped;
|
||||||
|
goto nextItem1;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (c == ':') {
|
if (c == ':') {
|
||||||
@@ -360,9 +365,14 @@ bool ProFileEvaluator::Private::read(ProFile *pro, QTextStream *ts)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (c == ' ' || c == '\t') {
|
if (c == ' ' || c == '\t') {
|
||||||
if (sts == Started)
|
if (sts == Started) {
|
||||||
sts = PutSpace;
|
sts = PutSpace;
|
||||||
|
if (escaped == Escaped)
|
||||||
|
escaped = PostEscaped;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
|
putch1:
|
||||||
|
escaped = NotEscaped;
|
||||||
putch:
|
putch:
|
||||||
if (sts == PutSpace)
|
if (sts == PutSpace)
|
||||||
*ptr++ = ' ';
|
*ptr++ = ' ';
|
||||||
@@ -370,15 +380,17 @@ bool ProFileEvaluator::Private::read(ProFile *pro, QTextStream *ts)
|
|||||||
sts = Started;
|
sts = Started;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
m_proitemPtr = ptr;
|
if (escaped != NotEscaped) {
|
||||||
done:
|
--ptr;
|
||||||
if (escaped) {
|
if (ptr != (ushort *)m_proitem.unicode() && *(ptr - 1) == ' ')
|
||||||
--m_proitemPtr;
|
--ptr;
|
||||||
updateItem();
|
|
||||||
} else {
|
|
||||||
updateItem();
|
|
||||||
finalizeBlock();
|
|
||||||
}
|
}
|
||||||
|
m_proitemPtr = ptr;
|
||||||
|
updateItem();
|
||||||
|
if (cmtptr)
|
||||||
|
insertComment(line.right(end - cmtptr).simplified());
|
||||||
|
if (sts != NeverStarted && escaped == NotEscaped)
|
||||||
|
finalizeBlock();
|
||||||
++m_lineNo;
|
++m_lineNo;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
@@ -494,8 +506,6 @@ void ProFileEvaluator::Private::insertOperator(const char op)
|
|||||||
|
|
||||||
void ProFileEvaluator::Private::insertComment(const QString &comment)
|
void ProFileEvaluator::Private::insertComment(const QString &comment)
|
||||||
{
|
{
|
||||||
updateItem();
|
|
||||||
|
|
||||||
QString strComment;
|
QString strComment;
|
||||||
if (!m_commentItem)
|
if (!m_commentItem)
|
||||||
strComment = m_pendingComment;
|
strComment = m_pendingComment;
|
||||||
|
|||||||
Reference in New Issue
Block a user