in jflex/src/main/java/jflex/Main.java [245:291]
private static void printUnicodePropertyValuesAndAliases(String unicodeVersion)
throws UnicodeProperties.UnsupportedUnicodeVersionException {
Pattern versionPattern = Pattern.compile("(\\d+)(?:\\.(\\d+))?(?:\\.\\d+)?");
Matcher matcher = versionPattern.matcher(unicodeVersion);
if (!matcher.matches()) {
throw new UnicodeProperties.UnsupportedUnicodeVersionException();
}
String underscoreVersion =
matcher.group(1) + (null == matcher.group(2) ? "_0" : "_" + matcher.group(2));
String[] propertyValues;
String[] propertyValueAliases;
try {
Class<?> clazz = Class.forName("jflex.unicode.data.Unicode_" + underscoreVersion);
Field field = clazz.getField("propertyValues");
propertyValues = (String[]) field.get(null);
field = clazz.getField("propertyValueAliases");
propertyValueAliases = (String[]) field.get(null);
} catch (Exception e) {
throw new UnicodeProperties.UnsupportedUnicodeVersionException(e);
}
SortedMap<String, SortedSet<String>> propertyValuesToAliases = new TreeMap<>();
for (String value : propertyValues) {
propertyValuesToAliases.put(value, new TreeSet<String>());
}
for (int i = 0; i < propertyValueAliases.length - 1; i += 2) {
String alias = propertyValueAliases[i];
String value = propertyValueAliases[i + 1];
SortedSet<String> aliases = propertyValuesToAliases.get(value);
if (null == aliases) {
aliases = new TreeSet<>();
propertyValuesToAliases.put(value, aliases);
}
aliases.add(alias);
}
for (Map.Entry<String, SortedSet<String>> entry : propertyValuesToAliases.entrySet()) {
String value = entry.getKey();
SortedSet<String> aliases = entry.getValue();
Out.print(value);
if (aliases.size() > 0) {
for (String alias : aliases) {
Out.print(", " + alias);
}
}
Out.println("");
}
}