diff --git a/libjava/classpath/ChangeLog.gcj b/libjava/classpath/ChangeLog.gcj index 3503a07edf7..81112e50159 100644 --- a/libjava/classpath/ChangeLog.gcj +++ b/libjava/classpath/ChangeLog.gcj @@ -1,3 +1,16 @@ +2006-09-25 Tom Tromey + + PR libgcj/29178: + * gnu/java/nio/charset/US_ASCII.java (Encoder.canEncode): New method. + (Encoder.canEncode): Likewise. + (Encoder.encodeLoop): Return unmappable for all non-ASCII characters. + * gnu/java/nio/charset/ByteCharset.java (Encoder.canEncode): New + method. + (Encoder.canEncode): Likewise. + * gnu/java/nio/charset/ISO_8859_1.java (Encoder.canEncode): New + method. + (Encoder.canEncode): Likewise. + 2006-09-25 Tom Tromey * native/fdlibm/mprec.c (mprec_calloc): Renamed. diff --git a/libjava/classpath/gnu/java/nio/charset/ByteCharset.java b/libjava/classpath/gnu/java/nio/charset/ByteCharset.java index 2cc91b850f6..da0fdcbcdb3 100644 --- a/libjava/classpath/gnu/java/nio/charset/ByteCharset.java +++ b/libjava/classpath/gnu/java/nio/charset/ByteCharset.java @@ -156,6 +156,22 @@ abstract class ByteCharset extends Charset } } + public boolean canEncode(char c) + { + byte b = (c < lookup.length) ? lookup[c] : 0; + return b != 0 || c == 0; + } + + public boolean canEncode(CharSequence cs) + { + for (int i = 0; i < cs.length(); ++i) + { + if (! canEncode(cs.charAt(i))) + return false; + } + return true; + } + protected CoderResult encodeLoop (CharBuffer in, ByteBuffer out) { // TODO: Optimize this in the case in.hasArray() / out.hasArray() diff --git a/libjava/classpath/gnu/java/nio/charset/ISO_8859_1.java b/libjava/classpath/gnu/java/nio/charset/ISO_8859_1.java index cc06ecd5ad0..2a3073a32ed 100644 --- a/libjava/classpath/gnu/java/nio/charset/ISO_8859_1.java +++ b/libjava/classpath/gnu/java/nio/charset/ISO_8859_1.java @@ -128,6 +128,19 @@ final class ISO_8859_1 extends Charset super (cs, 1.0f, 1.0f); } + public boolean canEncode(char c) + { + return c <= 0xff; + } + + public boolean canEncode(CharSequence cs) + { + for (int i = 0; i < cs.length(); ++i) + if (! canEncode(cs.charAt(i))) + return false; + return true; + } + protected CoderResult encodeLoop (CharBuffer in, ByteBuffer out) { // TODO: Optimize this in the case in.hasArray() / out.hasArray() diff --git a/libjava/classpath/gnu/java/nio/charset/US_ASCII.java b/libjava/classpath/gnu/java/nio/charset/US_ASCII.java index d26f7ffc9ab..8888416bebf 100644 --- a/libjava/classpath/gnu/java/nio/charset/US_ASCII.java +++ b/libjava/classpath/gnu/java/nio/charset/US_ASCII.java @@ -134,6 +134,19 @@ final class US_ASCII extends Charset super (cs, 1.0f, 1.0f); } + public boolean canEncode(char c) + { + return c <= 0x7f; + } + + public boolean canEncode(CharSequence cs) + { + for (int i = 0; i < cs.length(); ++i) + if (! canEncode(cs.charAt(i))) + return false; + return true; + } + protected CoderResult encodeLoop (CharBuffer in, ByteBuffer out) { // TODO: Optimize this in the case in.hasArray() / out.hasArray() @@ -141,7 +154,7 @@ final class US_ASCII extends Charset { char c = in.get (); - if (c > Byte.MAX_VALUE) + if (c > 0x7f) { in.position (in.position () - 1); return CoderResult.unmappableForLength (1);