Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/solaris/classes/sun/awt/motif/X11JIS0201.java
32288 views
/*1* Copyright (c) 1996, 2012, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package sun.awt.motif;2627import java.nio.ByteBuffer;28import java.nio.CharBuffer;29import java.nio.charset.*;30import sun.nio.cs.*;31import sun.nio.cs.ext.JIS_X_0201;32import static sun.nio.cs.CharsetMapping.*;3334public class X11JIS0201 extends Charset {3536private static Charset jis0201 = new JIS_X_0201();37private static SingleByte.Encoder enc =38(SingleByte.Encoder)jis0201.newEncoder();3940public X11JIS0201 () {41super("X11JIS0201", null);42}4344public CharsetEncoder newEncoder() {45return new Encoder(this);46}4748public CharsetDecoder newDecoder() {49return jis0201.newDecoder();50}5152public boolean contains(Charset cs) {53return cs instanceof X11JIS0201;54}5556private class Encoder extends CharsetEncoder {5758public Encoder(Charset cs) {59super(cs, 1.0f, 1.0f);60}6162public boolean canEncode(char c){63if ((c >= 0xff61 && c <= 0xff9f)64|| c == 0x203e65|| c == 0xa5) {66return true;67}68return false;69}7071private Surrogate.Parser sgp;72protected CoderResult encodeLoop(CharBuffer src, ByteBuffer dst) {73char[] sa = src.array();74int sp = src.arrayOffset() + src.position();75int sl = src.arrayOffset() + src.limit();7677byte[] da = dst.array();78int dp = dst.arrayOffset() + dst.position();79int dl = dst.arrayOffset() + dst.limit();80CoderResult cr = CoderResult.UNDERFLOW;81if ((dl - dp) < (sl - sp)) {82sl = sp + (dl - dp);83cr = CoderResult.OVERFLOW;84}85try {86while (sp < sl) {87char c = sa[sp];88int b = enc.encode(c);89if (b == UNMAPPABLE_ENCODING) {90if (Character.isSurrogate(c)) {91if (sgp == null)92sgp = new Surrogate.Parser();93if (sgp.parse(c, sa, sp, sl) >= 0)94return CoderResult.unmappableForLength(2);95}96return CoderResult.unmappableForLength(1);97}98da[dp++] = (byte)b;99sp++;100}101return cr;102} finally {103src.position(sp - src.arrayOffset());104dst.position(dp - dst.arrayOffset());105}106}107}108}109110111