TextPatternUtil { public static String findPattern(String stringToRecognize) { StringBuilder sb = new StringBuilder(); boolean skipNextOne = false; for (int i = 0; i < stringToRecognize.length(); i++) { if (skipNextOne) { skipNextOne = false; continue; } Integer codePoint = stringToRecognize.codePointAt(i); if (isValidProlongedSoundMark(codePoint, sb)) { sb.append(sb.charAt(sb.length() - 1)); } else { sb.append(Character.toChars(findReplaceCodePoint(codePoint))); } if (Character.isHighSurrogate(stringToRecognize.charAt(i))) { skipNextOne = true; } } return sb.toString(); } private  TextPatternUtil(); static String findPattern(String stringToRecognize); static Integer replaceCharacter(Integer codePointToReplace, Random random); static List<Integer> replaceStringCodePoints(String stringToReplace, Random random); static char[] replacePatternCharacter(Integer codePointToReplace, Random random); static Set<CharPattern> getCharPatterns(List<Integer> codePoints, List<Integer> filteredCodepoints); static CharPattern getCharPattern(Integer codepoint); static final int PROLONGED_SOUND_MARK; }
@Test public void testFindPattern() { checkPattern("ケーキ", "KKK"); checkPattern("bーキ", "aーK"); checkPattern("ｰヽヾ", "kKK"); checkPattern("ゝゞゟ", "HHゟ"); checkPattern("ほーむ", "HHH"); checkPattern("dー", "aー"); checkPattern("abc-d", "aaa-a"); checkPattern("Straße", "Aaaaaa"); checkPattern("トンキンｨｩ", "KKKKkk"); checkPattern("とうきょう", "HHHHH"); checkPattern("서울", "GG"); checkPattern("北京", "CC"); checkPattern("\uD840\uDC00", "C"); checkPattern("\uD840\uDC40\uD840\uDFD3\uD841\uDC01\uD840\uDFD3", "CCCC"); }