private appendCodePoint ( int par0 ) : global::java.lang.StringBuilder | ||
par0 | int | |
Результат | global::java.lang.StringBuilder |
private int normalizeCharClass(StringBuilder newPattern, int i) { StringBuilder charClass = new StringBuilder(); StringBuilder eq = null; int lastCodePoint = -1; String result; i++; charClass.append("["); while(true) { int c = normalizedPattern.codePointAt(i); StringBuilder sequenceBuffer; if (c == ']' && lastCodePoint != '\\') { charClass.append((char)c); break; } else if (Character.getType(c) == Character.NON_SPACING_MARK) { sequenceBuffer = new StringBuilder(); sequenceBuffer.appendCodePoint(lastCodePoint); while(Character.getType(c) == Character.NON_SPACING_MARK) { sequenceBuffer.appendCodePoint(c); i += Character.charCount(c); if (i >= normalizedPattern.length()) break; c = normalizedPattern.codePointAt(i); } String ea = produceEquivalentAlternation( sequenceBuffer.toString()); charClass.setLength(charClass.length()-Character.charCount(lastCodePoint)); if (eq == null) eq = new StringBuilder(); eq.append('|'); eq.append(ea); } else { charClass.appendCodePoint(c); i++; } if (i == normalizedPattern.length()) throw error(new String("Unclosed character class")); lastCodePoint = c; } if (eq != null) { result = new String("(?:"+charClass.toString()+eq.toString()+")"); } else { result = charClass.toString(); } newPattern.append(result); return i; }
private String[] producePermutations(String input) { if (input.length() == countChars(input, 0, 1)) return new String[] {input}; if (input.length() == countChars(input, 0, 2)) { int c0 = Character.codePointAt(input, 0); int c1 = Character.codePointAt(input, Character.charCount(c0)); if (getClass(c1) == getClass(c0)) { return new String[] {input}; } String[] result = new String[2]; result[0] = input; StringBuilder sb = new StringBuilder(2); sb.appendCodePoint(c1); sb.appendCodePoint(c0); result[1] = sb.toString(); return result; } int length = 1; int nCodePoints = countCodePoints(input); for(int x=1; x<nCodePoints; x++) length = length * (x+1); String[] temp = new String[length]; int[] combClass = new int[nCodePoints]; for(int x=0, i=0; x<nCodePoints; x++) { int c = Character.codePointAt(input, i); combClass[x] = getClass(c); i += Character.charCount(c); } // For each char, take it out and add the permutations // of the remaining chars int index = 0; int len; // offset maintains the index in code units. for(int x=0, offset=0; x<nCodePoints; x++, offset+=len) { continue1: len = countChars(input, offset, 1); boolean skip = false; for(int y=x-1; y>=0; y--) { if (combClass[y] == combClass[x]) { offset+=len; if (x < nCodePoints) goto continue1; goto end1; } } StringBuilder sb = new StringBuilder(input); String otherChars = sb.delete(offset, offset+len).toString(); String[] subResult = producePermutations(otherChars); String prefix = input.substring(offset, offset+len); for(int y=0; y<subResult.Length; y++) temp[index++] = prefix + subResult[y]; } end1: String[] _result = new String[index]; for (int x=0; x<index; x++) _result[x] = temp[x]; return _result; }
private void normalize() { boolean inCharClass = false; int lastCodePoint = -1; // Convert pattern into normalizedD form normalizedPattern = Normalizer.normalize(pattern, Normalizer.Form.NFD); patternLength = normalizedPattern.length(); // Modify pattern to match canonical equivalences StringBuilder newPattern = new StringBuilder(patternLength); for(int i=0; i<patternLength; ) { int c = normalizedPattern.codePointAt(i); StringBuilder sequenceBuffer; if ((Character.getType(c) == Character.NON_SPACING_MARK) && (lastCodePoint != -1)) { sequenceBuffer = new StringBuilder(); sequenceBuffer.appendCodePoint(lastCodePoint); sequenceBuffer.appendCodePoint(c); while(Character.getType(c) == Character.NON_SPACING_MARK) { i += Character.charCount(c); if (i >= patternLength) break; c = normalizedPattern.codePointAt(i); sequenceBuffer.appendCodePoint(c); } String ea = produceEquivalentAlternation( sequenceBuffer.toString()); newPattern.setLength(newPattern.length()-Character.charCount(lastCodePoint)); newPattern.append("(?:").append(ea).append(")"); } else if (c == '[' && lastCodePoint != '\\') { i = normalizeCharClass(newPattern, i); } else { newPattern.appendCodePoint(c); } lastCodePoint = c; i += Character.charCount(c); } normalizedPattern = newPattern.toString(); }