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, '/* ... */'
|
"/\\*.*?\\*/" // C-style comments, '/* ... */'
|
||||||
"|"
|
"|"
|
||||||
// Anything inside single quotes, '...', but mind the escaped quote and the
|
// Anything inside single quotes, '...', but mind:
|
||||||
// escaped slash (\\)
|
// 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
|
// Anything inside double quotes, "...", but mind:
|
||||||
// the escaped slash (\\)
|
// 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*";
|
const char *IDENTIFIER_REGEX = "[_a-zA-Z]\\w*";
|
||||||
|
|
||||||
|
@ -112,6 +112,20 @@ TEST( IdentifierUtilsTest, RemoveIdentifierFreeTextWorks ) {
|
|||||||
"foo \n"
|
"foo \n"
|
||||||
"bar \n"
|
"bar \n"
|
||||||
"qux " );
|
"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