fixed PY-2915 Convert double-quoted string to single-quoted string: breaks code in case of escaped characters

This commit is contained in:
Ekaterina Tuzova
2011-02-11 18:20:43 +03:00
parent 804e3f12f7
commit 5dbe9b9c95
4 changed files with 7 additions and 7 deletions
@@ -55,12 +55,12 @@ public class PyQuotedStringIntention extends BaseIntentionAction {
if (string != null) {
String stringText = string.getText();
if (stringText.startsWith("'") && stringText.endsWith("'")) {
String result = convertSingleToDoubleQuoted(stringText);
String result = convertSingleToDoubleQuoted(stringText.substring(1, stringText.length()-1));
PyStringLiteralExpression st = elementGenerator.createStringLiteralAlreadyEscaped(result);
string.replace(st);
}
if (stringText.startsWith("\"") && stringText.endsWith("\"")) {
String result = convertDoubleToSingleQuoted(string.getStringValue());
String result = convertDoubleToSingleQuoted(stringText);
PyStringLiteralExpression st = elementGenerator.createStringLiteralAlreadyEscaped(result);
string.replace(st);
}
@@ -85,7 +85,7 @@ public class PyQuotedStringIntention extends BaseIntentionAction {
else if (ch == '\'') {
stringBuilder.append("\\\'");
}
else if (ch == '\\') {
else if (ch == '\\' && charArr[i+1] == '\"') {
skipNext = true;
stringBuilder.append(charArr[i+1]);
}
@@ -115,7 +115,7 @@ public class PyQuotedStringIntention extends BaseIntentionAction {
else if (ch == '"') {
stringBuilder.append("\\\"");
}
else if (ch == '\\') {
else if (ch == '\\' && charArr[i+1] == '\'') {
skipNext = true;
stringBuilder.append(charArr[i+1]);
}
@@ -1 +1 @@
a = '\'Hello\' - said man.'
a = '\'Hello\' - said man.\n Let\'s go.'
@@ -1 +1 @@
a = "'Hello'<caret> - said man."
a = "'Hello'<caret> - said man.\n Let's go."
@@ -139,7 +139,7 @@ public class PyIntentionTest extends PyLightFixtureTestCase {
assertNull(action);
}
public void testQuotedString() {
public void testQuotedString() { //PY-2915
doTest(PyBundle.message("INTN.quoted.string.double.to.single"));
}