if (args.length != 2 && args.length != 3) usage(); if (args[0].equals("dump"))
dump(Integer.parseInt(args[1], 16), new ObjectOutputStream(new FileOutputStream(args[2]))); elseif (args[0].equals("load"))
load(Integer.parseInt(args[1], 16), new ObjectInputStream(new FileInputStream(args[2]))); elseif (args[0].equals("check"))
check(Integer.parseInt(args[1], 16), new File(args[2])); elseif (args[0].equals("char"))
showChar(Integer.parseInt(args[1],16)); elseif (args[0].equals("fchar"))
showFileChar(args[1], Integer.parseInt(args[2],16)); else usage(); if (differences != 0) { thrownew RuntimeException("There are differences between Character properties and the specification.");
}
}
staticvoid usage() {
System.err.println("Usage: java CharCheck <command>");
System.err.println("where <command> is one of the following:");
System.err.println("dump <plane> <file> - dumps the character properties of the given plane,");
System.err.println(" read from the current VM, to the given file.");
System.err.println("load <plane> <file> - loads the character properties from the given");
System.err.println(" file and compares them to those of the given character plane");
System.err.println(" in the current VM.");
System.err.println("check <plane> <file> - compare the current VM's character properties");
System.err.println(" in the given plane to those listed in the given file, ");
System.err.println(" which should be in the format available on ");
System.err.println(" ftp.unicode.org/Public/2.0-Update.");
System.err.println("char <code> - show current VM properties of the given Unicode char.");
System.err.println("fchar <file> <code> - show file properties of the given Unicode char.");
System.exit(0);
}
static String getTypeName(int type) { return (type >= 0 && type < UnicodeSpec.generalCategoryList.length) ?
(UnicodeSpec.generalCategoryList[type][UnicodeSpec.LONG] + '(' + type + ')') :
("<Illegal type value " + type + ">");
}
String version = System.getProperty("java.version");
System.out.println("Current VM version " + version); int rangeLimit = (plane << 16) | 0xFFFF;
String record;
UnicodeSpec[] spec = UnicodeSpec.readSpecFile(specFile, plane); int rangeStart = 0x0000; boolean isRange = false;
lastCheck = (plane << 16) - 1;
for (int currentSpec = 0; currentSpec < spec.length; currentSpec++) { int c = spec[currentSpec].getCodePoint(); if (isRange) { // Must see end of range now if (spec[currentSpec].getName().endsWith("Last>")) { for (int d=rangeStart; d<=c; d++) {
checkOneChar(d, spec[currentSpec]);
}
} else { // No good -- First without Last
System.out.println("BAD FILE: First without last at '" + escape(rangeStart) + "'");
}
isRange = false;
} else { // Look for a First, Last pair: This is a pair of entries like the following: // 4E00;<CJK Ideograph, First>;Lo;0;L;;;;;N;;;;; // 9FA5;<CJK Ideograph, Last>;Lo;0;L;;;;;N;;;;; if (spec[currentSpec].getName().endsWith("First>")) {
rangeStart = c;
isRange = true;
} else {
checkOneChar(c, spec[currentSpec]);
}
}
}
// Check undefined chars at the end of the range
while (lastCheck < rangeLimit) checkOneCharDefined(++lastCheck, "?", false);
// In GenerateCharacter, the following ranges are handled specially. // Each is the start of a 26-character range with values 10..35. staticfinalchar NUMERIC_EXCEPTION[] = { '\u0041', '\u0061', '\uFF21', '\uFF41' };
staticvoid checkOneChar(int c, UnicodeSpec charSpec) { // Handle intervening ranges -- we assume that we will be called in monotonically // increasing order. If the last char we checked is more than one before this // char, then check the intervening range -- it should all be undefined. int lowerLimit = (c & 0xFF0000); if (lastCheck >= lowerLimit && (lastCheck+1) != c) { for (int i=lastCheck+1; i<c; ++i)
checkOneCharDefined(i, "?", false);
}
lastCheck = c;
// isDefined should be true
checkOneCharDefined(c, charSpec.getName(), true);
// Check lower, upper, and titlecase conversion int upper = Character.toUpperCase(c); int lower = Character.toLowerCase(c); int title = Character.toTitleCase(c); int upperDB = charSpec.hasUpperMap() ? charSpec.getUpperMap() : c; int lowerDB = charSpec.hasLowerMap() ? charSpec.getLowerMap() : c; int titleDB = charSpec.hasTitleMap() ? charSpec.getTitleMap() : c; if (upper != upperDB) showDifference(c, charSpec.getName(), "upper", hex6(upper), hex6(upperDB)); if (lower != lowerDB) showDifference(c, charSpec.getName(), "lower", hex6(lower), hex6(lowerDB)); if (title != titleDB) showDifference(c, charSpec.getName(), "title", hex6(title), hex6(titleDB));
// Check the character general category (type) int type = Character.getType(c); int typeDB = charSpec.getGeneralCategory(); if (type != typeDB) {
showDifference(c, charSpec.getName(), "type",
UnicodeSpec.generalCategoryList[type][UnicodeSpec.SHORT],
UnicodeSpec.generalCategoryList[typeDB][UnicodeSpec.SHORT]);
}
staticvoid dump(int plane, ObjectOutputStream out) throws Exception {
String version = System.getProperty("java.version");
System.out.println("Writing file version " + version);
out.writeObject(version);
long[] data = newlong[0x20000]; long[] onechar = newlong[2]; int j=0; int begin = plane<<16; int end = begin + 0xFFFF; for (int i = begin; i <= end; ++i) {
getPackedCharacterData(i, onechar);
data[j++] = onechar[0];
data[j++] = onechar[1];
}
out.writeObject(data);
}
staticlong[] loadData(ObjectInputStream in) throws Exception {
String version = System.getProperty("java.version");
String inVersion = (String)in.readObject();
System.out.println("Reading file version " + inVersion);
System.out.println("Current version " + version);
long[] data = (long[])in.readObject(); if (data.length != 0x20000) {
System.out.println("BAD ARRAY LENGTH: " + data.length);
} return data;
}
staticvoid showChar(int c) { long[] chardata = newlong[2];
getPackedCharacterData(c, chardata);
System.out.println("Current VM properties for '" + hex6(c) + "': " +
hex6(chardata[1]) + ' ' + hex6(chardata[0]));
String[] data = unpackCharacterData(chardata); for (int i=0; i<data.length; ++i)
System.out.println(" " + escape(data[i]));
}
staticvoid showFileChar(String fileName, int c) throws Exception {
ObjectInputStream in = new ObjectInputStream(new FileInputStream(fileName));
String inVersion = (String)in.readObject();
System.out.println("Reading file version " + inVersion);
long[] data = (long[])in.readObject(); if (data.length != 0x20000) {
System.out.println("BAD ARRAY LENGTH: " + data.length);
} int offset = c & 0xFFFF; long[] chardata = { data[2*offset], data[2*offset+1] };
String[] datap = unpackCharacterData(chardata);
System.out.println(escape("File properties for '" + hex6(c)+ "':")); for (int i=0; i<datap.length; ++i)
System.out.println(" " + escape(datap[i]));
}
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.