Skip to content

Commit 01497f2

Browse files
committed
at sign (@) not handled correctly in preprocessor (more fixes)
1 parent 4b44e7e commit 01497f2

File tree

1 file changed

+40
-34
lines changed

1 file changed

+40
-34
lines changed

src/pre.l

Lines changed: 40 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1161,6 +1161,44 @@ static void expandExpression(QCString &expr,QCString *rest,int pos)
11611161
}
11621162
}
11631163

1164+
/*! @brief Process string or character literal.
1165+
*
1166+
* \a inputStr should point to the start of a string or character literal.
1167+
* the routine will return a pointer to just after the end of the literal
1168+
* the character making up the literal will be added to \a result.
1169+
*/
1170+
const char *processUntilMatchingTerminator(const char *inputStr,QCString &result)
1171+
{
1172+
if (inputStr==0) return inputStr;
1173+
char term = *inputStr; // capture start character of the literal
1174+
if (term==0 || (term!='\'' && term!='"')) return inputStr; // not a valid literal
1175+
char c=term;
1176+
// output start character
1177+
result+=c;
1178+
inputStr++;
1179+
while ((c=*inputStr)) // while inside the literal
1180+
{
1181+
if (c==term) // found end marker of the literal
1182+
{
1183+
// output end character and stop
1184+
result+=c;
1185+
inputStr++;
1186+
break;
1187+
}
1188+
else if (c=='\\') // escaped character, process next character
1189+
// as well without checking for end marker.
1190+
{
1191+
result+=c;
1192+
inputStr++;
1193+
c=*inputStr;
1194+
if (c==0) break; // unexpected end of string after escape character
1195+
}
1196+
result+=c;
1197+
inputStr++;
1198+
}
1199+
return inputStr;
1200+
}
1201+
11641202
/*! replaces all occurrences of @@@@ in \a s by @@
11651203
* and removes all occurrences of @@E.
11661204
* All identifiers found are replaced by 0L
@@ -1196,17 +1234,7 @@ QCString removeIdsAndMarkers(const char *s)
11961234
}
11971235
else if (c=='\'') // quoted character
11981236
{
1199-
result+=c;
1200-
p++;
1201-
char pc=c;
1202-
while ((c=*p) && (c!='\'' || pc=='\\'))
1203-
{
1204-
result+=c;
1205-
pc=c;
1206-
p++;
1207-
}
1208-
result+=c;
1209-
p++;
1237+
p = processUntilMatchingTerminator(p,result);
12101238
}
12111239
else if (c=='d' && !inNum) // identifier starting with a `d'
12121240
{
@@ -1334,30 +1362,8 @@ QCString removeMarkers(const char *s)
13341362
}
13351363
break;
13361364
case '"': // skip string literals
1337-
{
1338-
result+=c;
1339-
char pc=c;
1340-
c=*++p;
1341-
while (*p && (c!='"' || pc=='\\')) // no end quote
1342-
{
1343-
result+=c;
1344-
c=*++p;
1345-
}
1346-
if (*p) result+=c,p++;
1347-
}
1348-
break;
13491365
case '\'': // skip char literals
1350-
{
1351-
result+=c;
1352-
char pc=c;
1353-
c=*++p;
1354-
while (*p && (c!='\'' || pc=='\\')) // no end quote
1355-
{
1356-
result+=c;
1357-
c=*++p;
1358-
}
1359-
if (*p) result+=c,p++;
1360-
}
1366+
p = processUntilMatchingTerminator(p,result);
13611367
break;
13621368
default:
13631369
{

0 commit comments

Comments
 (0)