J. Duke | 319a3b9 | 2007-12-01 00:00:00 +0000 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright 2004 Sun Microsystems, Inc. All Rights Reserved. |
| 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
| 4 | * |
| 5 | * This code is free software; you can redistribute it and/or modify it |
| 6 | * under the terms of the GNU General Public License version 2 only, as |
| 7 | * published by the Free Software Foundation. Sun designates this |
| 8 | * particular file as subject to the "Classpath" exception as provided |
| 9 | * by Sun in the LICENSE file that accompanied this code. |
| 10 | * |
| 11 | * This code is distributed in the hope that it will be useful, but WITHOUT |
| 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 14 | * version 2 for more details (a copy is included in the LICENSE file that |
| 15 | * accompanied this code). |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License version |
| 18 | * 2 along with this work; if not, write to the Free Software Foundation, |
| 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
| 20 | * |
| 21 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
| 22 | * CA 95054 USA or visit www.sun.com if you need additional information or |
| 23 | * have any questions. |
| 24 | */ |
| 25 | |
| 26 | /* |
| 27 | */ |
| 28 | |
| 29 | package sun.nio.cs.ext; |
| 30 | |
| 31 | import java.nio.charset.Charset; |
| 32 | import java.nio.charset.CharsetDecoder; |
| 33 | import java.nio.charset.CharsetEncoder; |
| 34 | import sun.nio.cs.HistoricallyNamedCharset; |
| 35 | |
| 36 | public class Big5_Solaris extends Charset implements HistoricallyNamedCharset |
| 37 | { |
| 38 | public Big5_Solaris() { |
| 39 | super("x-Big5-Solaris", ExtendedCharsets.aliasesFor("x-Big5-Solaris")); |
| 40 | } |
| 41 | |
| 42 | public String historicalName() { |
| 43 | return "Big5_Solaris"; |
| 44 | } |
| 45 | |
| 46 | public boolean contains(Charset cs) { |
| 47 | return ((cs.name().equals("US-ASCII")) |
| 48 | || (cs instanceof Big5) |
| 49 | || (cs instanceof Big5_Solaris)); |
| 50 | } |
| 51 | |
| 52 | public CharsetDecoder newDecoder() { |
| 53 | return new Decoder(this); |
| 54 | } |
| 55 | |
| 56 | public CharsetEncoder newEncoder() { |
| 57 | return new Encoder(this); |
| 58 | } |
| 59 | |
| 60 | private static class Decoder extends Big5.Decoder { |
| 61 | |
| 62 | protected char decodeDouble(int byte1, int byte2) { |
| 63 | char c = super.decodeDouble(byte1, byte2); |
| 64 | |
| 65 | // Big5 Solaris implementation has 7 additional mappings |
| 66 | |
| 67 | if (c == REPLACE_CHAR) { |
| 68 | if (byte1 == 0xf9) { |
| 69 | switch (byte2) { |
| 70 | case 0xD6: |
| 71 | c = (char)0x7881; |
| 72 | break; |
| 73 | case 0xD7: |
| 74 | c = (char)0x92B9; |
| 75 | break; |
| 76 | case 0xD8: |
| 77 | c = (char)0x88CF; |
| 78 | break; |
| 79 | case 0xD9: |
| 80 | c = (char)0x58BB; |
| 81 | break; |
| 82 | case 0xDA: |
| 83 | c = (char)0x6052; |
| 84 | break; |
| 85 | case 0xDB: |
| 86 | c = (char)0x7CA7; |
| 87 | break; |
| 88 | case 0xDC: |
| 89 | c = (char)0x5AFA; |
| 90 | break; |
| 91 | } |
| 92 | } |
| 93 | } |
| 94 | return c; |
| 95 | } |
| 96 | |
| 97 | private Decoder(Charset cs) { |
| 98 | super(cs); |
| 99 | } |
| 100 | } |
| 101 | |
| 102 | private static class Encoder extends Big5.Encoder { |
| 103 | |
| 104 | protected int encodeDouble(char ch) { |
| 105 | int r = super.encodeDouble(ch); |
| 106 | |
| 107 | if (r == 0) { |
| 108 | switch (ch) { |
| 109 | case 0x7881: |
| 110 | r = 0xF9D6; |
| 111 | break; |
| 112 | case 0x92B9: |
| 113 | r = 0xF9D7; |
| 114 | break; |
| 115 | case 0x88CF: |
| 116 | r = 0xF9D8; |
| 117 | break; |
| 118 | case 0x58BB: |
| 119 | r = 0xF9D9; |
| 120 | break; |
| 121 | case 0x6052: |
| 122 | r = 0xF9DA; |
| 123 | break; |
| 124 | case 0x7CA7: |
| 125 | r = 0xF9DB; |
| 126 | break; |
| 127 | case 0x5AFA: |
| 128 | r = 0xF9DC; |
| 129 | break; |
| 130 | } |
| 131 | } |
| 132 | return r; |
| 133 | } |
| 134 | |
| 135 | private Encoder(Charset cs) { |
| 136 | super(cs); |
| 137 | } |
| 138 | } |
| 139 | } |