Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Logback: the reliable, generic, fast and flexible logging framework. Copyright (C) 1999-2012, QOS.ch. All rights reserved. This program and the accompanying materials are dual-licensed under either the terms of the Eclipse Public License v1.0 as published by the Eclipse Foundation or (per the licensee's choosing) under the terms of the GNU Lesser General Public License version 2.1 as published by the Free Software Foundation.
 
 package ch.qos.logback.core.subst;
 
 
 import java.util.List;
 
 public class Tokenizer {
 
   enum TokenizerState {LITERAL_STATE, START_STATE, DEFAULT_VAL_STATE}
 
   final String pattern;
   final int patternLength;
 
   public Tokenizer(String pattern) {
     this. = pattern;
      = pattern.length();
   }
 
   int pointer = 0;
 
   List tokenize() throws ScanException {
     List<TokentokenList = new ArrayList<Token>();
     StringBuilder buf = new StringBuilder();
 
     while ( < ) {
       char c = .charAt();
       ++;
 
       switch () {
         case :
           handleLiteralState(ctokenListbuf);
           break;
         case :
           handleStartState(ctokenListbuf);
           break;
         case :
           handleDefaultValueState(ctokenListbuf);
         default:
       }
     }
     // EOS
     switch () {
       case :
         addLiteralToken(tokenListbuf);
         break;
       case :
         throw new ScanException("Unexpected end of pattern string");
     }
     return tokenList;
   }
 
   private void handleDefaultValueState(char cList<TokentokenListStringBuilder stringBuilder) {
     if (c == .) {
       tokenList.add(.);
     } else {
       stringBuilder.append(.).append(c);
     }
   }
 
   private void handleStartState(char cList<TokentokenListStringBuilder stringBuilder) {
     if (c == .) {
       tokenList.add(.);
     } else {
       stringBuilder.append(.).append(c);
     }
   }
 
   private void handleLiteralState(char cList<TokentokenListStringBuilder stringBuilder) {
     if (c == .) {
       addLiteralToken(tokenListstringBuilder);
       stringBuilder.setLength(0);
     } else if (c == .) {
       addLiteralToken(tokenListstringBuilder);
       stringBuilder.setLength(0);
     } else if (c == .) {
       addLiteralToken(tokenListstringBuilder);
       tokenList.add(.);
       stringBuilder.setLength(0);
     } else  if (c == .) {
      addLiteralToken(tokenListstringBuilder);
      tokenList.add(.);
      stringBuilder.setLength(0);
    } else {
      stringBuilder.append(c);
    }
  }
  private void addLiteralToken(List<TokentokenListStringBuilder stringBuilder) {
    if (stringBuilder.length() == 0)
      return;
    tokenList.add(new Token(..stringBuilder.toString()));
  }
New to GrepCode? Check out our FAQ X