Пример #1
0
 public void finalizeConverter(char c) {
   if (c == '#') {
     addConverter(new UserDirPatternConverter(formattingInfo));
     currentLiteral.setLength(0);
   } else {
     super.finalizeConverter(c);
   }
 }
Пример #2
0
 public PatternConverter parse() {
   char c;
   i = 0;
   while (i < patternLength) {
     c = pattern.charAt(i++);
     switch (state) {
       case LITERAL_STATE:
         // In literal state, the last char is always a literal.
         if (i == patternLength) {
           currentLiteral.append(c);
           continue;
         }
         if (c == ESCAPE_CHAR) {
           // peek at the next char.
           switch (pattern.charAt(i)) {
             case ESCAPE_CHAR:
               currentLiteral.append(c);
               i++; // move pointer
               break;
             case 'n':
               currentLiteral.append(Layout.LINE_SEP);
               i++; // move pointer
               break;
             default:
               if (currentLiteral.length() != 0) {
                 addToList(new LiteralPatternConverter(currentLiteral.toString()));
                 // LogLog.debug("Parsed LITERAL converter: \""
                 //           +currentLiteral+"\".");
               }
               currentLiteral.setLength(0);
               currentLiteral.append(c); // append %
               state = CONVERTER_STATE;
               formattingInfo.reset();
           }
         } else {
           currentLiteral.append(c);
         }
         break;
       case CONVERTER_STATE:
         currentLiteral.append(c);
         switch (c) {
           case '-':
             formattingInfo.leftAlign = true;
             break;
           case '.':
             state = DOT_STATE;
             break;
           default:
             if (c >= '0' && c <= '9') {
               formattingInfo.min = c - '0';
               state = MIN_STATE;
             } else finalizeConverter(c);
         } // switch
         break;
       case MIN_STATE:
         currentLiteral.append(c);
         if (c >= '0' && c <= '9') formattingInfo.min = formattingInfo.min * 10 + (c - '0');
         else if (c == '.') state = DOT_STATE;
         else {
           finalizeConverter(c);
         }
         break;
       case DOT_STATE:
         currentLiteral.append(c);
         if (c >= '0' && c <= '9') {
           formattingInfo.max = c - '0';
           state = MAX_STATE;
         } else {
           LogLog.error(
               "Error occured in position "
                   + i
                   + ".\n Was expecting digit, instead got char \""
                   + c
                   + "\".");
           state = LITERAL_STATE;
         }
         break;
       case MAX_STATE:
         currentLiteral.append(c);
         if (c >= '0' && c <= '9') formattingInfo.max = formattingInfo.max * 10 + (c - '0');
         else {
           finalizeConverter(c);
           state = LITERAL_STATE;
         }
         break;
     } // switch
   } // while
   if (currentLiteral.length() != 0) {
     addToList(new LiteralPatternConverter(currentLiteral.toString()));
     // LogLog.debug("Parsed LITERAL converter: \""+currentLiteral+"\".");
   }
   return head;
 }
 /*     */ public PatternConverter parse() /*     */ {
   /* 134 */ this.i = 0;
   /* 135 */ while (this.i < this.patternLength) {
     /* 136 */ char c = this.pattern.charAt(this.i++);
     /* 137 */ switch (this.state)
     /*     */ {
         /*     */ case 0:
         /* 140 */ if (this.i == this.patternLength) {
           /* 141 */ this.currentLiteral.append(c);
           /*     */ }
         /* 144 */ else if (c == '%')
         /*     */ {
           /* 146 */ switch (this.pattern.charAt(this.i)) {
               /*     */ case '%':
               /* 148 */ this.currentLiteral.append(c);
               /* 149 */ this.i += 1;
               /* 150 */ break;
               /*     */ case 'n':
               /* 152 */ this.currentLiteral.append(Layout.LINE_SEP);
               /* 153 */ this.i += 1;
               /* 154 */ break;
               /*     */ default:
               /* 156 */ if (this.currentLiteral.length() != 0) {
                 /* 157 */ addToList(new LiteralPatternConverter(this.currentLiteral.toString()));
                 /*     */ }
               /*     */
               /* 162 */ this.currentLiteral.setLength(0);
               /* 163 */ this.currentLiteral.append(c);
               /* 164 */ this.state = 1;
               /* 165 */ this.formattingInfo.reset();
               break;
               /*     */ }
           /*     */ }
         /*     */ else {
           /* 169 */ this.currentLiteral.append(c);
           /*     */ }
         /* 171 */ break;
         /*     */ case 1:
         /* 173 */ this.currentLiteral.append(c);
         /* 174 */ switch (c) {
             /*     */ case '-':
             /* 176 */ this.formattingInfo.leftAlign = true;
             /* 177 */ break;
             /*     */ case '.':
             /* 179 */ this.state = 3;
             /* 180 */ break;
             /*     */ default:
             /* 182 */ if ((c >= '0') && (c <= '9')) {
               /* 183 */ this.formattingInfo.min = (c - '0');
               /* 184 */ this.state = 4;
               /*     */ }
             /*     */ else {
               /* 187 */ finalizeConverter(c);
               /*     */ }
             /*     */ }
         /* 189 */ break;
         /*     */ case 4:
         /* 191 */ this.currentLiteral.append(c);
         /* 192 */ if ((c >= '0') && (c <= '9'))
           /* 193 */ this.formattingInfo.min = (this.formattingInfo.min * 10 + (c - '0'));
         /* 194 */ else if (c == '.') /* 195 */ this.state = 3;
         /*     */ else {
           /* 197 */ finalizeConverter(c);
           /*     */ }
         /* 199 */ break;
         /*     */ case 3:
         /* 201 */ this.currentLiteral.append(c);
         /* 202 */ if ((c >= '0') && (c <= '9')) {
           /* 203 */ this.formattingInfo.max = (c - '0');
           /* 204 */ this.state = 5;
           /*     */ }
         /*     */ else {
           /* 207 */ LogLog.error(
               "Error occured in position "
                   + this.i
                   + ".\n Was expecting digit, instead got char \""
                   + c
                   + "\".");
           /*     */
           /* 209 */ this.state = 0;
           /*     */ }
         /* 211 */ break;
         /*     */ case 5:
         /* 213 */ this.currentLiteral.append(c);
         /* 214 */ if ((c >= '0') && (c <= '9')) {
           /* 215 */ this.formattingInfo.max = (this.formattingInfo.max * 10 + (c - '0'));
           /*     */ } else {
           /* 217 */ finalizeConverter(c);
           /* 218 */ this.state = 0;
           /*     */ }
         /*     */ case 2:
         /*     */ }
     /*     */ }
   /* 223 */ if (this.currentLiteral.length() != 0) {
     /* 224 */ addToList(new LiteralPatternConverter(this.currentLiteral.toString()));
     /*     */ }
   /*     */
   /* 227 */ return this.head;
   /*     */ }