Identifier collection now smarter about strings
Previously, a string like 'foo\'bar\'zoo' would make the collection process think that "bar" is not inside a string because it wouldn't recognize that the quotes are escaped. Now it does. Fixes #143.
This commit is contained in:
parent
101d949a88
commit
fd2fd60f7c
@ -30,9 +30,11 @@ const char *COMMENT_AND_STRING_REGEX =
|
||||
"|"
|
||||
"/\\*.*?\\*/" // C-style comments, '/* ... */'
|
||||
"|"
|
||||
"'[^']*'" // Anything inside single quotes, '...'
|
||||
"'(?:\\\\'|.)*?'" // Anything inside single quotes, '...', but mind the
|
||||
// escaped quote
|
||||
"|"
|
||||
"\"[^\"]*\""; // Anything inside double quotes, "..."
|
||||
"\"(?:\\\\\"|.)*?\""; // Anything inside double quotes, "...", but mind
|
||||
// the escaped double quote
|
||||
|
||||
const char *IDENTIFIER_REGEX = "[_a-zA-Z]\\w*";
|
||||
|
||||
|
@ -63,6 +63,15 @@ TEST( IdentifierUtilsTest, RemoveIdentifierFreeTextWorks ) {
|
||||
"bar \n"
|
||||
"qux" );
|
||||
|
||||
EXPECT_STREQ( RemoveIdentifierFreeText(
|
||||
"foo \n"
|
||||
"bar 'fo\\'oz\\nfoo'\n"
|
||||
"qux"
|
||||
).c_str(),
|
||||
"foo \n"
|
||||
"bar \n"
|
||||
"qux" );
|
||||
|
||||
EXPECT_STREQ( RemoveIdentifierFreeText(
|
||||
"foo \n"
|
||||
"bar \"foo\"\n"
|
||||
@ -71,6 +80,15 @@ TEST( IdentifierUtilsTest, RemoveIdentifierFreeTextWorks ) {
|
||||
"foo \n"
|
||||
"bar \n"
|
||||
"qux" );
|
||||
|
||||
EXPECT_STREQ( RemoveIdentifierFreeText(
|
||||
"foo \n"
|
||||
"bar \"fo\\\"oz\\nfoo\"\n"
|
||||
"qux"
|
||||
).c_str(),
|
||||
"foo \n"
|
||||
"bar \n"
|
||||
"qux" );
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user