diff --git a/cpp/ycm/IdentifierUtils.cpp b/cpp/ycm/IdentifierUtils.cpp index fbfac6cb..b559b9be 100644 --- a/cpp/ycm/IdentifierUtils.cpp +++ b/cpp/ycm/IdentifierUtils.cpp @@ -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*"; diff --git a/cpp/ycm/tests/IdentifierUtils_test.cpp b/cpp/ycm/tests/IdentifierUtils_test.cpp index 04f16a57..48092c1e 100644 --- a/cpp/ycm/tests/IdentifierUtils_test.cpp +++ b/cpp/ycm/tests/IdentifierUtils_test.cpp @@ -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" ); }