Ident collector handles escaped starting quotes

Previously, it would consider \"foo\"bar" as a slash and a "foo\"bar" string and
this would screw up tracking of quotes in the file.

Fix #535.
This commit is contained in:
Strahinja Val Markovic 2013-08-30 14:38:23 -07:00
parent 7cc399a017
commit 62462b48bc
2 changed files with 25 additions and 6 deletions

View File

@ -37,13 +37,18 @@ const char *COMMENT_AND_STRING_REGEX =
"|"
"/\\*.*?\\*/" // C-style comments, '/* ... */'
"|"
// Anything inside single quotes, '...', but mind the escaped quote and the
// escaped slash (\\)
"'(?:\\\\\\\\|\\\\'|.)*?'"
// Anything inside single quotes, '...', but mind:
// 1. that the starting single quote is not escaped
// 2. the escaped slash (\\)
// 3. the escaped single quote inside the string
// "(?<!\\\\)'(?:\\\\\\\\|\\\\'|.)*?'"
"(?<!\\\\)'(?:\\\\\\\\|\\\\'|.)*?'"
"|"
// Anything inside double quotes, "...", but mind the escaped double quote and
// the escaped slash (\\)
"\"(?:\\\\\\\\|\\\\\"|.)*?\"";
// Anything inside double quotes, "...", but mind:
// 1. that the starting double quote is not escaped
// 2. the escaped slash (\\)
// 3. the escaped double quote inside the string
"(?<!\\\\)\"(?:\\\\\\\\|\\\\\"|.)*?\"";
const char *IDENTIFIER_REGEX = "[_a-zA-Z]\\w*";

View File

@ -112,6 +112,20 @@ TEST( IdentifierUtilsTest, RemoveIdentifierFreeTextWorks ) {
"foo \n"
"bar \n"
"qux " );
EXPECT_STREQ( RemoveIdentifierFreeText(
"\\\"foo\\\""
"'\"'"
"'bar' zoo'test'"
).c_str(),
"\\\"foo\\\" zoo" );
EXPECT_STREQ( RemoveIdentifierFreeText(
"\\'foo\\'"
"\"'\""
"\"bar\" zoo\"test\""
).c_str(),
"\\'foo\\' zoo" );
}