1245N/A/*
2362N/A * Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved.
1245N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
1245N/A *
1245N/A * This code is free software; you can redistribute it and/or modify it
1245N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
1245N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
1245N/A *
1245N/A * This code is distributed in the hope that it will be useful, but WITHOUT
1245N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1245N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
1245N/A * version 2 for more details (a copy is included in the LICENSE file that
1245N/A * accompanied this code).
1245N/A *
1245N/A * You should have received a copy of the GNU General Public License version
1245N/A * 2 along with this work; if not, write to the Free Software Foundation,
1245N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
1245N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
1245N/A */
1245N/A
1245N/A/*
1245N/A *
1245N/A * package private helper class which provides decoder (native->ucs)
1245N/A * mapping capability for the benefit of compound encoders/decoders
1245N/A * whose individual component submappings do not need an association with
1245N/A * an enclosing charset
1245N/A *
1245N/A */
1245N/A
1245N/A
1245N/Apublic class DBCSDecoderMapping {
1245N/A
1245N/A /* 1rst level index */
1245N/A private short[] index1;
1245N/A /*
1245N/A * 2nd level index, provided by subclass
1245N/A * every string has 0x10*(end-start+1) characters.
1245N/A */
1245N/A private String[] index2;
1245N/A
1245N/A protected int start;
1245N/A protected int end;
1245N/A
1245N/A protected static final char REPLACE_CHAR='\uFFFD';
1245N/A
1245N/A public DBCSDecoderMapping(short[] index1, String[] index2,
1245N/A int start, int end) {
1245N/A this.index1 = index1;
1245N/A this.index2 = index2;
1245N/A this.start = start;
1245N/A this.end = end;
1245N/A }
1245N/A
1245N/A /*
1245N/A * Can be changed by subclass
1245N/A */
1245N/A protected char decodeSingle(int b) {
1245N/A if (b >= 0)
1245N/A return (char) b;
1245N/A return REPLACE_CHAR;
1245N/A }
1245N/A
1245N/A protected char decodeDouble(int byte1, int byte2) {
1245N/A if (((byte1 < 0) || (byte1 > index1.length))
1245N/A || ((byte2 < start) || (byte2 > end)))
1245N/A return REPLACE_CHAR;
1245N/A
1245N/A int n = (index1[byte1] & 0xf) * (end - start + 1) + (byte2 - start);
1245N/A return index2[index1[byte1] >> 4].charAt(n);
1245N/A }
1245N/A}