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