IDEA-167346 Do not escape single quote in strings

This commit is contained in:
Egor.Ushakov
2017-02-07 17:51:02 +03:00
parent 45384fb8c5
commit f53a873116
5 changed files with 84 additions and 19 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2000-2016 JetBrains s.r.o.
* Copyright 2000-2017 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -33,17 +33,17 @@ import java.util.*;
import java.util.Map.Entry;
public class ConstExprent extends Exprent {
private static final Map<Integer, String> ESCAPES;
private static final Map<Integer, String> CHAR_ESCAPES;
static {
ESCAPES = new HashMap<>();
ESCAPES.put(new Integer(0x8), "\\b"); /* \u0008: backspace BS */
ESCAPES.put(new Integer(0x9), "\\t"); /* \u0009: horizontal tab HT */
ESCAPES.put(new Integer(0xA), "\\n"); /* \u000a: linefeed LF */
ESCAPES.put(new Integer(0xC), "\\f"); /* \u000c: form feed FF */
ESCAPES.put(new Integer(0xD), "\\r"); /* \u000d: carriage return CR */
ESCAPES.put(new Integer(0x22), "\\\""); /* \u0022: double quote " */
ESCAPES.put(new Integer(0x27), "\\\'"); /* \u0027: single quote ' */
ESCAPES.put(new Integer(0x5C), "\\\\"); /* \u005c: backslash \ */
CHAR_ESCAPES = new HashMap<>();
CHAR_ESCAPES.put(new Integer(0x8), "\\b"); /* \u0008: backspace BS */
CHAR_ESCAPES.put(new Integer(0x9), "\\t"); /* \u0009: horizontal tab HT */
CHAR_ESCAPES.put(new Integer(0xA), "\\n"); /* \u000a: linefeed LF */
CHAR_ESCAPES.put(new Integer(0xC), "\\f"); /* \u000c: form feed FF */
CHAR_ESCAPES.put(new Integer(0xD), "\\r"); /* \u000d: carriage return CR */
//CHAR_ESCAPES.put(new Integer(0x22), "\\\""); /* \u0022: double quote " */
CHAR_ESCAPES.put(new Integer(0x27), "\\\'"); /* \u0027: single quote ' */
CHAR_ESCAPES.put(new Integer(0x5C), "\\\\"); /* \u005c: backslash \ */
}
private VarType constType;
@@ -130,7 +130,7 @@ public class ConstExprent extends Exprent {
case CodeConstants.TYPE_CHAR:
Integer val = (Integer)value;
String ret = ESCAPES.get(val);
String ret = CHAR_ESCAPES.get(val);
if (ret == null) {
char c = (char)val.intValue();
if (c >= 32 && c < 127 || !ascii && TextUtil.isPrintableUnicode(c)) {
@@ -140,7 +140,7 @@ public class ConstExprent extends Exprent {
ret = TextUtil.charToUnicodeLiteral(c);
}
}
return new TextBuffer().append('\'').append(ret).append('\'');
return new TextBuffer(ret).enclose("'", "'");
case CodeConstants.TYPE_BYTE:
case CodeConstants.TYPE_BYTECHAR:
@@ -235,7 +235,7 @@ public class ConstExprent extends Exprent {
case CodeConstants.TYPE_OBJECT:
if (constType.equals(VarType.VARTYPE_STRING)) {
return new TextBuffer().append('"').append(convertStringToJava(value.toString(), ascii)).append('"');
return new TextBuffer(convertStringToJava(value.toString(), ascii)).enclose("\"", "\"");
}
else if (constType.equals(VarType.VARTYPE_CLASS)) {
String stringVal = value.toString();
@@ -274,9 +274,9 @@ public class ConstExprent extends Exprent {
case 0x22: //"\\\\\""); // u0022: double quote "
buffer.append("\\\"");
break;
case 0x27: //"\\\\'"); // u0027: single quote '
buffer.append("\\\'");
break;
//case 0x27: //"\\\\'"); // u0027: single quote '
// buffer.append("\\\'");
// break;
default:
if (c >= 32 && c < 127 || !ascii && TextUtil.isPrintableUnicode(c)) {
buffer.append(c);