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:
parent
7cc399a017
commit
62462b48bc
@ -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*";
|
||||
|
||||
|
@ -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" );
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user