Commit a7bf8038 by Tom Tromey Committed by Tom Tromey

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
parent 9b910171
2006-09-25 Tom Tromey <tromey@redhat.com> 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. * native/fdlibm/mprec.c (mprec_calloc): Renamed.
(Balloc): Updated. (Balloc): Updated.
......
...@@ -156,6 +156,22 @@ abstract class ByteCharset extends Charset ...@@ -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) protected CoderResult encodeLoop (CharBuffer in, ByteBuffer out)
{ {
// TODO: Optimize this in the case in.hasArray() / out.hasArray() // TODO: Optimize this in the case in.hasArray() / out.hasArray()
......
...@@ -128,6 +128,19 @@ final class ISO_8859_1 extends Charset ...@@ -128,6 +128,19 @@ final class ISO_8859_1 extends Charset
super (cs, 1.0f, 1.0f); 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) protected CoderResult encodeLoop (CharBuffer in, ByteBuffer out)
{ {
// TODO: Optimize this in the case in.hasArray() / out.hasArray() // TODO: Optimize this in the case in.hasArray() / out.hasArray()
......
...@@ -134,6 +134,19 @@ final class US_ASCII extends Charset ...@@ -134,6 +134,19 @@ final class US_ASCII extends Charset
super (cs, 1.0f, 1.0f); 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) protected CoderResult encodeLoop (CharBuffer in, ByteBuffer out)
{ {
// TODO: Optimize this in the case in.hasArray() / out.hasArray() // TODO: Optimize this in the case in.hasArray() / out.hasArray()
...@@ -141,7 +154,7 @@ final class US_ASCII extends Charset ...@@ -141,7 +154,7 @@ final class US_ASCII extends Charset
{ {
char c = in.get (); char c = in.get ();
if (c > Byte.MAX_VALUE) if (c > 0x7f)
{ {
in.position (in.position () - 1); in.position (in.position () - 1);
return CoderResult.unmappableForLength (1); return CoderResult.unmappableForLength (1);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment