-/* ISO_8859_1.java --
+/* ISO_8859_1.java --
Copyright (C) 2002, 2004, 2005 Free Software Foundation, Inc.
This file is part of GNU Classpath.
* ISO-8859-1 charset.
*
* @author Jesse Rosenstock
+ * @modified Ian Rogers
*/
final class ISO_8859_1 extends Charset
{
* http://java.sun.com/j2se/1.5.0/docs/guide/intl/encoding.doc.html
*/
super ("ISO-8859-1", new String[] {
- /* These names are provided by
+ /* These names are provided by
* http://www.iana.org/assignments/character-sets
*/
"iso-ir-100",
/* These names are provided by
* http://oss.software.ibm.com/cgi-bin/icu/convexp?s=ALL
*/
- "ISO8859_1", "ISO_8859_1", "ibm-819", "ISO_8859-1:1987",
- "819"
+ "ISO8859_1",
+ "ISO_8859_1",
+ "ibm-819",
+ "ISO_8859-1:1987",
+ "819",
+ "ISO8859-1"
});
}
private static final class Decoder extends CharsetDecoder
{
+ /** Helper to decode loops */
+ private static final ByteDecodeLoopHelper helper = new ByteDecodeLoopHelper()
+ {
+ protected boolean isMappable(byte b)
+ {
+ return true;
+ }
+ protected char mapToChar(byte b)
+ {
+ return (char)(b & 0xFF);
+ }
+ };
+
// Package-private to avoid a trampoline constructor.
Decoder (Charset cs)
{
protected CoderResult decodeLoop (ByteBuffer in, CharBuffer out)
{
- // TODO: Optimize this in the case in.hasArray() / out.hasArray()
- while (in.hasRemaining ())
- {
- byte b = in.get ();
-
- if (!out.hasRemaining ())
- {
- in.position (in.position () - 1);
- return CoderResult.OVERFLOW;
- }
-
- out.put ((char) (b & 0xFF));
- }
-
- return CoderResult.UNDERFLOW;
+ return helper.decodeLoop(in, out);
}
}
private static final class Encoder extends CharsetEncoder
{
+ /** Helper to encode loops */
+ private static final ByteEncodeLoopHelper helper = new ByteEncodeLoopHelper()
+ {
+ protected boolean isMappable(char c)
+ {
+ return c <= 0xff;
+ }
+ protected byte mapToByte(char c)
+ {
+ return (byte)c;
+ }
+ };
// Package-private to avoid a trampoline constructor.
Encoder (Charset cs)
{
super (cs, 1.0f, 1.0f);
}
- protected CoderResult encodeLoop (CharBuffer in, ByteBuffer out)
+ public boolean canEncode(char c)
{
- // TODO: Optimize this in the case in.hasArray() / out.hasArray()
- while (in.hasRemaining ())
- {
- char c = in.get ();
-
- if (c > 0xFF)
- {
- in.position (in.position () - 1);
- return CoderResult.unmappableForLength (1);
- }
- if (!out.hasRemaining ())
- {
- in.position (in.position () - 1);
- return CoderResult.OVERFLOW;
- }
-
- out.put ((byte) 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;
+ }
- return CoderResult.UNDERFLOW;
+ protected CoderResult encodeLoop (CharBuffer in, ByteBuffer out)
+ {
+ return helper.encodeLoop(in, out);
}
}
}