jdk/src/share/classes/sun/awt/Symbol.java
author malenkov
Tue, 05 Feb 2013 20:07:54 +0400
changeset 16892 24a521782b42
parent 5506 202f599c92aa
permissions -rw-r--r--
8006790: Improve checking for windows Reviewed-by: art, mschoene
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     2
 * Copyright (c) 1997, 2005, 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.awt;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.nio.ByteBuffer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.nio.CharBuffer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.nio.charset.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
public class Symbol extends Charset {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
    public Symbol () {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
        super("Symbol", null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
    public CharsetEncoder newEncoder() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
        return new Encoder(this);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
    /* Seems like supporting a decoder is required, but we aren't going
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
     * to be publically exposing this class, so no need to waste work
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
    public CharsetDecoder newDecoder() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
        throw new Error("Decoder is not implemented for Symbol Charset");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
    public boolean contains(Charset cs) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
        return cs instanceof Symbol;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
    private static class Encoder extends CharsetEncoder {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
        public Encoder(Charset cs) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
            super(cs, 1.0f, 1.0f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
        public boolean canEncode(char c) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
            if (c >= 0x2200 && c <= 0x22ef) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
                if (table_math[c - 0x2200] != 0x00) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
                    return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
            } else if (c >= 0x0391 && c <= 0x03d6) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
                if (table_greek[c - 0x0391] != 0x00) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
                    return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
        protected CoderResult encodeLoop(CharBuffer src, ByteBuffer dst) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
            char[] sa = src.array();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
            int sp = src.arrayOffset() + src.position();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
            int sl = src.arrayOffset() + src.limit();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
            assert (sp <= sl);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
            sp = (sp <= sl ? sp : sl);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
            byte[] da = dst.array();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
            int dp = dst.arrayOffset() + dst.position();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
            int dl = dst.arrayOffset() + dst.limit();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
            assert (dp <= dl);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
            dp = (dp <= dl ? dp : dl);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
                while (sp < sl) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
                    char c = sa[sp];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
                    if (dl - dp < 1)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
                        return CoderResult.OVERFLOW;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
                    if (!canEncode(c))
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
                        return CoderResult.unmappableForLength(1);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
                    sp++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
                    if (c >= 0x2200 && c <= 0x22ef){
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
                        da[dp++] = table_math[c - 0x2200];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
                    } else if (c >= 0x0391 && c <= 0x03d6) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
                        da[dp++]= table_greek[c - 0x0391];
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
                return CoderResult.UNDERFLOW;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
            } finally {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
                src.position(sp - src.arrayOffset());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
                dst.position(dp - dst.arrayOffset());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
        private static byte[] table_math = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
            (byte)0042, (byte)0000, (byte)0144, (byte)0044,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
            (byte)0000, (byte)0306, (byte)0104, (byte)0321,    // 00
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
            (byte)0316, (byte)0317, (byte)0000, (byte)0000,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
            (byte)0000, (byte)0047, (byte)0000, (byte)0120,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
            (byte)0000, (byte)0345, (byte)0055, (byte)0000,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
            (byte)0000, (byte)0244, (byte)0000, (byte)0052,    // 10
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
            (byte)0260, (byte)0267, (byte)0326, (byte)0000,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
            (byte)0000, (byte)0265, (byte)0245, (byte)0000,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
            (byte)0000, (byte)0000, (byte)0000, (byte)0275,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
            (byte)0000, (byte)0000, (byte)0000, (byte)0331,    // 20
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
            (byte)0332, (byte)0307, (byte)0310, (byte)0362,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
            (byte)0000, (byte)0000, (byte)0000, (byte)0000,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
            (byte)0000, (byte)0000, (byte)0000, (byte)0000,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
            (byte)0134, (byte)0000, (byte)0000, (byte)0000,    // 30
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
            (byte)0000, (byte)0000, (byte)0000, (byte)0000,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
            (byte)0176, (byte)0000, (byte)0000, (byte)0000,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
            (byte)0000, (byte)0000, (byte)0000, (byte)0000,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
            (byte)0000, (byte)0100, (byte)0000, (byte)0000,    // 40
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
            (byte)0273, (byte)0000, (byte)0000, (byte)0000,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
            (byte)0000, (byte)0000, (byte)0000, (byte)0000,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
            (byte)0000, (byte)0000, (byte)0000, (byte)0000,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
            (byte)0000, (byte)0000, (byte)0000, (byte)0000,    // 50
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
            (byte)0000, (byte)0000, (byte)0000, (byte)0000,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
            (byte)0000, (byte)0000, (byte)0000, (byte)0000,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
            (byte)0271, (byte)0272, (byte)0000, (byte)0000,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
            (byte)0243, (byte)0263, (byte)0000, (byte)0000,    // 60
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
            (byte)0000, (byte)0000, (byte)0000, (byte)0000,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
            (byte)0000, (byte)0000, (byte)0000, (byte)0000,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
            (byte)0000, (byte)0000, (byte)0000, (byte)0000,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
            (byte)0000, (byte)0000, (byte)0000, (byte)0000,    // 70
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
            (byte)0000, (byte)0000, (byte)0000, (byte)0000,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
            (byte)0000, (byte)0000, (byte)0000, (byte)0000,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
            (byte)0000, (byte)0000, (byte)0314, (byte)0311,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
            (byte)0313, (byte)0000, (byte)0315, (byte)0312,    // 80
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
            (byte)0000, (byte)0000, (byte)0000, (byte)0000,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
            (byte)0000, (byte)0000, (byte)0000, (byte)0000,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
            (byte)0000, (byte)0000, (byte)0000, (byte)0000,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
            (byte)0000, (byte)0305, (byte)0000, (byte)0304,    // 90
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
            (byte)0000, (byte)0000, (byte)0000, (byte)0000,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
            (byte)0000, (byte)0000, (byte)0000, (byte)0000,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
            (byte)0000, (byte)0000, (byte)0000, (byte)0000,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
            (byte)0000, (byte)0136, (byte)0000, (byte)0000,    // a0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
            (byte)0000, (byte)0000, (byte)0000, (byte)0000,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
            (byte)0000, (byte)0000, (byte)0000, (byte)0000,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
            (byte)0000, (byte)0000, (byte)0000, (byte)0000,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
            (byte)0000, (byte)0000, (byte)0000, (byte)0000,    // b0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
            (byte)0000, (byte)0000, (byte)0000, (byte)0000,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
            (byte)0000, (byte)0000, (byte)0000, (byte)0000,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
            (byte)0000, (byte)0000, (byte)0000, (byte)0000,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
            (byte)0340, (byte)0327, (byte)0000, (byte)0000,    // c0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
            (byte)0000, (byte)0000, (byte)0000, (byte)0000,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
            (byte)0000, (byte)0000, (byte)0000, (byte)0000,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
            (byte)0000, (byte)0000, (byte)0000, (byte)0000,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
            (byte)0000, (byte)0000, (byte)0000, (byte)0000,    // d0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
            (byte)0000, (byte)0000, (byte)0000, (byte)0000,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
            (byte)0000, (byte)0000, (byte)0000, (byte)0000,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
            (byte)0000, (byte)0000, (byte)0000, (byte)0000,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
            (byte)0000, (byte)0000, (byte)0000, (byte)0000,    // e0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
            (byte)0000, (byte)0000, (byte)0000, (byte)0000,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
            (byte)0000, (byte)0000, (byte)0000, (byte)0274,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
        };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
        private static byte[] table_greek = {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
            (byte)0101, (byte)0102, (byte)0107,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
            (byte)0104, (byte)0105, (byte)0132, (byte)0110,    // 90
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
            (byte)0121, (byte)0111, (byte)0113, (byte)0114,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
            (byte)0115, (byte)0116, (byte)0130, (byte)0117,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
            (byte)0120, (byte)0122, (byte)0000, (byte)0123,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
            (byte)0124, (byte)0125, (byte)0106, (byte)0103,    // a0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
            (byte)0131, (byte)0127, (byte)0000, (byte)0000,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
            (byte)0000, (byte)0000, (byte)0000, (byte)0000,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
            (byte)0000, (byte)0141, (byte)0142, (byte)0147,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
            (byte)0144, (byte)0145, (byte)0172, (byte)0150,    // b0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
            (byte)0161, (byte)0151, (byte)0153, (byte)0154,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
            (byte)0155, (byte)0156, (byte)0170, (byte)0157,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
            (byte)0160, (byte)0162, (byte)0126, (byte)0163,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
            (byte)0164, (byte)0165, (byte)0146, (byte)0143,    // c0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
            (byte)0171, (byte)0167, (byte)0000, (byte)0000,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
            (byte)0000, (byte)0000, (byte)0000, (byte)0000,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
            (byte)0000, (byte)0112, (byte)0241, (byte)0000,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
            (byte)0000, (byte)0152, (byte)0166,                // d0
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
        };
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
        /* The default implementation creates a decoder and we don't have one */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        public boolean isLegalReplacement(byte[] repl) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
}