/* * Copyright (c) 2009, 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. * * 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.
*/
staticchar[] getEUC_TWChars(boolean skipNR) { //CharsetEncoder encOLD = Charset.forName("EUC_TW_OLD").newEncoder();
CharsetEncoder encOLD = new EUC_TW_OLD().newEncoder();
CharsetEncoder enc = Charset.forName("EUC_TW").newEncoder(); char[] cc = newchar[0x20000]; char[] c2 = newchar[2]; int pos = 0; int i = 0; //bmp for (i = 0; i < 0x10000; i++) { //SKIP these 3 NR codepoints if compared to EUC_TW if (skipNR && (i == 0x4ea0 || i == 0x51ab || i == 0x52f9)) continue; if (encOLD.canEncode((char)i) != enc.canEncode((char)i)) {
System.out.printf(" Err i=%x: old=%b new=%b%n", i,
encOLD.canEncode((char)i),
enc.canEncode((char)i)); thrownew RuntimeException("canEncode() err!");
}
if (enc.canEncode((char)i)) {
cc[pos++] = (char)i;
}
}
//supp
CharBuffer cb = CharBuffer.wrap(newchar[2]); for (i = 0x20000; i < 0x30000; i++) {
Character.toChars(i, c2, 0);
cb.clear();cb.put(c2[0]);cb.put(c2[1]);cb.flip();
if (encOLD.canEncode(cb) != enc.canEncode(cb)) { thrownew RuntimeException("canEncode() err!");
}
// The first byte is the length of malformed bytes staticbyte[][] malformed = { //{5, (byte)0xF8, (byte)0x80, (byte)0x80, (byte)0x9F, (byte)0x80, (byte)0xC0 },
};
staticvoid checkMalformed(Charset cs) throws Exception { boolean failed = false;
String csn = cs.name();
System.out.printf("Check malformed <%s>...%n", csn); for (boolean direct: newboolean[] {false, true}) { for (byte[] bins : malformed) { int mlen = bins[0]; byte[] bin = Arrays.copyOfRange(bins, 1, bins.length);
CoderResult cr = decodeCR(bin, cs, direct);
String ashex = ""; for (int i = 0; i < bin.length; i++) { if (i > 0) ashex += " ";
ashex += Integer.toBinaryString((int)bin[i] & 0xff);
} if (!cr.isMalformed()) {
System.out.printf(" FAIL(direct=%b): [%s] not malformed.\n", direct, ashex);
failed = true;
} elseif (cr.length() != mlen) {
System.out.printf(" FAIL(direct=%b): [%s] malformed[len=%d].\n", direct, ashex, cr.length());
failed = true;
}
}
} if (failed) thrownew RuntimeException("Check malformed failed " + csn);
}
publicstaticvoid main(String[] args) throws Exception { // be the first one //checkInit("EUC_TW_OLD");
checkInit("EUC_TW");
Charset euctw = Charset.forName("EUC_TW");
checkRoundtrip(euctw);
compare(euctw, new EUC_TW_OLD());
checkMalformed(euctw);
checkUnderOverflow(euctw);
}
}
Messung V0.5
¤ Dauer der Verarbeitung: 0.1 Sekunden
(vorverarbeitet)
¤
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.