protected int toExactWidthRegex( PatternAPI pattern, Locale locale, String flags, Justification j, char padding, int width, int precision, String formatString, int position) { WidthMatchSubpatterns sub = createSubpatterns(pattern, locale, flags, j, padding, width, precision); sub.open(); sub.paddingWidth = -1; int result = appendExactWidthRegex( sub, locale, flags, Justification.None, padding, -1, precision, formatString, position); for (int w = 0; w <= width; w++) { sub.paddingWidth = width - w; int r = appendExactWidthRegex( sub, locale, flags, j, padding, w, precision, formatString, position); if (r != IGNORE_SUBPATTERN) result = r; } sub.close(); pattern.putMemento(sub); return result; }
@Override public Object parse( MatcherAPI matcherAPI, Matcher matcher, int capturingBase, Object memento, Object lastArgValue) { if (memento instanceof WidthMatchSubpatterns) { WidthMatchSubpatterns sub = (WidthMatchSubpatterns) memento; int n = sub.getMatchingPattern(matcher, capturingBase); capturingBase += sub.getCapturingOffset(n); Object m = sub.getMemento(n); return parse(matcher, capturingBase, n - 1, m, lastArgValue); } else { return parse(matcher, capturingBase + 1, -2, memento, lastArgValue); } }
protected int appendExactWidthRegex( WidthMatchSubpatterns sub, Locale locale, String flags, Justification j, char padding, int width, int precision, String formatString, int position) { sub.beginSubpattern(); int r = toRegex(sub.api(), locale, flags, padding, width, precision, formatString, position); if (r == IGNORE_SUBPATTERN) sub.ignoreSubpattern(); else sub.allowEmptySubpattern(); sub.endSubpattern(); return r; }