re PR libgcj/29178 (CharsetEncoder.canEncode() gives different results than Sun version)

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.

From-SVN: r117209
This commit is contained in:
Tom Tromey 2006-09-25 21:04:01 +00:00 committed by Tom Tromey
parent 9b910171a0
commit a7bf80389a
4 changed files with 56 additions and 1 deletions

View File

@ -1,3 +1,16 @@
2006-09-25 Tom Tromey <tromey@redhat.com>
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 <tromey@redhat.com>
* native/fdlibm/mprec.c (mprec_calloc): Renamed.

View File

@ -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()

View File

@ -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()

View File

@ -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);