Beispiel #1
0
 @Override
 public int toRegex(
     PatternAPI pattern,
     Locale locale,
     String flags,
     int width,
     int precision,
     String formatString,
     int position) {
   ensureValidFlags(flags, getValidFlags());
   Justification j = getJustification(flags, width);
   char padding = j == Justification.None ? 0 : getPaddingChar(flags);
   if (j != Justification.None && matchExactWidth(flags, width)) {
     return toExactWidthRegex(
         pattern, locale, flags, j, padding, width, precision, formatString, position);
   }
   switch (j) {
     case Center:
     case Right:
       appendPadding(pattern, padding);
   }
   pattern.addedCapturingGroup();
   pattern.append('(');
   int result = toRegex(pattern, locale, flags, padding, precision, formatString, position);
   pattern.append(')');
   switch (j) {
     case Left:
     case Center:
       appendPadding(pattern, padding);
   }
   return result;
 }
Beispiel #2
0
  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;
  }
Beispiel #3
0
 protected void appendPadding(final PatternAPI pattern, final char padding, int w) {
   if (w <= 0) return;
   pattern.append("[");
   if (padding == ']') pattern.append('\\');
   pattern.append(padding);
   pattern.append("]{");
   pattern.append(String.valueOf(w));
   pattern.append("}");
 }
Beispiel #4
0
 protected void appendPadding(final PatternAPI pattern, final char padding) {
   pattern.append("[");
   if (padding == ']') pattern.append('\\');
   pattern.append(padding);
   pattern.append("]*");
 }