提交 293e67d4 编写于 作者: S sherman

6730652: CharsetEncoder.canEncode(char) returns incorrect values for some charsets

Summary: override the canEncode() in ISO2022_CN_CNS
Reviewed-by: martin
上级 0afcf0de
...@@ -388,9 +388,9 @@ abstract class ISO2022 ...@@ -388,9 +388,9 @@ abstract class ISO2022
protected static class Encoder extends CharsetEncoder { protected static class Encoder extends CharsetEncoder {
private final Surrogate.Parser sgp = new Surrogate.Parser(); private final Surrogate.Parser sgp = new Surrogate.Parser();
private final byte SS2 = (byte)0x8e; public static final byte SS2 = (byte)0x8e;
private final byte PLANE2 = (byte)0xA2; public static final byte PLANE2 = (byte)0xA2;
private final byte PLANE3 = (byte)0xA3; public static final byte PLANE3 = (byte)0xA3;
private final byte MSB = (byte)0x80; private final byte MSB = (byte)0x80;
protected final byte maximumDesignatorLength = 4; protected final byte maximumDesignatorLength = 4;
......
...@@ -76,6 +76,15 @@ public class ISO2022_CN_CNS extends ISO2022 implements HistoricallyNamedCharset ...@@ -76,6 +76,15 @@ public class ISO2022_CN_CNS extends ISO2022 implements HistoricallyNamedCharset
} catch (Exception e) { } } catch (Exception e) { }
} }
private byte[] bb = new byte[4];
public boolean canEncode(char c) {
int n = 0;
return (c <= '\u007f' ||
(n = ((EUC_TW.Encoder)ISOEncoder).toEUC(c, bb)) == 2 ||
(n == 4 && bb[0] == SS2 &&
(bb[1] == PLANE2 || bb[1] == PLANE3)));
}
/* /*
* Since ISO2022-CN-CNS possesses a CharsetEncoder * Since ISO2022-CN-CNS possesses a CharsetEncoder
* without the corresponding CharsetDecoder half the * without the corresponding CharsetDecoder half the
......
...@@ -22,7 +22,7 @@ ...@@ -22,7 +22,7 @@
*/ */
/* @test /* @test
@bug 5066863 5066867 5066874 5066879 5066884 5066887 5065777 @bug 5066863 5066867 5066874 5066879 5066884 5066887 5065777 6730652
@summary canEncode() false iff encode() throws CharacterCodingException @summary canEncode() false iff encode() throws CharacterCodingException
@run main/timeout=1200 FindCanEncodeBugs @run main/timeout=1200 FindCanEncodeBugs
@author Martin Buchholz @author Martin Buchholz
...@@ -52,9 +52,7 @@ public class FindCanEncodeBugs { ...@@ -52,9 +52,7 @@ public class FindCanEncodeBugs {
String csn = e.getKey(); String csn = e.getKey();
Charset cs = e.getValue(); Charset cs = e.getValue();
if (! cs.canEncode() || if (! cs.canEncode() || csn.matches("x-COMPOUND_TEXT"))
csn.matches("x-COMPOUND_TEXT") ||
csn.matches("x-ISO-2022-CN-CNS")) // ISO2022_CN_CNS supports less
continue; continue;
//System.out.println(csn); //System.out.println(csn);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册