Escape surrogate characters
This commit is contained in:
@@ -18,7 +18,7 @@ internal final annotation class CharAnno : kotlin.Annotation {
|
||||
internal final fun <get-value>(): kotlin.Char
|
||||
}
|
||||
|
||||
test.IntAnno(value = 42: kotlin.Int) test.ShortAnno(value = 42.toShort(): kotlin.Short) test.ByteAnno(value = 42.toByte(): kotlin.Byte) test.LongAnno(value = 42.toLong(): kotlin.Long) test.CharAnno(value = #65(A): kotlin.Char) test.BooleanAnno(value = false: kotlin.Boolean) test.FloatAnno(value = 3.14.toFloat(): kotlin.Float) test.DoubleAnno(value = 3.14.toDouble(): kotlin.Double) internal final class Class {
|
||||
test.IntAnno(value = 42: kotlin.Int) test.ShortAnno(value = 42.toShort(): kotlin.Short) test.ByteAnno(value = 42.toByte(): kotlin.Byte) test.LongAnno(value = 42.toLong(): kotlin.Long) test.CharAnno(value = \u0041 ('A'): kotlin.Char) test.BooleanAnno(value = false: kotlin.Boolean) test.FloatAnno(value = 3.14.toFloat(): kotlin.Float) test.DoubleAnno(value = 3.14.toDouble(): kotlin.Double) internal final class Class {
|
||||
/*primary*/ public constructor Class()
|
||||
}
|
||||
|
||||
|
||||
@@ -13,5 +13,7 @@ val f: Float = 3.14f
|
||||
val d: Double = 3.14
|
||||
val bb: Boolean = true
|
||||
val c: Char = '\u03c0' // pi symbol
|
||||
val MAX_HIGH_SURROGATE: Char = '\uDBFF'
|
||||
val nl = '\n'
|
||||
|
||||
val str: String = ":)"
|
||||
@@ -1,12 +1,14 @@
|
||||
package test
|
||||
|
||||
internal val MAX_HIGH_SURROGATE: kotlin.Char = \uDBFF ('?')
|
||||
internal fun <get-MAX_HIGH_SURROGATE>(): kotlin.Char
|
||||
internal val b: kotlin.Byte = 100.toByte()
|
||||
internal fun <get-b>(): kotlin.Byte
|
||||
internal val b1: kotlin.Byte = 1.toByte()
|
||||
internal fun <get-b1>(): kotlin.Byte
|
||||
internal val bb: kotlin.Boolean = true
|
||||
internal fun <get-bb>(): kotlin.Boolean
|
||||
internal val c: kotlin.Char = #960(π)
|
||||
internal val c: kotlin.Char = \u03C0 ('π')
|
||||
internal fun <get-c>(): kotlin.Char
|
||||
internal val d: kotlin.Double = 3.14.toDouble()
|
||||
internal fun <get-d>(): kotlin.Double
|
||||
@@ -20,9 +22,11 @@ internal val l: kotlin.Long = 2000000000000.toLong()
|
||||
internal fun <get-l>(): kotlin.Long
|
||||
internal val l1: kotlin.Long = 1.toLong()
|
||||
internal fun <get-l1>(): kotlin.Long
|
||||
internal val nl: kotlin.Char = \u000A ('\n')
|
||||
internal fun <get-nl>(): kotlin.Char
|
||||
internal val s: kotlin.Short = 20000.toShort()
|
||||
internal fun <get-s>(): kotlin.Short
|
||||
internal val s1: kotlin.Short = 1.toShort()
|
||||
internal fun <get-s1>(): kotlin.Short
|
||||
internal val str: kotlin.String = ":)"
|
||||
internal fun <get-str>(): kotlin.String
|
||||
internal fun <get-str>(): kotlin.String
|
||||
|
||||
@@ -13,4 +13,4 @@ annotation class Ann(
|
||||
|
||||
Ann('c', 99.toChar(), 'c'.toInt(), 'c'.toLong(), 'c'.toByte(), 'c'.toShort(), 'c'.toDouble(), 'c'.toFloat()) class MyClass
|
||||
|
||||
// EXPECTED: Ann(b1 = #99(c): Char, b2 = #99(c): Char, b3 = 99: Int, b4 = 99.toLong(): Long, b5 = 99.toByte(): Byte, b6 = 99.toShort(): Short, b7 = 99.0.toDouble(): Double, b8 = 99.0.toFloat(): Float)
|
||||
// EXPECTED: Ann(b1 = \u0063 ('c'): Char, b2 = \u0063 ('c'): Char, b3 = 99: Int, b4 = 99.toLong(): Long, b5 = 99.toByte(): Byte, b6 = 99.toShort(): Short, b7 = 99.0.toDouble(): Double, b8 = 99.0.toFloat(): Float)
|
||||
@@ -40,6 +40,29 @@ public class CharValue extends IntegerValueConstant<Character> {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "#" + ((int) value) + "(" + value + ")";
|
||||
return String.format("\\u%04X ('%s')", (int) value, getPrintablePart(value));
|
||||
}
|
||||
|
||||
private static String getPrintablePart(char c) {
|
||||
switch (c) {
|
||||
case '\b':
|
||||
return "\\b";
|
||||
case '\t':
|
||||
return "\\t";
|
||||
case '\n':
|
||||
return "\\n";
|
||||
case '\f':
|
||||
return "\\f";
|
||||
case '\r':
|
||||
return "\\r";
|
||||
default:
|
||||
return isPrintableUnicode(c) ? Character.toString(c) : "?";
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean isPrintableUnicode(char c) {
|
||||
int t = Character.getType(c);
|
||||
return t != Character.UNASSIGNED && t != Character.LINE_SEPARATOR && t != Character.PARAGRAPH_SEPARATOR &&
|
||||
t != Character.CONTROL && t != Character.FORMAT && t != Character.PRIVATE_USE && t != Character.SURROGATE;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user