2 *******************************************************************************
\r
3 * Copyright (C) 2006-2008, International Business Machines Corporation and *
\r
4 * others. All Rights Reserved. *
\r
5 *******************************************************************************
\r
8 package com.ibm.icu.charset;
\r
10 import java.nio.BufferOverflowException;
\r
11 import java.nio.BufferUnderflowException;
\r
12 import java.nio.ByteBuffer;
\r
13 import java.nio.CharBuffer;
\r
14 import java.nio.charset.CharsetDecoder;
\r
15 import java.nio.charset.CharsetEncoder;
\r
16 import java.nio.charset.CoderResult;
\r
18 import com.ibm.icu.text.UnicodeSet;
\r
20 class Charset88591 extends CharsetASCII {
\r
21 public Charset88591(String icuCanonicalName, String javaCanonicalName, String[] aliases) {
\r
22 super(icuCanonicalName, javaCanonicalName, aliases);
\r
25 class CharsetDecoder88591 extends CharsetDecoderASCII {
\r
26 public CharsetDecoder88591(CharsetICU cs) {
\r
30 protected CoderResult decodeLoopCoreOptimized(ByteBuffer source, CharBuffer target,
\r
31 byte[] sourceArray, char[] targetArray, int oldSource, int offset, int limit) {
\r
34 * perform 88591 conversion from the source array to the target array. no range check is
\r
37 for (int i = oldSource; i < limit; i++)
\r
38 targetArray[i + offset] = (char) (sourceArray[i] & 0xff);
\r
43 protected CoderResult decodeLoopCoreUnoptimized(ByteBuffer source, CharBuffer target)
\r
44 throws BufferUnderflowException, BufferOverflowException {
\r
47 * perform 88591 conversion from the source buffer to the target buffer. no range check
\r
48 * is necessary (an exception will be generated to end the loop).
\r
51 target.put((char) (source.get() & 0xff));
\r
55 class CharsetEncoder88591 extends CharsetEncoderASCII {
\r
56 public CharsetEncoder88591(CharsetICU cs) {
\r
60 protected final CoderResult encodeLoopCoreOptimized(CharBuffer source, ByteBuffer target,
\r
61 char[] sourceArray, byte[] targetArray, int oldSource, int offset, int limit,
\r
66 * perform 88591 conversion from the source array to the target array, making sure each
\r
67 * char in the source is within the correct range
\r
69 for (i = oldSource; i < limit; i++) {
\r
70 ch = (int) sourceArray[i];
\r
71 if ((ch & 0xff00) == 0) {
\r
72 targetArray[i + offset] = (byte) ch;
\r
79 * if some byte was not in the correct range, we need to deal with this byte by calling
\r
80 * encodeMalformedOrUnmappable and move the source and target positions to reflect the
\r
81 * early termination of the loop
\r
83 if ((ch & 0xff00) != 0) {
\r
84 source.position(i + 1);
\r
85 target.position(i + offset);
\r
86 return encodeMalformedOrUnmappable(source, ch, flush);
\r
91 protected final CoderResult encodeLoopCoreUnoptimized(CharBuffer source, ByteBuffer target,
\r
92 boolean flush) throws BufferUnderflowException, BufferOverflowException {
\r
96 * perform 88591 conversion from the source buffer to the target buffer, making sure
\r
97 * each char in the source is within the correct range
\r
101 ch = (int) source.get();
\r
102 if ((ch & 0xff00) == 0) {
\r
103 target.put((byte) ch);
\r
109 * if we reach here, it's because a character was not in the correct range, and we need
\r
110 * to deak with this by calling encodeMalformedOrUnmappable.
\r
112 return encodeMalformedOrUnmappable(source, ch, flush);
\r
117 public CharsetDecoder newDecoder() {
\r
118 return new CharsetDecoder88591(this);
\r
121 public CharsetEncoder newEncoder() {
\r
122 return new CharsetEncoder88591(this);
\r
125 void getUnicodeSetImpl( UnicodeSet setFillIn, int which){
\r
126 setFillIn.add(0,0xff);
\r