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:
Strahinja Val Markovic 2013-02-21 22:12:34 -08:00
parent 101d949a88
commit fd2fd60f7c
2 changed files with 22 additions and 2 deletions

View File

@ -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*";

View File

@ -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" );
}