jdk/src/jdk.charsets/unix/classes/sun/nio/cs/ext/CompoundTextSupport.java
author prr
Thu, 18 Dec 2014 10:45:45 -0800
changeset 29908 83e2c403fefd
parent 25859 3317bb8137f4
permissions -rw-r--r--
8067050: Better font consistency checking Reviewed-by: bae, srl, mschoene
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
7668
d4a77089c587 6962318: Update copyright year
ohair
parents: 5785
diff changeset
     2
 * Copyright (c) 2001, 2010, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package sun.nio.cs.ext;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.util.Collections;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.util.ArrayList;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.util.HashMap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.util.List;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.util.Map;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.nio.charset.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
final class CompoundTextSupport {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
    private static final class ControlSequence {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
        final int hash;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
        final byte[] escSequence;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
        final byte[] encoding;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
        ControlSequence(byte[] escSequence) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
            this(escSequence, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
        ControlSequence(byte[] escSequence, byte[] encoding) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
            if (escSequence == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
                throw new NullPointerException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
            this.escSequence = escSequence;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
            this.encoding = encoding;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
            int hash = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
            int length = escSequence.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
            for (int i = 0; i < escSequence.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
                hash += (((int)escSequence[i]) & 0xff) << (i % 4);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
            if (encoding != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
                for (int i = 0; i < encoding.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
                    hash += (((int)encoding[i]) & 0xff) << (i % 4);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
                length += 2 /* M L */ + encoding.length + 1 /* 0x02 */;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
            this.hash = hash;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
            if (MAX_CONTROL_SEQUENCE_LEN < length) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
                MAX_CONTROL_SEQUENCE_LEN = length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
        public boolean equals(Object obj) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
            if (this == obj) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
                return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
            if (!(obj instanceof ControlSequence)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
            ControlSequence rhs = (ControlSequence)obj;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
            if (escSequence != rhs.escSequence) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
                if (escSequence.length != rhs.escSequence.length) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
                    return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
                for (int i = 0; i < escSequence.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
                    if (escSequence[i] != rhs.escSequence[i]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
                        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
            if (encoding != rhs.encoding) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
                if (encoding == null || rhs.encoding == null ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
                    encoding.length != rhs.encoding.length)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
                {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
                    return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
                for (int i = 0; i < encoding.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
                    if (encoding[i] != rhs.encoding[i]) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
                        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
        public int hashCode() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
            return hash;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        ControlSequence concatenate(ControlSequence rhs) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
            if (encoding != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
                throw new IllegalArgumentException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
                    ("cannot concatenate to a non-standard charset escape " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
                     "sequence");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
            int len = escSequence.length + rhs.escSequence.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
            byte[] newEscSequence = new byte[len];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
            System.arraycopy(escSequence, 0, newEscSequence, 0,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
                             escSequence.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
            System.arraycopy(rhs.escSequence, 0, newEscSequence,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
                             escSequence.length, rhs.escSequence.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
            return new ControlSequence(newEscSequence, rhs.encoding);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
    static int MAX_CONTROL_SEQUENCE_LEN;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     * Maps a GL or GR escape sequence to an encoding.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     */
5785
5dfabe612d10 6959197: When building with JAVAC_MAX_WARNINGS=true, the build fails in sun/nio/cs due to the use of -Werror
andrew
parents: 5506
diff changeset
   133
    private static final Map<ControlSequence, String> sequenceToEncodingMap;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     * Indicates whether a particular encoding wants the high bit turned on
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     * or off.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     */
5785
5dfabe612d10 6959197: When building with JAVAC_MAX_WARNINGS=true, the build fails in sun/nio/cs due to the use of -Werror
andrew
parents: 5506
diff changeset
   139
    private static final Map<ControlSequence, Boolean> highBitsMap;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
     * Maps an encoding to an escape sequence. Rather than manage two
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     * converters in CharToByteCOMPOUND_TEXT, we output escape sequences which
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     * modify both GL and GR if necessary. This makes the output slightly less
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     * efficient, but our code much simpler.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
     */
5785
5dfabe612d10 6959197: When building with JAVAC_MAX_WARNINGS=true, the build fails in sun/nio/cs due to the use of -Werror
andrew
parents: 5506
diff changeset
   147
    private static final Map<String, ControlSequence> encodingToSequenceMap;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
     * The keys of 'encodingToSequenceMap', sorted in preferential order.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
     */
5785
5dfabe612d10 6959197: When building with JAVAC_MAX_WARNINGS=true, the build fails in sun/nio/cs due to the use of -Werror
andrew
parents: 5506
diff changeset
   152
    private static final List<String> encodings;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
    static {
5785
5dfabe612d10 6959197: When building with JAVAC_MAX_WARNINGS=true, the build fails in sun/nio/cs due to the use of -Werror
andrew
parents: 5506
diff changeset
   155
        HashMap<ControlSequence, String> tSequenceToEncodingMap =
5dfabe612d10 6959197: When building with JAVAC_MAX_WARNINGS=true, the build fails in sun/nio/cs due to the use of -Werror
andrew
parents: 5506
diff changeset
   156
            new HashMap<>(33, 1.0f);
5dfabe612d10 6959197: When building with JAVAC_MAX_WARNINGS=true, the build fails in sun/nio/cs due to the use of -Werror
andrew
parents: 5506
diff changeset
   157
        HashMap<ControlSequence, Boolean> tHighBitsMap =
5dfabe612d10 6959197: When building with JAVAC_MAX_WARNINGS=true, the build fails in sun/nio/cs due to the use of -Werror
andrew
parents: 5506
diff changeset
   158
            new HashMap<>(31, 1.0f);
5dfabe612d10 6959197: When building with JAVAC_MAX_WARNINGS=true, the build fails in sun/nio/cs due to the use of -Werror
andrew
parents: 5506
diff changeset
   159
        HashMap<String, ControlSequence> tEncodingToSequenceMap =
5dfabe612d10 6959197: When building with JAVAC_MAX_WARNINGS=true, the build fails in sun/nio/cs due to the use of -Werror
andrew
parents: 5506
diff changeset
   160
            new HashMap<>(21, 1.0f);
5dfabe612d10 6959197: When building with JAVAC_MAX_WARNINGS=true, the build fails in sun/nio/cs due to the use of -Werror
andrew
parents: 5506
diff changeset
   161
        ArrayList<String> tEncodings = new ArrayList<>(21);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        if (!(isEncodingSupported("US-ASCII") &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
              isEncodingSupported("ISO-8859-1")))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
            throw new ExceptionInInitializerError
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
                ("US-ASCII and ISO-8859-1 unsupported");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
        ControlSequence leftAscii = // high bit off, leave off
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
            new ControlSequence(new byte[] { 0x1B, 0x28, 0x42 });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
        tSequenceToEncodingMap.put(leftAscii, "US-ASCII");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
        tHighBitsMap.put(leftAscii, Boolean.FALSE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
            ControlSequence rightAscii = // high bit on, turn off
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
                new ControlSequence(new byte[] { 0x1B, 0x29, 0x42 });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
            tSequenceToEncodingMap.put(rightAscii, "US-ASCII");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
            tHighBitsMap.put(rightAscii, Boolean.FALSE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
            ControlSequence rightHalf = // high bit on, leave on
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
                new ControlSequence(new byte[] { 0x1B, 0x2D, 0x41 });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
            tSequenceToEncodingMap.put(rightHalf, "ISO-8859-1");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
            tHighBitsMap.put(rightHalf, Boolean.TRUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
            ControlSequence fullSet = leftAscii.concatenate(rightHalf);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
            tEncodingToSequenceMap.put("ISO-8859-1", fullSet);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
            tEncodings.add("ISO-8859-1");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        if (isEncodingSupported("ISO-8859-2")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
            ControlSequence rightHalf = // high bit on, leave on
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
                new ControlSequence(new byte[] { 0x1B, 0x2D, 0x42 });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
            tSequenceToEncodingMap.put(rightHalf, "ISO-8859-2");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
            tHighBitsMap.put(rightHalf, Boolean.TRUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
            ControlSequence fullSet = leftAscii.concatenate(rightHalf);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
            tEncodingToSequenceMap.put("ISO-8859-2", fullSet);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
            tEncodings.add("ISO-8859-2");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
        if (isEncodingSupported("ISO-8859-3")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
            ControlSequence rightHalf = // high bit on, leave on
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
                new ControlSequence(new byte[] { 0x1B, 0x2D, 0x43 });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
            tSequenceToEncodingMap.put(rightHalf, "ISO-8859-3");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
            tHighBitsMap.put(rightHalf, Boolean.TRUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
            ControlSequence fullSet = leftAscii.concatenate(rightHalf);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
            tEncodingToSequenceMap.put("ISO-8859-3", fullSet);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
            tEncodings.add("ISO-8859-3");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
        if (isEncodingSupported("ISO-8859-4")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
            ControlSequence rightHalf = // high bit on, leave on
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
                new ControlSequence(new byte[] { 0x1B, 0x2D, 0x44 });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
            tSequenceToEncodingMap.put(rightHalf, "ISO-8859-4");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
            tHighBitsMap.put(rightHalf, Boolean.TRUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
            ControlSequence fullSet = leftAscii.concatenate(rightHalf);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
            tEncodingToSequenceMap.put("ISO-8859-4", fullSet);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
            tEncodings.add("ISO-8859-4");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
        if (isEncodingSupported("ISO-8859-5")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
            ControlSequence rightHalf = // high bit on, leave on
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
                new ControlSequence(new byte[] { 0x1B, 0x2D, 0x4C });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
            tSequenceToEncodingMap.put(rightHalf, "ISO-8859-5");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
            tHighBitsMap.put(rightHalf, Boolean.TRUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
            ControlSequence fullSet = leftAscii.concatenate(rightHalf);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
            tEncodingToSequenceMap.put("ISO-8859-5", fullSet);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
            tEncodings.add("ISO-8859-5");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
        if (isEncodingSupported("ISO-8859-6")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
            ControlSequence rightHalf = // high bit on, leave on
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
                new ControlSequence(new byte[] { 0x1B, 0x2D, 0x47 });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
            tSequenceToEncodingMap.put(rightHalf, "ISO-8859-6");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
            tHighBitsMap.put(rightHalf, Boolean.TRUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
            ControlSequence fullSet = leftAscii.concatenate(rightHalf);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
            tEncodingToSequenceMap.put("ISO-8859-6", fullSet);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
            tEncodings.add("ISO-8859-6");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
        if (isEncodingSupported("ISO-8859-7")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
            ControlSequence rightHalf = // high bit on, leave on
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
                new ControlSequence(new byte[] { 0x1B, 0x2D, 0x46 });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
            tSequenceToEncodingMap.put(rightHalf, "ISO-8859-7");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
            tHighBitsMap.put(rightHalf, Boolean.TRUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
            ControlSequence fullSet = leftAscii.concatenate(rightHalf);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
            tEncodingToSequenceMap.put("ISO-8859-7", fullSet);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
            tEncodings.add("ISO-8859-7");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
        if (isEncodingSupported("ISO-8859-8")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
            ControlSequence rightHalf = // high bit on, leave on
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
                new ControlSequence(new byte[] { 0x1B, 0x2D, 0x48 });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
            tSequenceToEncodingMap.put(rightHalf, "ISO-8859-8");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
            tHighBitsMap.put(rightHalf, Boolean.TRUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
            ControlSequence fullSet = leftAscii.concatenate(rightHalf);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
            tEncodingToSequenceMap.put("ISO-8859-8", fullSet);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
            tEncodings.add("ISO-8859-8");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
        if (isEncodingSupported("ISO-8859-9")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
            ControlSequence rightHalf = // high bit on, leave on
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
                new ControlSequence(new byte[] { 0x1B, 0x2D, 0x4D });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
            tSequenceToEncodingMap.put(rightHalf, "ISO-8859-9");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
            tHighBitsMap.put(rightHalf, Boolean.TRUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
            ControlSequence fullSet = leftAscii.concatenate(rightHalf);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
            tEncodingToSequenceMap.put("ISO-8859-9", fullSet);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
            tEncodings.add("ISO-8859-9");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
        if (isEncodingSupported("JIS_X0201")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
            ControlSequence glLeft = // high bit off, leave off
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
                new ControlSequence(new byte[] { 0x1B, 0x28, 0x4A });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
            ControlSequence glRight = // high bit off, turn on
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
                new ControlSequence(new byte[] { 0x1B, 0x28, 0x49 });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
            ControlSequence grLeft = // high bit on, turn off
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
                new ControlSequence(new byte[] { 0x1B, 0x29, 0x4A });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
            ControlSequence grRight = // high bit on, leave on
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
                new ControlSequence(new byte[] { 0x1B, 0x29, 0x49 });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
            tSequenceToEncodingMap.put(glLeft, "JIS_X0201");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
            tSequenceToEncodingMap.put(glRight, "JIS_X0201");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
            tSequenceToEncodingMap.put(grLeft, "JIS_X0201");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
            tSequenceToEncodingMap.put(grRight, "JIS_X0201");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
            tHighBitsMap.put(glLeft, Boolean.FALSE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
            tHighBitsMap.put(glRight, Boolean.TRUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
            tHighBitsMap.put(grLeft, Boolean.FALSE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
            tHighBitsMap.put(grRight, Boolean.TRUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
            ControlSequence fullSet = glLeft.concatenate(grRight);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
            tEncodingToSequenceMap.put("JIS_X0201", fullSet);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
            tEncodings.add("JIS_X0201");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
        if (isEncodingSupported("X11GB2312")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
            ControlSequence leftHalf =  // high bit off, leave off
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
                new ControlSequence(new byte[] { 0x1B, 0x24, 0x28, 0x41 });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
            ControlSequence rightHalf = // high bit on, turn off
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
                new ControlSequence(new byte[] { 0x1B, 0x24, 0x29, 0x41 });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
            tSequenceToEncodingMap.put(leftHalf, "X11GB2312");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
            tSequenceToEncodingMap.put(rightHalf, "X11GB2312");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
            tHighBitsMap.put(leftHalf, Boolean.FALSE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
            tHighBitsMap.put(rightHalf, Boolean.FALSE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
            tEncodingToSequenceMap.put("X11GB2312", leftHalf);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
            tEncodings.add("X11GB2312");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
        if (isEncodingSupported("x-JIS0208")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
            ControlSequence leftHalf = // high bit off, leave off
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
                new ControlSequence(new byte[] { 0x1B, 0x24, 0x28, 0x42 });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
            ControlSequence rightHalf = // high bit on, turn off
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
                new ControlSequence(new byte[] { 0x1B, 0x24, 0x29, 0x42 });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
            tSequenceToEncodingMap.put(leftHalf, "x-JIS0208");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
            tSequenceToEncodingMap.put(rightHalf, "x-JIS0208");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
            tHighBitsMap.put(leftHalf, Boolean.FALSE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
            tHighBitsMap.put(rightHalf, Boolean.FALSE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
            tEncodingToSequenceMap.put("x-JIS0208", leftHalf);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
            tEncodings.add("x-JIS0208");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
        if (isEncodingSupported("X11KSC5601")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
            ControlSequence leftHalf = // high bit off, leave off
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
                new ControlSequence(new byte[] { 0x1B, 0x24, 0x28, 0x43 });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
            ControlSequence rightHalf = // high bit on, turn off
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
                new ControlSequence(new byte[] { 0x1B, 0x24, 0x29, 0x43 });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
            tSequenceToEncodingMap.put(leftHalf, "X11KSC5601");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
            tSequenceToEncodingMap.put(rightHalf, "X11KSC5601");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
            tHighBitsMap.put(leftHalf, Boolean.FALSE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
            tHighBitsMap.put(rightHalf, Boolean.FALSE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
            tEncodingToSequenceMap.put("X11KSC5601", leftHalf);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
            tEncodings.add("X11KSC5601");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
        // Encodings not listed in Compound Text Encoding spec
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
        // Esc seq: -b
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
        if (isEncodingSupported("ISO-8859-15")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
            ControlSequence rightHalf = // high bit on, leave on
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
                new ControlSequence(new byte[] { 0x1B, 0x2D, 0x62 });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
            tSequenceToEncodingMap.put(rightHalf, "ISO-8859-15");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
            tHighBitsMap.put(rightHalf, Boolean.TRUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
            ControlSequence fullSet = leftAscii.concatenate(rightHalf);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
            tEncodingToSequenceMap.put("ISO-8859-15", fullSet);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
            tEncodings.add("ISO-8859-15");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
        // Esc seq: -T
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
        if (isEncodingSupported("TIS-620")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
            ControlSequence rightHalf = // high bit on, leave on
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
                new ControlSequence(new byte[] { 0x1B, 0x2D, 0x54 });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
            tSequenceToEncodingMap.put(rightHalf, "TIS-620");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
            tHighBitsMap.put(rightHalf, Boolean.TRUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
            ControlSequence fullSet = leftAscii.concatenate(rightHalf);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
            tEncodingToSequenceMap.put("TIS-620", fullSet);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
            tEncodings.add("TIS-620");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
        if (isEncodingSupported("JIS_X0212-1990")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
            ControlSequence leftHalf = // high bit off, leave off
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
                new ControlSequence(new byte[] { 0x1B, 0x24, 0x28, 0x44 });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
            ControlSequence rightHalf = // high bit on, turn off
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
                new ControlSequence(new byte[] { 0x1B, 0x24, 0x29, 0x44 });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
            tSequenceToEncodingMap.put(leftHalf, "JIS_X0212-1990");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
            tSequenceToEncodingMap.put(rightHalf, "JIS_X0212-1990");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
            tHighBitsMap.put(leftHalf, Boolean.FALSE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
            tHighBitsMap.put(rightHalf, Boolean.FALSE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
            tEncodingToSequenceMap.put("JIS_X0212-1990", leftHalf);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
            tEncodings.add("JIS_X0212-1990");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
        if (isEncodingSupported("X11CNS11643P1")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
            ControlSequence leftHalf = // high bit off, leave off
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
                new ControlSequence(new byte[] { 0x1B, 0x24, 0x28, 0x47 });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
            ControlSequence rightHalf = // high bit on, turn off
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
                new ControlSequence(new byte[] { 0x1B, 0x24, 0x29, 0x47 });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
            tSequenceToEncodingMap.put(leftHalf, "X11CNS11643P1");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
            tSequenceToEncodingMap.put(rightHalf, "X11CNS11643P1");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
            tHighBitsMap.put(leftHalf, Boolean.FALSE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
            tHighBitsMap.put(rightHalf, Boolean.FALSE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
            tEncodingToSequenceMap.put("X11CNS11643P1", leftHalf);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
            tEncodings.add("X11CNS11643P1");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
        if (isEncodingSupported("X11CNS11643P2")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
            ControlSequence leftHalf = // high bit off, leave off
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
                new ControlSequence(new byte[] { 0x1B, 0x24, 0x28, 0x48 });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
            ControlSequence rightHalf = // high bit on, turn off
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
                new ControlSequence(new byte[] { 0x1B, 0x24, 0x29, 0x48 });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
            tSequenceToEncodingMap.put(leftHalf, "X11CNS11643P2");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
            tSequenceToEncodingMap.put(rightHalf, "X11CNS11643P2");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
            tHighBitsMap.put(leftHalf, Boolean.FALSE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
            tHighBitsMap.put(rightHalf, Boolean.FALSE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
            tEncodingToSequenceMap.put("X11CNS11643P2", leftHalf);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
            tEncodings.add("X11CNS11643P2");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
        if (isEncodingSupported("X11CNS11643P3")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
            ControlSequence leftHalf = // high bit off, leave off
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
                new ControlSequence(new byte[] { 0x1B, 0x24, 0x28, 0x49 });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
            ControlSequence rightHalf = // high bit on, turn off
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
                new ControlSequence(new byte[] { 0x1B, 0x24, 0x29, 0x49 });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
            tSequenceToEncodingMap.put(leftHalf, "X11CNS11643P3");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
            tSequenceToEncodingMap.put(rightHalf, "X11CNS11643P3");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
            tHighBitsMap.put(leftHalf, Boolean.FALSE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
            tHighBitsMap.put(rightHalf, Boolean.FALSE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
            tEncodingToSequenceMap.put("X11CNS11643P3", leftHalf);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
            tEncodings.add("X11CNS11643P3");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
        // Esc seq: %/2??SUN-KSC5601.1992-3
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
        if (isEncodingSupported("x-Johab")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
            // 0x32 looks wrong. It's copied from the Sun X11 Compound Text
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
            // support code. It implies that all Johab characters comprise two
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
            // octets, which isn't true. Johab supports the ASCII/KS-Roman
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
            // characters from 0x21-0x7E with single-byte representations.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
            ControlSequence johab = new ControlSequence(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
                new byte[] { 0x1b, 0x25, 0x2f, 0x32 },
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
                new byte[] { 0x53, 0x55, 0x4e, 0x2d, 0x4b, 0x53, 0x43, 0x35,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
                             0x36, 0x30, 0x31, 0x2e, 0x31, 0x39, 0x39, 0x32,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
                             0x2d, 0x33 });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
            tSequenceToEncodingMap.put(johab, "x-Johab");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
            tEncodingToSequenceMap.put("x-Johab", johab);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
            tEncodings.add("x-Johab");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
        // Esc seq: %/2??SUN-BIG5-1
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
        if (isEncodingSupported("Big5")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
            // 0x32 looks wrong. It's copied from the Sun X11 Compound Text
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
            // support code. It implies that all Big5 characters comprise two
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
            // octets, which isn't true. Big5 supports the ASCII/CNS-Roman
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
            // characters from 0x21-0x7E with single-byte representations.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
            ControlSequence big5 = new ControlSequence(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
                new byte[] { 0x1b, 0x25, 0x2f, 0x32 },
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
                new byte[] { 0x53, 0x55, 0x4e, 0x2d, 0x42, 0x49, 0x47, 0x35,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
                             0x2d, 0x31 });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
            tSequenceToEncodingMap.put(big5, "Big5");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
            tEncodingToSequenceMap.put("Big5", big5);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
            tEncodings.add("Big5");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
        sequenceToEncodingMap =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
            Collections.unmodifiableMap(tSequenceToEncodingMap);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
        highBitsMap = Collections.unmodifiableMap(tHighBitsMap);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
        encodingToSequenceMap =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
            Collections.unmodifiableMap(tEncodingToSequenceMap);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
        encodings = Collections.unmodifiableList(tEncodings);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
    private static boolean isEncodingSupported(String encoding) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
            if (Charset.isSupported(encoding))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
                return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
        } catch (IllegalArgumentException x) { }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
        return (getDecoder(encoding) != null &&
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
                getEncoder(encoding) != null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
    // For Decoder
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
    static CharsetDecoder getStandardDecoder(byte[] escSequence) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
        return getNonStandardDecoder(escSequence, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
    static boolean getHighBit(byte[] escSequence) {
5785
5dfabe612d10 6959197: When building with JAVAC_MAX_WARNINGS=true, the build fails in sun/nio/cs due to the use of -Werror
andrew
parents: 5506
diff changeset
   463
        Boolean bool = highBitsMap.get(new ControlSequence(escSequence));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
        return (bool == Boolean.TRUE);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
    static CharsetDecoder getNonStandardDecoder(byte[] escSequence,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
                                                       byte[] encoding) {
5785
5dfabe612d10 6959197: When building with JAVAC_MAX_WARNINGS=true, the build fails in sun/nio/cs due to the use of -Werror
andrew
parents: 5506
diff changeset
   468
        return getDecoder(sequenceToEncodingMap.get
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
            (new ControlSequence(escSequence, encoding)));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
    static CharsetDecoder getDecoder(String enc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
        if (enc == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
        Charset cs = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
            cs = Charset.forName(enc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
        } catch (IllegalArgumentException e) {
5785
5dfabe612d10 6959197: When building with JAVAC_MAX_WARNINGS=true, the build fails in sun/nio/cs due to the use of -Werror
andrew
parents: 5506
diff changeset
   479
            Class<?> cls;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
                cls = Class.forName("sun.awt.motif." + enc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
            } catch (ClassNotFoundException ee) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
                cs = (Charset)cls.newInstance();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
            } catch (InstantiationException ee) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
            } catch (IllegalAccessException ee) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
            return cs.newDecoder();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
        } catch (UnsupportedOperationException e) {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
    // For Encoder
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
    static byte[] getEscapeSequence(String encoding) {
5785
5dfabe612d10 6959197: When building with JAVAC_MAX_WARNINGS=true, the build fails in sun/nio/cs due to the use of -Werror
andrew
parents: 5506
diff changeset
   502
        ControlSequence seq = encodingToSequenceMap.get(encoding);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
        if (seq != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
            return seq.escSequence;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
    static byte[] getEncoding(String encoding) {
5785
5dfabe612d10 6959197: When building with JAVAC_MAX_WARNINGS=true, the build fails in sun/nio/cs due to the use of -Werror
andrew
parents: 5506
diff changeset
   509
        ControlSequence seq = encodingToSequenceMap.get(encoding);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
        if (seq != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
            return seq.encoding;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
    }
5785
5dfabe612d10 6959197: When building with JAVAC_MAX_WARNINGS=true, the build fails in sun/nio/cs due to the use of -Werror
andrew
parents: 5506
diff changeset
   515
    static List<String> getEncodings() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
        return encodings;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
    static CharsetEncoder getEncoder(String enc) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
        if (enc == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
        Charset cs = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
            cs = Charset.forName(enc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
        } catch (IllegalArgumentException e) {
5785
5dfabe612d10 6959197: When building with JAVAC_MAX_WARNINGS=true, the build fails in sun/nio/cs due to the use of -Werror
andrew
parents: 5506
diff changeset
   526
            Class<?> cls;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
                cls = Class.forName("sun.awt.motif." + enc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
            } catch (ClassNotFoundException ee) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
                cs = (Charset)cls.newInstance();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
            } catch (InstantiationException ee) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
            } catch (IllegalAccessException ee) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
            return cs.newEncoder();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
        } catch (Throwable e) {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
    // Not an instantiable class
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
    private CompoundTextSupport() {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
}