src/java.base/share/classes/sun/nio/cs/DoubleByte.java
author sherman
Wed, 31 Jan 2018 08:42:59 -0800
changeset 48688 08b5eb52ccfd
parent 47216 71c04702a3d5
permissions -rw-r--r--
8166339: Code conversion working behavior was changed for x-IBM834 Reviewed-by: coffeys
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
28969
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
     1
/*
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
     2
 * Copyright (c) 2009, 2013, Oracle and/or its affiliates. All rights reserved.
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
     4
 *
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
    10
 *
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
    15
 * accompanied this code).
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
    16
 *
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
    20
 *
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
    23
 * questions.
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
    24
 */
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
    25
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
    26
package sun.nio.cs;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
    27
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
    28
import java.nio.ByteBuffer;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
    29
import java.nio.CharBuffer;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
    30
import java.nio.charset.Charset;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
    31
import java.nio.charset.CharsetDecoder;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
    32
import java.nio.charset.CharsetEncoder;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
    33
import java.nio.charset.CoderResult;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
    34
import java.util.Arrays;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
    35
import sun.nio.cs.Surrogate;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
    36
import sun.nio.cs.ArrayDecoder;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
    37
import sun.nio.cs.ArrayEncoder;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
    38
import static sun.nio.cs.CharsetMapping.*;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
    39
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
    40
/*
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
    41
 * Four types of "DoubleByte" charsets are implemented in this class
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
    42
 * (1)DoubleByte
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
    43
 *    The "mostly widely used" multibyte charset, a combination of
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
    44
 *    a singlebyte character set (usually the ASCII charset) and a
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
    45
 *    doublebyte character set. The codepoint values of singlebyte
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
    46
 *    and doublebyte don't overlap. Microsoft's multibyte charsets
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
    47
 *    and IBM's "DBCS_ASCII" charsets, such as IBM1381, 942, 943,
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
    48
 *    948, 949 and 950 are such charsets.
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
    49
 *
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
    50
 * (2)DoubleByte_EBCDIC
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
    51
 *    IBM EBCDIC Mix multibyte charset. Use SO and SI to shift (switch)
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
    52
 *    in and out between the singlebyte character set and doublebyte
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
    53
 *    character set.
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
    54
 *
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
    55
 * (3)DoubleByte_SIMPLE_EUC
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
    56
 *    It's a "simple" form of EUC encoding scheme, only have the
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
    57
 *    singlebyte character set G0 and one doublebyte character set
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
    58
 *    G1 are defined, G2 (with SS2) and G3 (with SS3) are not used.
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
    59
 *    So it is actually the same as the "typical" type (1) mentioned
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
    60
 *    above, except it return "malformed" for the SS2 and SS3 when
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
    61
 *    decoding.
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
    62
 *
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
    63
 * (4)DoubleByte ONLY
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
    64
 *    A "pure" doublebyte only character set. From implementation
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
    65
 *    point of view, this is the type (1) with "decodeSingle" always
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
    66
 *    returns unmappable.
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
    67
 *
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
    68
 * For simplicity, all implementations share the same decoding and
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
    69
 * encoding data structure.
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
    70
 *
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
    71
 * Decoding:
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
    72
 *
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
    73
 *    char[][] b2c;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
    74
 *    char[] b2cSB;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
    75
 *    int b2Min, b2Max
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
    76
 *
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
    77
 *    public char decodeSingle(int b) {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
    78
 *        return b2cSB.[b];
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
    79
 *    }
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
    80
 *
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
    81
 *    public char decodeDouble(int b1, int b2) {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
    82
 *        if (b2 < b2Min || b2 > b2Max)
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
    83
 *            return UNMAPPABLE_DECODING;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
    84
 *         return b2c[b1][b2 - b2Min];
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
    85
 *    }
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
    86
 *
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
    87
 *    (1)b2Min, b2Max are the corresponding min and max value of the
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
    88
 *       low-half of the double-byte.
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
    89
 *    (2)The high 8-bit/b1 of the double-byte are used to indexed into
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
    90
 *       b2c array.
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
    91
 *
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
    92
 * Encoding:
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
    93
 *
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
    94
 *    char[] c2b;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
    95
 *    char[] c2bIndex;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
    96
 *
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
    97
 *    public int encodeChar(char ch) {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
    98
 *        return c2b[c2bIndex[ch >> 8] + (ch & 0xff)];
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
    99
 *    }
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   100
 *
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   101
 */
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   102
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   103
public class DoubleByte {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   104
32649
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 28969
diff changeset
   105
    public static final char[] B2C_UNMAPPABLE;
28969
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   106
    static {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   107
        B2C_UNMAPPABLE = new char[0x100];
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   108
        Arrays.fill(B2C_UNMAPPABLE, UNMAPPABLE_DECODING);
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   109
    }
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   110
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   111
    public static class Decoder extends CharsetDecoder
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   112
                                implements DelegatableDecoder, ArrayDecoder
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   113
    {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   114
        final char[][] b2c;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   115
        final char[] b2cSB;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   116
        final int b2Min;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   117
        final int b2Max;
33663
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents: 32649
diff changeset
   118
        final boolean isASCIICompatible;
28969
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   119
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   120
        // for SimpleEUC override
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   121
        protected CoderResult crMalformedOrUnderFlow(int b) {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   122
            return CoderResult.UNDERFLOW;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   123
        }
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   124
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   125
        protected CoderResult crMalformedOrUnmappable(int b1, int b2) {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   126
            if (b2c[b1] == B2C_UNMAPPABLE ||                // isNotLeadingByte(b1)
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   127
                b2c[b2] != B2C_UNMAPPABLE ||                // isLeadingByte(b2)
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   128
                decodeSingle(b2) != UNMAPPABLE_DECODING) {  // isSingle(b2)
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   129
                return CoderResult.malformedForLength(1);
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   130
            }
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   131
            return CoderResult.unmappableForLength(2);
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   132
        }
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   133
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   134
        public Decoder(Charset cs, float avgcpb, float maxcpb,
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   135
                       char[][] b2c, char[] b2cSB,
33663
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents: 32649
diff changeset
   136
                       int b2Min, int b2Max,
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents: 32649
diff changeset
   137
                       boolean isASCIICompatible) {
28969
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   138
            super(cs, avgcpb, maxcpb);
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   139
            this.b2c = b2c;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   140
            this.b2cSB = b2cSB;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   141
            this.b2Min = b2Min;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   142
            this.b2Max = b2Max;
33663
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents: 32649
diff changeset
   143
            this.isASCIICompatible = isASCIICompatible;
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents: 32649
diff changeset
   144
        }
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents: 32649
diff changeset
   145
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents: 32649
diff changeset
   146
        public Decoder(Charset cs, char[][] b2c, char[] b2cSB, int b2Min, int b2Max,
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents: 32649
diff changeset
   147
                       boolean isASCIICompatible) {
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents: 32649
diff changeset
   148
            this(cs, 0.5f, 1.0f, b2c, b2cSB, b2Min, b2Max, isASCIICompatible);
28969
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   149
        }
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   150
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   151
        public Decoder(Charset cs, char[][] b2c, char[] b2cSB, int b2Min, int b2Max) {
33663
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents: 32649
diff changeset
   152
            this(cs, 0.5f, 1.0f, b2c, b2cSB, b2Min, b2Max, false);
28969
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   153
        }
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   154
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   155
        protected CoderResult decodeArrayLoop(ByteBuffer src, CharBuffer dst) {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   156
            byte[] sa = src.array();
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   157
            int sp = src.arrayOffset() + src.position();
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   158
            int sl = src.arrayOffset() + src.limit();
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   159
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   160
            char[] da = dst.array();
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   161
            int dp = dst.arrayOffset() + dst.position();
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   162
            int dl = dst.arrayOffset() + dst.limit();
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   163
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   164
            try {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   165
                while (sp < sl && dp < dl) {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   166
                    // inline the decodeSingle/Double() for better performance
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   167
                    int inSize = 1;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   168
                    int b1 = sa[sp] & 0xff;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   169
                    char c = b2cSB[b1];
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   170
                    if (c == UNMAPPABLE_DECODING) {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   171
                        if (sl - sp < 2)
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   172
                            return crMalformedOrUnderFlow(b1);
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   173
                        int b2 = sa[sp + 1] & 0xff;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   174
                        if (b2 < b2Min || b2 > b2Max ||
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   175
                            (c = b2c[b1][b2 - b2Min]) == UNMAPPABLE_DECODING) {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   176
                            return crMalformedOrUnmappable(b1, b2);
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   177
                        }
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   178
                        inSize++;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   179
                    }
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   180
                    da[dp++] = c;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   181
                    sp += inSize;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   182
                }
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   183
                return (sp >= sl) ? CoderResult.UNDERFLOW
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   184
                                  : CoderResult.OVERFLOW;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   185
            } finally {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   186
                src.position(sp - src.arrayOffset());
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   187
                dst.position(dp - dst.arrayOffset());
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   188
            }
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   189
        }
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   190
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   191
        protected CoderResult decodeBufferLoop(ByteBuffer src, CharBuffer dst) {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   192
            int mark = src.position();
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   193
            try {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   194
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   195
                while (src.hasRemaining() && dst.hasRemaining()) {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   196
                    int b1 = src.get() & 0xff;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   197
                    char c = b2cSB[b1];
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   198
                    int inSize = 1;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   199
                    if (c == UNMAPPABLE_DECODING) {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   200
                        if (src.remaining() < 1)
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   201
                            return crMalformedOrUnderFlow(b1);
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   202
                        int b2 = src.get() & 0xff;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   203
                        if (b2 < b2Min || b2 > b2Max ||
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   204
                            (c = b2c[b1][b2 - b2Min]) == UNMAPPABLE_DECODING)
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   205
                            return crMalformedOrUnmappable(b1, b2);
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   206
                        inSize++;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   207
                    }
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   208
                    dst.put(c);
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   209
                    mark += inSize;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   210
                }
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   211
                return src.hasRemaining()? CoderResult.OVERFLOW
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   212
                                         : CoderResult.UNDERFLOW;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   213
            } finally {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   214
                src.position(mark);
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   215
            }
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   216
        }
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   217
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   218
        // Make some protected methods public for use by JISAutoDetect
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   219
        public CoderResult decodeLoop(ByteBuffer src, CharBuffer dst) {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   220
            if (src.hasArray() && dst.hasArray())
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   221
                return decodeArrayLoop(src, dst);
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   222
            else
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   223
                return decodeBufferLoop(src, dst);
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   224
        }
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   225
33663
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents: 32649
diff changeset
   226
        @Override
28969
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   227
        public int decode(byte[] src, int sp, int len, char[] dst) {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   228
            int dp = 0;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   229
            int sl = sp + len;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   230
            char repl = replacement().charAt(0);
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   231
            while (sp < sl) {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   232
                int b1 = src[sp++] & 0xff;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   233
                char c = b2cSB[b1];
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   234
                if (c == UNMAPPABLE_DECODING) {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   235
                    if (sp < sl) {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   236
                        int b2 = src[sp++] & 0xff;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   237
                        if (b2 < b2Min || b2 > b2Max ||
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   238
                            (c = b2c[b1][b2 - b2Min]) == UNMAPPABLE_DECODING) {
48688
08b5eb52ccfd 8166339: Code conversion working behavior was changed for x-IBM834
sherman
parents: 47216
diff changeset
   239
                            if (crMalformedOrUnmappable(b1, b2).length() == 1) {
08b5eb52ccfd 8166339: Code conversion working behavior was changed for x-IBM834
sherman
parents: 47216
diff changeset
   240
                                sp--;
28969
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   241
                            }
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   242
                        }
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   243
                    }
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   244
                    if (c == UNMAPPABLE_DECODING) {
33663
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents: 32649
diff changeset
   245
                         c = repl;
28969
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   246
                    }
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   247
                }
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   248
                dst[dp++] = c;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   249
            }
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   250
            return dp;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   251
        }
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   252
33663
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents: 32649
diff changeset
   253
        @Override
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents: 32649
diff changeset
   254
        public boolean isASCIICompatible() {
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents: 32649
diff changeset
   255
            return isASCIICompatible;
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents: 32649
diff changeset
   256
        }
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents: 32649
diff changeset
   257
28969
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   258
        public void implReset() {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   259
            super.implReset();
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   260
        }
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   261
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   262
        public CoderResult implFlush(CharBuffer out) {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   263
            return super.implFlush(out);
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   264
        }
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   265
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   266
        // decode loops are not using decodeSingle/Double() for performance
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   267
        // reason.
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   268
        public char decodeSingle(int b) {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   269
            return b2cSB[b];
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   270
        }
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   271
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   272
        public char decodeDouble(int b1, int b2) {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   273
            if (b1 < 0 || b1 > b2c.length ||
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   274
                b2 < b2Min || b2 > b2Max)
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   275
                return UNMAPPABLE_DECODING;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   276
            return  b2c[b1][b2 - b2Min];
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   277
        }
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   278
    }
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   279
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   280
    // IBM_EBCDIC_DBCS
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   281
    public static class Decoder_EBCDIC extends Decoder {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   282
        private static final int SBCS = 0;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   283
        private static final int DBCS = 1;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   284
        private static final int SO = 0x0e;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   285
        private static final int SI = 0x0f;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   286
        private int  currentState;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   287
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   288
        public Decoder_EBCDIC(Charset cs,
33663
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents: 32649
diff changeset
   289
                              char[][] b2c, char[] b2cSB, int b2Min, int b2Max,
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents: 32649
diff changeset
   290
                              boolean isASCIICompatible) {
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents: 32649
diff changeset
   291
            super(cs, b2c, b2cSB, b2Min, b2Max, isASCIICompatible);
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents: 32649
diff changeset
   292
        }
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents: 32649
diff changeset
   293
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents: 32649
diff changeset
   294
        public Decoder_EBCDIC(Charset cs,
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents: 32649
diff changeset
   295
                              char[][] b2c, char[] b2cSB, int b2Min, int b2Max) {
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents: 32649
diff changeset
   296
            super(cs, b2c, b2cSB, b2Min, b2Max, false);
28969
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   297
        }
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   298
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   299
        public void implReset() {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   300
            currentState = SBCS;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   301
        }
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   302
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   303
        // Check validity of dbcs ebcdic byte pair values
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   304
        //
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   305
        // First byte : 0x41 -- 0xFE
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   306
        // Second byte: 0x41 -- 0xFE
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   307
        // Doublebyte blank: 0x4040
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   308
        //
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   309
        // The validation implementation in "old" DBCS_IBM_EBCDIC and sun.io
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   310
        // as
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   311
        //            if ((b1 != 0x40 || b2 != 0x40) &&
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   312
        //                (b2 < 0x41 || b2 > 0xfe)) {...}
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   313
        // is not correct/complete (range check for b1)
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   314
        //
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   315
        private static boolean isDoubleByte(int b1, int b2) {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   316
            return (0x41 <= b1 && b1 <= 0xfe && 0x41 <= b2 && b2 <= 0xfe)
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   317
                   || (b1 == 0x40 && b2 == 0x40); // DBCS-HOST SPACE
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   318
        }
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   319
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   320
        protected CoderResult decodeArrayLoop(ByteBuffer src, CharBuffer dst) {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   321
            byte[] sa = src.array();
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   322
            int sp = src.arrayOffset() + src.position();
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   323
            int sl = src.arrayOffset() + src.limit();
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   324
            char[] da = dst.array();
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   325
            int dp = dst.arrayOffset() + dst.position();
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   326
            int dl = dst.arrayOffset() + dst.limit();
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   327
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   328
            try {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   329
                // don't check dp/dl together here, it's possible to
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   330
                // decdoe a SO/SI without space in output buffer.
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   331
                while (sp < sl) {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   332
                    int b1 = sa[sp] & 0xff;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   333
                    int inSize = 1;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   334
                    if (b1 == SO) {  // Shift out
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   335
                        if (currentState != SBCS)
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   336
                            return CoderResult.malformedForLength(1);
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   337
                        else
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   338
                            currentState = DBCS;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   339
                    } else if (b1 == SI) {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   340
                        if (currentState != DBCS)
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   341
                            return CoderResult.malformedForLength(1);
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   342
                        else
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   343
                            currentState = SBCS;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   344
                    } else {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   345
                        char c =  UNMAPPABLE_DECODING;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   346
                        if (currentState == SBCS) {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   347
                            c = b2cSB[b1];
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   348
                            if (c == UNMAPPABLE_DECODING)
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   349
                                return CoderResult.unmappableForLength(1);
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   350
                        } else {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   351
                            if (sl - sp < 2)
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   352
                                return CoderResult.UNDERFLOW;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   353
                            int b2 = sa[sp + 1] & 0xff;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   354
                            if (b2 < b2Min || b2 > b2Max ||
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   355
                                (c = b2c[b1][b2 - b2Min]) == UNMAPPABLE_DECODING) {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   356
                                if (!isDoubleByte(b1, b2))
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   357
                                    return CoderResult.malformedForLength(2);
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   358
                                return CoderResult.unmappableForLength(2);
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   359
                            }
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   360
                            inSize++;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   361
                        }
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   362
                        if (dl - dp < 1)
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   363
                            return CoderResult.OVERFLOW;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   364
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   365
                        da[dp++] = c;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   366
                    }
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   367
                    sp += inSize;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   368
                }
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   369
                return CoderResult.UNDERFLOW;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   370
            } finally {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   371
                src.position(sp - src.arrayOffset());
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   372
                dst.position(dp - dst.arrayOffset());
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   373
            }
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   374
        }
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   375
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   376
        protected CoderResult decodeBufferLoop(ByteBuffer src, CharBuffer dst) {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   377
            int mark = src.position();
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   378
            try {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   379
                while (src.hasRemaining()) {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   380
                    int b1 = src.get() & 0xff;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   381
                    int inSize = 1;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   382
                    if (b1 == SO) {  // Shift out
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   383
                        if (currentState != SBCS)
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   384
                            return CoderResult.malformedForLength(1);
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   385
                        else
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   386
                            currentState = DBCS;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   387
                    } else if (b1 == SI) {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   388
                        if (currentState != DBCS)
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   389
                            return CoderResult.malformedForLength(1);
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   390
                        else
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   391
                            currentState = SBCS;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   392
                    } else {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   393
                        char c = UNMAPPABLE_DECODING;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   394
                        if (currentState == SBCS) {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   395
                            c = b2cSB[b1];
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   396
                            if (c == UNMAPPABLE_DECODING)
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   397
                                return CoderResult.unmappableForLength(1);
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   398
                        } else {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   399
                            if (src.remaining() < 1)
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   400
                                return CoderResult.UNDERFLOW;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   401
                            int b2 = src.get()&0xff;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   402
                            if (b2 < b2Min || b2 > b2Max ||
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   403
                                (c = b2c[b1][b2 - b2Min]) == UNMAPPABLE_DECODING) {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   404
                                if (!isDoubleByte(b1, b2))
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   405
                                    return CoderResult.malformedForLength(2);
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   406
                                return CoderResult.unmappableForLength(2);
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   407
                            }
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   408
                            inSize++;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   409
                        }
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   410
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   411
                        if (dst.remaining() < 1)
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   412
                            return CoderResult.OVERFLOW;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   413
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   414
                        dst.put(c);
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   415
                    }
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   416
                    mark += inSize;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   417
                }
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   418
                return CoderResult.UNDERFLOW;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   419
            } finally {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   420
                src.position(mark);
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   421
            }
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   422
        }
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   423
33663
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents: 32649
diff changeset
   424
        @Override
28969
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   425
        public int decode(byte[] src, int sp, int len, char[] dst) {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   426
            int dp = 0;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   427
            int sl = sp + len;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   428
            currentState = SBCS;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   429
            char repl = replacement().charAt(0);
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   430
            while (sp < sl) {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   431
                int b1 = src[sp++] & 0xff;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   432
                if (b1 == SO) {  // Shift out
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   433
                    if (currentState != SBCS)
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   434
                        dst[dp++] = repl;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   435
                    else
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   436
                        currentState = DBCS;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   437
                } else if (b1 == SI) {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   438
                    if (currentState != DBCS)
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   439
                        dst[dp++] = repl;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   440
                    else
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   441
                        currentState = SBCS;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   442
                } else {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   443
                    char c =  UNMAPPABLE_DECODING;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   444
                    if (currentState == SBCS) {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   445
                        c = b2cSB[b1];
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   446
                        if (c == UNMAPPABLE_DECODING)
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   447
                            c = repl;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   448
                    } else {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   449
                        if (sl == sp) {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   450
                            c = repl;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   451
                        } else {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   452
                            int b2 = src[sp++] & 0xff;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   453
                            if (b2 < b2Min || b2 > b2Max ||
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   454
                                (c = b2c[b1][b2 - b2Min]) == UNMAPPABLE_DECODING) {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   455
                                c = repl;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   456
                            }
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   457
                        }
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   458
                    }
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   459
                    dst[dp++] = c;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   460
                }
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   461
            }
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   462
            return dp;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   463
        }
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   464
    }
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   465
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   466
    // DBCS_ONLY
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   467
    public static class Decoder_DBCSONLY extends Decoder {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   468
        static final char[] b2cSB_UNMAPPABLE;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   469
        static {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   470
            b2cSB_UNMAPPABLE = new char[0x100];
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   471
            Arrays.fill(b2cSB_UNMAPPABLE, UNMAPPABLE_DECODING);
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   472
        }
48688
08b5eb52ccfd 8166339: Code conversion working behavior was changed for x-IBM834
sherman
parents: 47216
diff changeset
   473
08b5eb52ccfd 8166339: Code conversion working behavior was changed for x-IBM834
sherman
parents: 47216
diff changeset
   474
        // always returns unmappableForLenth(2) for doublebyte_only
08b5eb52ccfd 8166339: Code conversion working behavior was changed for x-IBM834
sherman
parents: 47216
diff changeset
   475
        @Override
08b5eb52ccfd 8166339: Code conversion working behavior was changed for x-IBM834
sherman
parents: 47216
diff changeset
   476
        protected CoderResult crMalformedOrUnmappable(int b1, int b2) {
08b5eb52ccfd 8166339: Code conversion working behavior was changed for x-IBM834
sherman
parents: 47216
diff changeset
   477
            return CoderResult.unmappableForLength(2);
08b5eb52ccfd 8166339: Code conversion working behavior was changed for x-IBM834
sherman
parents: 47216
diff changeset
   478
        }
08b5eb52ccfd 8166339: Code conversion working behavior was changed for x-IBM834
sherman
parents: 47216
diff changeset
   479
33663
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents: 32649
diff changeset
   480
        public Decoder_DBCSONLY(Charset cs, char[][] b2c, char[] b2cSB, int b2Min, int b2Max,
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents: 32649
diff changeset
   481
                                boolean isASCIICompatible) {
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents: 32649
diff changeset
   482
            super(cs, 0.5f, 1.0f, b2c, b2cSB_UNMAPPABLE, b2Min, b2Max, isASCIICompatible);
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents: 32649
diff changeset
   483
        }
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents: 32649
diff changeset
   484
28969
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   485
        public Decoder_DBCSONLY(Charset cs, char[][] b2c, char[] b2cSB, int b2Min, int b2Max) {
33663
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents: 32649
diff changeset
   486
            super(cs, 0.5f, 1.0f, b2c, b2cSB_UNMAPPABLE, b2Min, b2Max, false);
28969
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   487
        }
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   488
    }
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   489
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   490
    // EUC_SIMPLE
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   491
    // The only thing we need to "override" is to check SS2/SS3 and
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   492
    // return "malformed" if found
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   493
    public static class Decoder_EUC_SIM extends Decoder {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   494
        private final int SS2 =  0x8E;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   495
        private final int SS3 =  0x8F;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   496
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   497
        public Decoder_EUC_SIM(Charset cs,
33663
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents: 32649
diff changeset
   498
                               char[][] b2c, char[] b2cSB, int b2Min, int b2Max,
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents: 32649
diff changeset
   499
                               boolean isASCIICompatible) {
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents: 32649
diff changeset
   500
            super(cs, b2c, b2cSB, b2Min, b2Max, isASCIICompatible);
28969
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   501
        }
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   502
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   503
        // No support provided for G2/G3 for SimpleEUC
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   504
        protected CoderResult crMalformedOrUnderFlow(int b) {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   505
            if (b == SS2 || b == SS3 )
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   506
                return CoderResult.malformedForLength(1);
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   507
            return CoderResult.UNDERFLOW;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   508
        }
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   509
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   510
        protected CoderResult crMalformedOrUnmappable(int b1, int b2) {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   511
            if (b1 == SS2 || b1 == SS3 )
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   512
                return CoderResult.malformedForLength(1);
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   513
            return CoderResult.unmappableForLength(2);
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   514
        }
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   515
33663
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents: 32649
diff changeset
   516
        @Override
28969
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   517
        public int decode(byte[] src, int sp, int len, char[] dst) {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   518
            int dp = 0;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   519
            int sl = sp + len;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   520
            char repl = replacement().charAt(0);
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   521
            while (sp < sl) {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   522
                int b1 = src[sp++] & 0xff;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   523
                char c = b2cSB[b1];
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   524
                if (c == UNMAPPABLE_DECODING) {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   525
                    if (sp < sl) {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   526
                        int b2 = src[sp++] & 0xff;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   527
                        if (b2 < b2Min || b2 > b2Max ||
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   528
                            (c = b2c[b1][b2 - b2Min]) == UNMAPPABLE_DECODING) {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   529
                            if (b1 == SS2 || b1 == SS3) {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   530
                                sp--;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   531
                            }
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   532
                            c = repl;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   533
                        }
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   534
                    } else {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   535
                        c = repl;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   536
                    }
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   537
                }
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   538
                dst[dp++] = c;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   539
            }
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   540
            return dp;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   541
        }
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   542
    }
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   543
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   544
    public static class Encoder extends CharsetEncoder
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   545
                                implements ArrayEncoder
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   546
    {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   547
        protected final int MAX_SINGLEBYTE = 0xff;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   548
        private final char[] c2b;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   549
        private final char[] c2bIndex;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   550
        protected Surrogate.Parser sgp;
33663
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents: 32649
diff changeset
   551
        final boolean isASCIICompatible;
28969
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   552
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   553
        public Encoder(Charset cs, char[] c2b, char[] c2bIndex) {
33663
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents: 32649
diff changeset
   554
            this(cs, c2b, c2bIndex, false);
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents: 32649
diff changeset
   555
        }
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents: 32649
diff changeset
   556
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents: 32649
diff changeset
   557
        public Encoder(Charset cs, char[] c2b, char[] c2bIndex, boolean isASCIICompatible) {
28969
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   558
            super(cs, 2.0f, 2.0f);
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   559
            this.c2b = c2b;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   560
            this.c2bIndex = c2bIndex;
33663
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents: 32649
diff changeset
   561
            this.isASCIICompatible = isASCIICompatible;
28969
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   562
        }
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   563
33663
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents: 32649
diff changeset
   564
        public Encoder(Charset cs, float avg, float max, byte[] repl, char[] c2b, char[] c2bIndex,
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents: 32649
diff changeset
   565
                       boolean isASCIICompatible) {
28969
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   566
            super(cs, avg, max, repl);
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   567
            this.c2b = c2b;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   568
            this.c2bIndex = c2bIndex;
33663
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents: 32649
diff changeset
   569
            this.isASCIICompatible = isASCIICompatible;
28969
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   570
        }
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   571
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   572
        public boolean canEncode(char c) {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   573
            return encodeChar(c) != UNMAPPABLE_ENCODING;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   574
        }
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   575
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   576
        protected Surrogate.Parser sgp() {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   577
            if (sgp == null)
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   578
                sgp = new Surrogate.Parser();
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   579
            return sgp;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   580
        }
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   581
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   582
        protected CoderResult encodeArrayLoop(CharBuffer src, ByteBuffer dst) {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   583
            char[] sa = src.array();
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   584
            int sp = src.arrayOffset() + src.position();
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   585
            int sl = src.arrayOffset() + src.limit();
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   586
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   587
            byte[] da = dst.array();
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   588
            int dp = dst.arrayOffset() + dst.position();
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   589
            int dl = dst.arrayOffset() + dst.limit();
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   590
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   591
            try {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   592
                while (sp < sl) {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   593
                    char c = sa[sp];
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   594
                    int bb = encodeChar(c);
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   595
                    if (bb == UNMAPPABLE_ENCODING) {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   596
                        if (Character.isSurrogate(c)) {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   597
                            if (sgp().parse(c, sa, sp, sl) < 0)
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   598
                                return sgp.error();
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   599
                            return sgp.unmappableResult();
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   600
                        }
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   601
                        return CoderResult.unmappableForLength(1);
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   602
                    }
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   603
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   604
                    if (bb > MAX_SINGLEBYTE) {    // DoubleByte
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   605
                        if (dl - dp < 2)
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   606
                            return CoderResult.OVERFLOW;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   607
                        da[dp++] = (byte)(bb >> 8);
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   608
                        da[dp++] = (byte)bb;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   609
                    } else {                      // SingleByte
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   610
                        if (dl - dp < 1)
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   611
                            return CoderResult.OVERFLOW;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   612
                        da[dp++] = (byte)bb;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   613
                    }
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   614
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   615
                    sp++;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   616
                }
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   617
                return CoderResult.UNDERFLOW;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   618
            } finally {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   619
                src.position(sp - src.arrayOffset());
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   620
                dst.position(dp - dst.arrayOffset());
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   621
            }
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   622
        }
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   623
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   624
        protected CoderResult encodeBufferLoop(CharBuffer src, ByteBuffer dst) {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   625
            int mark = src.position();
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   626
            try {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   627
                while (src.hasRemaining()) {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   628
                    char c = src.get();
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   629
                    int bb = encodeChar(c);
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   630
                    if (bb == UNMAPPABLE_ENCODING) {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   631
                        if (Character.isSurrogate(c)) {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   632
                            if (sgp().parse(c, src) < 0)
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   633
                                return sgp.error();
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   634
                            return sgp.unmappableResult();
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   635
                        }
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   636
                        return CoderResult.unmappableForLength(1);
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   637
                    }
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   638
                    if (bb > MAX_SINGLEBYTE) {  // DoubleByte
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   639
                        if (dst.remaining() < 2)
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   640
                            return CoderResult.OVERFLOW;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   641
                        dst.put((byte)(bb >> 8));
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   642
                        dst.put((byte)(bb));
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   643
                    } else {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   644
                        if (dst.remaining() < 1)
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   645
                        return CoderResult.OVERFLOW;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   646
                        dst.put((byte)bb);
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   647
                    }
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   648
                    mark++;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   649
                }
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   650
                return CoderResult.UNDERFLOW;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   651
            } finally {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   652
                src.position(mark);
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   653
            }
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   654
        }
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   655
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   656
        protected CoderResult encodeLoop(CharBuffer src, ByteBuffer dst) {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   657
            if (src.hasArray() && dst.hasArray())
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   658
                return encodeArrayLoop(src, dst);
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   659
            else
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   660
                return encodeBufferLoop(src, dst);
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   661
        }
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   662
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   663
        protected byte[] repl = replacement();
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   664
        protected void implReplaceWith(byte[] newReplacement) {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   665
            repl = newReplacement;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   666
        }
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   667
33663
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents: 32649
diff changeset
   668
        @Override
28969
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   669
        public int encode(char[] src, int sp, int len, byte[] dst) {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   670
            int dp = 0;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   671
            int sl = sp + len;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   672
            int dl = dst.length;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   673
            while (sp < sl) {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   674
                char c = src[sp++];
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   675
                int bb = encodeChar(c);
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   676
                if (bb == UNMAPPABLE_ENCODING) {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   677
                    if (Character.isHighSurrogate(c) && sp < sl &&
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   678
                        Character.isLowSurrogate(src[sp])) {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   679
                        sp++;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   680
                    }
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   681
                    dst[dp++] = repl[0];
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   682
                    if (repl.length > 1)
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   683
                        dst[dp++] = repl[1];
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   684
                    continue;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   685
                } //else
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   686
                if (bb > MAX_SINGLEBYTE) { // DoubleByte
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   687
                    dst[dp++] = (byte)(bb >> 8);
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   688
                    dst[dp++] = (byte)bb;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   689
                } else {                          // SingleByte
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   690
                    dst[dp++] = (byte)bb;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   691
                }
33663
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents: 32649
diff changeset
   692
            }
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents: 32649
diff changeset
   693
            return dp;
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents: 32649
diff changeset
   694
        }
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents: 32649
diff changeset
   695
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents: 32649
diff changeset
   696
        @Override
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents: 32649
diff changeset
   697
        public int encodeFromLatin1(byte[] src, int sp, int len, byte[] dst) {
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents: 32649
diff changeset
   698
            int dp = 0;
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents: 32649
diff changeset
   699
            int sl = sp + len;
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents: 32649
diff changeset
   700
            while (sp < sl) {
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents: 32649
diff changeset
   701
                char c = (char)(src[sp++] & 0xff);
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents: 32649
diff changeset
   702
                int bb = encodeChar(c);
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents: 32649
diff changeset
   703
                if (bb == UNMAPPABLE_ENCODING) {
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents: 32649
diff changeset
   704
                    // no surrogate pair in latin1 string
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents: 32649
diff changeset
   705
                    dst[dp++] = repl[0];
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents: 32649
diff changeset
   706
                    if (repl.length > 1) {
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents: 32649
diff changeset
   707
                        dst[dp++] = repl[1];
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents: 32649
diff changeset
   708
                    }
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents: 32649
diff changeset
   709
                    continue;
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents: 32649
diff changeset
   710
                } //else
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents: 32649
diff changeset
   711
                if (bb > MAX_SINGLEBYTE) { // DoubleByte
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents: 32649
diff changeset
   712
                    dst[dp++] = (byte)(bb >> 8);
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents: 32649
diff changeset
   713
                    dst[dp++] = (byte)bb;
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents: 32649
diff changeset
   714
                } else {                   // SingleByte
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents: 32649
diff changeset
   715
                    dst[dp++] = (byte)bb;
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents: 32649
diff changeset
   716
                }
28969
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   717
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   718
            }
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   719
            return dp;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   720
        }
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   721
33663
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents: 32649
diff changeset
   722
        @Override
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents: 32649
diff changeset
   723
        public int encodeFromUTF16(byte[] src, int sp, int len, byte[] dst) {
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents: 32649
diff changeset
   724
            int dp = 0;
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents: 32649
diff changeset
   725
            int sl = sp + len;
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents: 32649
diff changeset
   726
            while (sp < sl) {
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents: 32649
diff changeset
   727
                char c = StringUTF16.getChar(src, sp++);
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents: 32649
diff changeset
   728
                int bb = encodeChar(c);
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents: 32649
diff changeset
   729
                if (bb == UNMAPPABLE_ENCODING) {
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents: 32649
diff changeset
   730
                    if (Character.isHighSurrogate(c) && sp < sl &&
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents: 32649
diff changeset
   731
                        Character.isLowSurrogate(StringUTF16.getChar(src, sp))) {
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents: 32649
diff changeset
   732
                        sp++;
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents: 32649
diff changeset
   733
                    }
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents: 32649
diff changeset
   734
                    dst[dp++] = repl[0];
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents: 32649
diff changeset
   735
                    if (repl.length > 1) {
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents: 32649
diff changeset
   736
                        dst[dp++] = repl[1];
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents: 32649
diff changeset
   737
                    }
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents: 32649
diff changeset
   738
                    continue;
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents: 32649
diff changeset
   739
                } //else
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents: 32649
diff changeset
   740
                if (bb > MAX_SINGLEBYTE) { // DoubleByte
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents: 32649
diff changeset
   741
                    dst[dp++] = (byte)(bb >> 8);
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents: 32649
diff changeset
   742
                    dst[dp++] = (byte)bb;
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents: 32649
diff changeset
   743
                } else {                   // SingleByte
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents: 32649
diff changeset
   744
                    dst[dp++] = (byte)bb;
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents: 32649
diff changeset
   745
                }
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents: 32649
diff changeset
   746
            }
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents: 32649
diff changeset
   747
            return dp;
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents: 32649
diff changeset
   748
        }
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents: 32649
diff changeset
   749
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents: 32649
diff changeset
   750
        @Override
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents: 32649
diff changeset
   751
        public boolean isASCIICompatible() {
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents: 32649
diff changeset
   752
            return isASCIICompatible;
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents: 32649
diff changeset
   753
        }
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents: 32649
diff changeset
   754
28969
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   755
        public int encodeChar(char ch) {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   756
            return c2b[c2bIndex[ch >> 8] + (ch & 0xff)];
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   757
        }
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   758
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   759
        // init the c2b and c2bIndex tables from b2c.
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   760
        public static void initC2B(String[] b2c, String b2cSB, String b2cNR,  String c2bNR,
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   761
                            int b2Min, int b2Max,
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   762
                            char[] c2b, char[] c2bIndex)
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   763
        {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   764
            Arrays.fill(c2b, (char)UNMAPPABLE_ENCODING);
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   765
            int off = 0x100;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   766
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   767
            char[][] b2c_ca = new char[b2c.length][];
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   768
            char[] b2cSB_ca = null;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   769
            if (b2cSB != null)
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   770
                b2cSB_ca = b2cSB.toCharArray();
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   771
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   772
            for (int i = 0; i < b2c.length; i++) {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   773
                if (b2c[i] == null)
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   774
                    continue;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   775
                b2c_ca[i] = b2c[i].toCharArray();
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   776
            }
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   777
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   778
            if (b2cNR != null) {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   779
                int j = 0;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   780
                while (j < b2cNR.length()) {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   781
                    char b  = b2cNR.charAt(j++);
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   782
                    char c  = b2cNR.charAt(j++);
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   783
                    if (b < 0x100 && b2cSB_ca != null) {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   784
                        if (b2cSB_ca[b] == c)
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   785
                            b2cSB_ca[b] = UNMAPPABLE_DECODING;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   786
                    } else {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   787
                        if (b2c_ca[b >> 8][(b & 0xff) - b2Min] == c)
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   788
                            b2c_ca[b >> 8][(b & 0xff) - b2Min] = UNMAPPABLE_DECODING;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   789
                    }
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   790
                }
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   791
            }
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   792
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   793
            if (b2cSB_ca != null) {      // SingleByte
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   794
                for (int b = 0; b < b2cSB_ca.length; b++) {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   795
                    char c = b2cSB_ca[b];
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   796
                    if (c == UNMAPPABLE_DECODING)
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   797
                        continue;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   798
                    int index = c2bIndex[c >> 8];
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   799
                    if (index == 0) {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   800
                        index = off;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   801
                        off += 0x100;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   802
                        c2bIndex[c >> 8] = (char)index;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   803
                    }
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   804
                    c2b[index + (c & 0xff)] = (char)b;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   805
                }
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   806
            }
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   807
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   808
            for (int b1 = 0; b1 < b2c.length; b1++) {  // DoubleByte
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   809
                char[] db = b2c_ca[b1];
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   810
                if (db == null)
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   811
                    continue;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   812
                for (int b2 = b2Min; b2 <= b2Max; b2++) {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   813
                    char c = db[b2 - b2Min];
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   814
                    if (c == UNMAPPABLE_DECODING)
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   815
                        continue;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   816
                    int index = c2bIndex[c >> 8];
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   817
                    if (index == 0) {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   818
                        index = off;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   819
                        off += 0x100;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   820
                        c2bIndex[c >> 8] = (char)index;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   821
                    }
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   822
                    c2b[index + (c & 0xff)] = (char)((b1 << 8) | b2);
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   823
                }
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   824
            }
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   825
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   826
            if (c2bNR != null) {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   827
                // add c->b only nr entries
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   828
                for (int i = 0; i < c2bNR.length(); i += 2) {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   829
                    char b = c2bNR.charAt(i);
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   830
                    char c = c2bNR.charAt(i + 1);
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   831
                    int index = (c >> 8);
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   832
                    if (c2bIndex[index] == 0) {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   833
                        c2bIndex[index] = (char)off;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   834
                        off += 0x100;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   835
                    }
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   836
                    index = c2bIndex[index] + (c & 0xff);
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   837
                    c2b[index] = b;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   838
                }
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   839
            }
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   840
        }
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   841
    }
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   842
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   843
    public static class Encoder_DBCSONLY extends Encoder {
33663
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents: 32649
diff changeset
   844
28969
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   845
        public Encoder_DBCSONLY(Charset cs, byte[] repl,
33663
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents: 32649
diff changeset
   846
                                char[] c2b, char[] c2bIndex,
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents: 32649
diff changeset
   847
                                boolean isASCIICompatible) {
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents: 32649
diff changeset
   848
            super(cs, 2.0f, 2.0f, repl, c2b, c2bIndex, isASCIICompatible);
28969
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   849
        }
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   850
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   851
        public int encodeChar(char ch) {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   852
            int bb = super.encodeChar(ch);
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   853
            if (bb <= MAX_SINGLEBYTE)
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   854
                return UNMAPPABLE_ENCODING;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   855
            return bb;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   856
        }
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   857
    }
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   858
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   859
    public static class Encoder_EBCDIC extends Encoder {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   860
        static final int SBCS = 0;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   861
        static final int DBCS = 1;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   862
        static final byte SO = 0x0e;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   863
        static final byte SI = 0x0f;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   864
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   865
        protected int  currentState = SBCS;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   866
33663
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents: 32649
diff changeset
   867
        public Encoder_EBCDIC(Charset cs, char[] c2b, char[] c2bIndex,
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents: 32649
diff changeset
   868
                              boolean isASCIICompatible) {
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents: 32649
diff changeset
   869
            super(cs, 4.0f, 5.0f, new byte[] {(byte)0x6f}, c2b, c2bIndex, isASCIICompatible);
28969
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   870
        }
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   871
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   872
        protected void implReset() {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   873
            currentState = SBCS;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   874
        }
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   875
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   876
        protected CoderResult implFlush(ByteBuffer out) {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   877
            if (currentState == DBCS) {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   878
                if (out.remaining() < 1)
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   879
                    return CoderResult.OVERFLOW;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   880
                out.put(SI);
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   881
            }
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   882
            implReset();
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   883
            return CoderResult.UNDERFLOW;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   884
        }
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   885
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   886
        protected CoderResult encodeArrayLoop(CharBuffer src, ByteBuffer dst) {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   887
            char[] sa = src.array();
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   888
            int sp = src.arrayOffset() + src.position();
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   889
            int sl = src.arrayOffset() + src.limit();
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   890
            byte[] da = dst.array();
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   891
            int dp = dst.arrayOffset() + dst.position();
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   892
            int dl = dst.arrayOffset() + dst.limit();
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   893
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   894
            try {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   895
                while (sp < sl) {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   896
                    char c = sa[sp];
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   897
                    int bb = encodeChar(c);
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   898
                    if (bb == UNMAPPABLE_ENCODING) {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   899
                        if (Character.isSurrogate(c)) {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   900
                            if (sgp().parse(c, sa, sp, sl) < 0)
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   901
                                return sgp.error();
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   902
                            return sgp.unmappableResult();
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   903
                        }
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   904
                        return CoderResult.unmappableForLength(1);
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   905
                    }
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   906
                    if (bb > MAX_SINGLEBYTE) {  // DoubleByte
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   907
                        if (currentState == SBCS) {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   908
                            if (dl - dp < 1)
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   909
                                return CoderResult.OVERFLOW;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   910
                            currentState = DBCS;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   911
                            da[dp++] = SO;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   912
                        }
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   913
                        if (dl - dp < 2)
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   914
                            return CoderResult.OVERFLOW;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   915
                        da[dp++] = (byte)(bb >> 8);
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   916
                        da[dp++] = (byte)bb;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   917
                    } else {                    // SingleByte
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   918
                        if (currentState == DBCS) {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   919
                            if (dl - dp < 1)
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   920
                                return CoderResult.OVERFLOW;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   921
                            currentState = SBCS;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   922
                            da[dp++] = SI;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   923
                        }
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   924
                        if (dl - dp < 1)
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   925
                            return CoderResult.OVERFLOW;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   926
                        da[dp++] = (byte)bb;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   927
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   928
                    }
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   929
                    sp++;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   930
                }
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   931
                return CoderResult.UNDERFLOW;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   932
            } finally {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   933
                src.position(sp - src.arrayOffset());
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   934
                dst.position(dp - dst.arrayOffset());
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   935
            }
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   936
        }
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   937
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   938
        protected CoderResult encodeBufferLoop(CharBuffer src, ByteBuffer dst) {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   939
            int mark = src.position();
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   940
            try {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   941
                while (src.hasRemaining()) {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   942
                    char c = src.get();
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   943
                    int bb = encodeChar(c);
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   944
                    if (bb == UNMAPPABLE_ENCODING) {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   945
                        if (Character.isSurrogate(c)) {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   946
                            if (sgp().parse(c, src) < 0)
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   947
                                return sgp.error();
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   948
                            return sgp.unmappableResult();
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   949
                        }
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   950
                        return CoderResult.unmappableForLength(1);
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   951
                    }
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   952
                    if (bb > MAX_SINGLEBYTE) {  // DoubleByte
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   953
                        if (currentState == SBCS) {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   954
                            if (dst.remaining() < 1)
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   955
                                return CoderResult.OVERFLOW;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   956
                            currentState = DBCS;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   957
                            dst.put(SO);
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   958
                        }
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   959
                        if (dst.remaining() < 2)
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   960
                            return CoderResult.OVERFLOW;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   961
                        dst.put((byte)(bb >> 8));
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   962
                        dst.put((byte)(bb));
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   963
                    } else {                  // Single-byte
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   964
                        if (currentState == DBCS) {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   965
                            if (dst.remaining() < 1)
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   966
                                return CoderResult.OVERFLOW;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   967
                            currentState = SBCS;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   968
                            dst.put(SI);
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   969
                        }
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   970
                        if (dst.remaining() < 1)
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   971
                            return CoderResult.OVERFLOW;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   972
                        dst.put((byte)bb);
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   973
                    }
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   974
                    mark++;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   975
                }
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   976
                return CoderResult.UNDERFLOW;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   977
            } finally {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   978
                src.position(mark);
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   979
            }
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   980
        }
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   981
33663
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents: 32649
diff changeset
   982
        @Override
28969
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   983
        public int encode(char[] src, int sp, int len, byte[] dst) {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   984
            int dp = 0;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   985
            int sl = sp + len;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   986
            while (sp < sl) {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   987
                char c = src[sp++];
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   988
                int bb = encodeChar(c);
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   989
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   990
                if (bb == UNMAPPABLE_ENCODING) {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   991
                    if (Character.isHighSurrogate(c) && sp < sl &&
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   992
                        Character.isLowSurrogate(src[sp])) {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   993
                        sp++;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   994
                    }
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   995
                    dst[dp++] = repl[0];
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   996
                    if (repl.length > 1)
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   997
                        dst[dp++] = repl[1];
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   998
                    continue;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
   999
                } //else
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
  1000
                if (bb > MAX_SINGLEBYTE) {           // DoubleByte
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
  1001
                    if (currentState == SBCS) {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
  1002
                        currentState = DBCS;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
  1003
                        dst[dp++] = SO;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
  1004
                    }
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
  1005
                    dst[dp++] = (byte)(bb >> 8);
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
  1006
                    dst[dp++] = (byte)bb;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
  1007
                } else {                             // SingleByte
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
  1008
                    if (currentState == DBCS) {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
  1009
                         currentState = SBCS;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
  1010
                         dst[dp++] = SI;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
  1011
                    }
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
  1012
                    dst[dp++] = (byte)bb;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
  1013
                }
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
  1014
            }
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
  1015
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
  1016
            if (currentState == DBCS) {
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
  1017
                 currentState = SBCS;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
  1018
                 dst[dp++] = SI;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
  1019
            }
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
  1020
            return dp;
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
  1021
        }
33663
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents: 32649
diff changeset
  1022
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents: 32649
diff changeset
  1023
        @Override
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents: 32649
diff changeset
  1024
        public int encodeFromLatin1(byte[] src, int sp, int len, byte[] dst) {
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents: 32649
diff changeset
  1025
            int dp = 0;
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents: 32649
diff changeset
  1026
            int sl = sp + len;
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents: 32649
diff changeset
  1027
            while (sp < sl) {
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents: 32649
diff changeset
  1028
                char c = (char)(src[sp++] & 0xff);
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents: 32649
diff changeset
  1029
                int bb = encodeChar(c);
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents: 32649
diff changeset
  1030
                if (bb == UNMAPPABLE_ENCODING) {
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents: 32649
diff changeset
  1031
                    // no surrogate pair in latin1 string
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents: 32649
diff changeset
  1032
                    dst[dp++] = repl[0];
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents: 32649
diff changeset
  1033
                    if (repl.length > 1)
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents: 32649
diff changeset
  1034
                        dst[dp++] = repl[1];
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents: 32649
diff changeset
  1035
                    continue;
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents: 32649
diff changeset
  1036
                } //else
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents: 32649
diff changeset
  1037
                if (bb > MAX_SINGLEBYTE) {           // DoubleByte
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents: 32649
diff changeset
  1038
                    if (currentState == SBCS) {
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents: 32649
diff changeset
  1039
                        currentState = DBCS;
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents: 32649
diff changeset
  1040
                        dst[dp++] = SO;
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents: 32649
diff changeset
  1041
                    }
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents: 32649
diff changeset
  1042
                    dst[dp++] = (byte)(bb >> 8);
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents: 32649
diff changeset
  1043
                    dst[dp++] = (byte)bb;
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents: 32649
diff changeset
  1044
                } else {                             // SingleByte
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents: 32649
diff changeset
  1045
                    if (currentState == DBCS) {
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents: 32649
diff changeset
  1046
                         currentState = SBCS;
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents: 32649
diff changeset
  1047
                         dst[dp++] = SI;
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents: 32649
diff changeset
  1048
                    }
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents: 32649
diff changeset
  1049
                    dst[dp++] = (byte)bb;
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents: 32649
diff changeset
  1050
                }
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents: 32649
diff changeset
  1051
            }
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents: 32649
diff changeset
  1052
            if (currentState == DBCS) {
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents: 32649
diff changeset
  1053
                 currentState = SBCS;
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents: 32649
diff changeset
  1054
                 dst[dp++] = SI;
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents: 32649
diff changeset
  1055
            }
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents: 32649
diff changeset
  1056
            return dp;
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents: 32649
diff changeset
  1057
        }
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents: 32649
diff changeset
  1058
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents: 32649
diff changeset
  1059
        @Override
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents: 32649
diff changeset
  1060
        public int encodeFromUTF16(byte[] src, int sp, int len, byte[] dst) {
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents: 32649
diff changeset
  1061
            int dp = 0;
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents: 32649
diff changeset
  1062
            int sl = sp + len;
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents: 32649
diff changeset
  1063
            while (sp < sl) {
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents: 32649
diff changeset
  1064
                char c = StringUTF16.getChar(src, sp++);
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents: 32649
diff changeset
  1065
                int bb = encodeChar(c);
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents: 32649
diff changeset
  1066
                if (bb == UNMAPPABLE_ENCODING) {
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents: 32649
diff changeset
  1067
                    if (Character.isHighSurrogate(c) && sp < sl &&
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents: 32649
diff changeset
  1068
                        Character.isLowSurrogate(StringUTF16.getChar(src, sp))) {
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents: 32649
diff changeset
  1069
                        sp++;
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents: 32649
diff changeset
  1070
                    }
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents: 32649
diff changeset
  1071
                    dst[dp++] = repl[0];
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents: 32649
diff changeset
  1072
                    if (repl.length > 1)
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents: 32649
diff changeset
  1073
                        dst[dp++] = repl[1];
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents: 32649
diff changeset
  1074
                    continue;
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents: 32649
diff changeset
  1075
                } //else
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents: 32649
diff changeset
  1076
                if (bb > MAX_SINGLEBYTE) {           // DoubleByte
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents: 32649
diff changeset
  1077
                    if (currentState == SBCS) {
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents: 32649
diff changeset
  1078
                        currentState = DBCS;
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents: 32649
diff changeset
  1079
                        dst[dp++] = SO;
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents: 32649
diff changeset
  1080
                    }
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents: 32649
diff changeset
  1081
                    dst[dp++] = (byte)(bb >> 8);
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents: 32649
diff changeset
  1082
                    dst[dp++] = (byte)bb;
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents: 32649
diff changeset
  1083
                } else {                             // SingleByte
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents: 32649
diff changeset
  1084
                    if (currentState == DBCS) {
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents: 32649
diff changeset
  1085
                         currentState = SBCS;
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents: 32649
diff changeset
  1086
                         dst[dp++] = SI;
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents: 32649
diff changeset
  1087
                    }
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents: 32649
diff changeset
  1088
                    dst[dp++] = (byte)bb;
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents: 32649
diff changeset
  1089
                }
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents: 32649
diff changeset
  1090
            }
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents: 32649
diff changeset
  1091
            if (currentState == DBCS) {
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents: 32649
diff changeset
  1092
                 currentState = SBCS;
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents: 32649
diff changeset
  1093
                 dst[dp++] = SI;
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents: 32649
diff changeset
  1094
            }
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents: 32649
diff changeset
  1095
            return dp;
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents: 32649
diff changeset
  1096
        }
28969
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
  1097
    }
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
  1098
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
  1099
    // EUC_SIMPLE
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
  1100
    public static class Encoder_EUC_SIM extends Encoder {
33663
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents: 32649
diff changeset
  1101
        public Encoder_EUC_SIM(Charset cs, char[] c2b, char[] c2bIndex,
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents: 32649
diff changeset
  1102
                               boolean isASCIICompatible) {
2cd62a4bd471 8141132: JEP 254: Compact Strings
thartmann
parents: 32649
diff changeset
  1103
            super(cs, c2b, c2bIndex, isASCIICompatible);
28969
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
  1104
        }
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
  1105
    }
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
  1106
f980bee32887 8073152: Update Standard/ExtendedCharsets to work with module system
sherman
parents:
diff changeset
  1107
}