@@ -1164,11 +1164,31 @@ void Lexer::lexStringLiteral() {
1164
1164
if (*TokStart == ' \' ' ) {
1165
1165
// Complain about single-quote string and suggest replacement with
1166
1166
// double-quoted equivalent.
1167
- // FIXME: Fixit should replace ['"'] with ["\""] (radar 22709931)
1168
1167
StringRef orig (TokStart, CurPtr - TokStart);
1169
1168
llvm::SmallString<32 > replacement;
1170
1169
replacement += ' "' ;
1171
- replacement += orig.slice (1 , orig.size () - 1 );
1170
+ std::string str = orig.slice (1 , orig.size () - 1 ).str ();
1171
+ std::string quot = " \" " ;
1172
+ size_t pos = 0 ;
1173
+ while (pos != str.length ()) {
1174
+ if (str.at (pos) == ' \\ ' ) {
1175
+ if (str.at (pos + 1 ) == ' \' ' ) {
1176
+ // Un-escape escaped single quotes.
1177
+ str.replace (pos, 2 , " '" );
1178
+ ++pos;
1179
+ } else {
1180
+ // Skip over escaped characters.
1181
+ pos += 2 ;
1182
+ }
1183
+ } else if (str.at (pos) == ' "' ) {
1184
+ str.replace (pos, 1 , " \\\" " );
1185
+ // Advance past the newly added ["\""].
1186
+ pos += 2 ;
1187
+ } else {
1188
+ ++pos;
1189
+ }
1190
+ }
1191
+ replacement += StringRef (str);
1172
1192
replacement += ' "' ;
1173
1193
diagnose (TokStart, diag::lex_single_quote_string)
1174
1194
.fixItReplaceChars (getSourceLoc (TokStart), getSourceLoc (CurPtr),
0 commit comments