/* * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this * particular file as subject to the "Classpath" exception as provided * by Oracle in the LICENSE file that accompanied this code. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions.
*/
publicchar decodeDoubleEx(int b1, int b2) { /* if the b2cSupp is null, the subclass need to override the methold if (b2cSupp == null) return UNMAPPABLE_DECODING;
*/ return b2cSupp[b1][b2 - b2Min];
}
protected CoderResult decodeArrayLoop(ByteBuffer src, CharBuffer dst) { byte[] sa = src.array(); int sp = src.arrayOffset() + src.position(); int sl = src.arrayOffset() + src.limit();
char[] da = dst.array(); int dp = dst.arrayOffset() + dst.position(); int dl = dst.arrayOffset() + dst.limit();
try { while (sp < sl) { int b1 = sa[sp] & 0xff; char c = decodeSingle(b1); int inSize = 1, outSize = 1; if (c == UNMAPPABLE_DECODING) { if (sl - sp < 2) return CoderResult.UNDERFLOW; int b2 = sa[sp + 1] & 0xff;
inSize++; if (b2 < b2Min || b2 > b2Max) return CoderResult.unmappableForLength(2);
c = decodeDouble(b1, b2); //bmp if (c == UNMAPPABLE_DECODING) {
c = decodeDoubleEx(b1, b2); //supp if (c == UNMAPPABLE_DECODING) {
c = decodeBig5(b1, b2); //big5 if (c == UNMAPPABLE_DECODING) return CoderResult.unmappableForLength(2);
} else { // supplementary character in u+2xxxx area
outSize = 2;
}
}
} if (dl - dp < outSize) return CoderResult.OVERFLOW; if (outSize == 2) { // supplementary characters
da[dp++] = Surrogate.high(0x20000 + c);
da[dp++] = Surrogate.low(0x20000 + c);
} else {
da[dp++] = c;
}
sp += inSize;
} return CoderResult.UNDERFLOW;
} finally {
src.position(sp - src.arrayOffset());
dst.position(dp - dst.arrayOffset());
}
}
protected CoderResult decodeBufferLoop(ByteBuffer src, CharBuffer dst) { int mark = src.position(); try { while (src.hasRemaining()) { int b1 = src.get() & 0xff; int inSize = 1, outSize = 1; char c = decodeSingle(b1); if (c == UNMAPPABLE_DECODING) { if (src.remaining() < 1) return CoderResult.UNDERFLOW; int b2 = src.get() & 0xff;
inSize++; if (b2 < b2Min || b2 > b2Max) return CoderResult.unmappableForLength(2);
c = decodeDouble(b1, b2); //bmp if (c == UNMAPPABLE_DECODING) {
c = decodeDoubleEx(b1, b2); //supp if (c == UNMAPPABLE_DECODING) {
c = decodeBig5(b1, b2); //big5 if (c == UNMAPPABLE_DECODING) return CoderResult.unmappableForLength(2);
} else {
outSize = 2;
}
}
} if (dst.remaining() < outSize) return CoderResult.OVERFLOW; if (outSize == 2) {
dst.put(Surrogate.high(0x20000 + c));
dst.put(Surrogate.low(0x20000 + c));
} else {
dst.put(c);
}
mark += inSize;
} return CoderResult.UNDERFLOW;
} finally {
src.position(mark);
}
}
publicint decode(byte[] src, int sp, int len, char[] dst) { int dp = 0; int sl = sp + len; char repl = replacement().charAt(0); while (sp < sl) { int b1 = src[sp++] & 0xff; char c = decodeSingle(b1); if (c == UNMAPPABLE_DECODING) { if (sl == sp) {
c = repl;
} else { int b2 = src[sp++] & 0xff; if (b2 < b2Min || b2 > b2Max) {
c = repl;
} elseif ((c = decodeDouble(b1, b2)) == UNMAPPABLE_DECODING) {
c = decodeDoubleEx(b1, b2); //supp if (c == UNMAPPABLE_DECODING) {
c = decodeBig5(b1, b2); //big5 if (c == UNMAPPABLE_DECODING)
c = repl;
} else { // supplementary character in u+2xxxx area
dst[dp++] = Surrogate.high(0x20000 + c);
dst[dp++] = Surrogate.low(0x20000 + c); continue;
}
}
}
}
dst[dp++] = c;
} return dp;
}
public CoderResult decodeLoop(ByteBuffer src, CharBuffer dst) { if (src.hasArray() && dst.hasArray()) return decodeArrayLoop(src, dst); else return decodeBufferLoop(src, dst);
}
publicstaticvoid initb2c(char[][]b2c, String[] b2cStr)
{ for (int i = 0; i < b2cStr.length; i++) { if (b2cStr[i] == null)
b2c[i] = DoubleByte.B2C_UNMAPPABLE; else
b2c[i] = b2cStr[i].toCharArray();
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.