Created
April 10, 2018 14:50
-
-
Save LionZXY/171ab2bc25a6d134ff1c3f190bd6e9e9 to your computer and use it in GitHub Desktop.
Parser old version
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@TargetApi(Build.VERSION_CODES.O) | |
public static void write(File rootDir) throws IllegalAccessException, IOException { | |
Field[] declaredFields = DefaultHyphenator.HyphenPattern.class.getDeclaredFields(); | |
List<Field> staticFields = new ArrayList<Field>(); | |
for (Field field : declaredFields) { | |
if (java.lang.reflect.Modifier.isStatic(field.getModifiers())) { | |
staticFields.add(field); | |
} | |
} | |
for (Field field : staticFields) { | |
File file = new File(rootDir, field.getName() + ".hyp"); | |
DefaultHyphenator.HyphenPattern hyphenPattern = (DefaultHyphenator.HyphenPattern) field.get(null); | |
StringBuilder sb = new StringBuilder(); | |
sb.append(hyphenPattern.leftMin) | |
.append(' ') | |
.append(hyphenPattern.rightMin) | |
.append('\n'); | |
for (Map.Entry<Integer, String> one : hyphenPattern.patternObject.entrySet()) { | |
sb.append(one.getKey()).append(' ').append(one.getValue()).append('\n'); | |
} | |
file.delete(); | |
file.createNewFile(); | |
Files.write(file.toPath(), sb.toString().getBytes(), StandardOpenOption.WRITE); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment