private void parsePattern(String pattern){

		int currentIndex = 0;
		int patternLength = pattern.length();
		Vector<FormatCommandInterface> converterVector = new Vector<FormatCommandInterface>(20);

		while (currentIndex < patternLength) {
			char currentChar = pattern.charAt(currentIndex);

			if (currentChar == '%') {

				currentIndex++;
				currentChar = pattern.charAt(currentIndex);

				switch (currentChar) {
					case CLIENT_ID_CONVERSION_CHAR:
						converterVector.addElement(new ClientIdFormatCommand());
						break;
					case CATEGORY_CONVERSION_CHAR:
						CategoryFormatCommand categoryFormatCommand = new CategoryFormatCommand();
						String specifier = extraxtSpecifier(pattern, currentIndex);
						int specifierLength = specifier.length();
						if (specifierLength > 0) {
							categoryFormatCommand.init(specifier);
							currentIndex = currentIndex + specifierLength + 2;
						}
						converterVector.addElement(categoryFormatCommand);
						break;
					case DATE_CONVERSION_CHAR:
						DateFormatCommand formatCommand = new DateFormatCommand();
						specifier = extraxtSpecifier(pattern, currentIndex);
						specifierLength = specifier.length();
						if (specifierLength > 0) {
							formatCommand.init(specifier);
							currentIndex = currentIndex + specifierLength + 2;
						}
						converterVector.addElement(formatCommand);
						break;
					case MESSAGE_CONVERSION_CHAR:
						converterVector.addElement(new MessageFormatCommand());
						break;

					case PRIORITY_CONVERSION_CHAR:
						converterVector.addElement(new PriorityFormatCommand());
						break;

					case RELATIVE_TIME_CONVERSION_CHAR:
						converterVector.addElement(new TimeFormatCommand());
						break;

					case THREAD_CONVERSION_CHAR:
						converterVector.addElement(new ThreadFormatCommand());
						break;

					case THROWABLE_CONVERSION_CHAR:
						converterVector.addElement(new ThrowableFormatCommand());
						break;

					case PERCENT_CONVERSION_CHAR:
						NoFormatCommand noFormatCommand = new NoFormatCommand();
						noFormatCommand.init("%");
						converterVector.addElement(noFormatCommand);
						break;

					default:
						Log.e(TAG, "Unrecognized conversion character " + currentChar);
						break;
				}

				currentIndex++;

			} else {

				int percentIndex = pattern.indexOf("%", currentIndex);
				String noFormatString = "";
				if (percentIndex != -1) {
					noFormatString = pattern.substring(currentIndex, percentIndex);
				} else {
					noFormatString = pattern.substring(currentIndex, patternLength);
				}

				NoFormatCommand noFormatCommand = new NoFormatCommand();
				noFormatCommand.init(noFormatString);
				converterVector.addElement(noFormatCommand);

				currentIndex = currentIndex + noFormatString.length();
			}

		}

		commandArray = new FormatCommandInterface[converterVector.size()];
		converterVector.copyInto(commandArray);

		patternParsed = true;
	}
private void parsePattern ( String pattern ) { int currentIndex = 0 ; int patternLength = pattern . length ( ) ; Vector < FormatCommandInterface > converterVector = new Vector < FormatCommandInterface > ( 20 ) ; while ( currentIndex < patternLength ) { char currentChar = pattern . charAt ( currentIndex ) ; if ( currentChar == '%' ) { currentIndex ++ ; currentChar = pattern . charAt ( currentIndex ) ; switch ( currentChar ) { case CLIENT_ID_CONVERSION_CHAR : converterVector . addElement ( new ClientIdFormatCommand ( ) ) ; break ; case CATEGORY_CONVERSION_CHAR : CategoryFormatCommand categoryFormatCommand = new CategoryFormatCommand ( ) ; String specifier = extraxtSpecifier ( pattern , currentIndex ) ; int specifierLength = specifier . length ( ) ; if ( specifierLength > 0 ) { categoryFormatCommand . init ( specifier ) ; currentIndex = currentIndex + specifierLength + 2 ; } converterVector . addElement ( categoryFormatCommand ) ; break ; case DATE_CONVERSION_CHAR : DateFormatCommand formatCommand = new DateFormatCommand ( ) ; specifier = extraxtSpecifier ( pattern , currentIndex ) ; specifierLength = specifier . length ( ) ; if ( specifierLength > 0 ) { formatCommand . init ( specifier ) ; currentIndex = currentIndex + specifierLength + 2 ; } converterVector . addElement ( formatCommand ) ; break ; case MESSAGE_CONVERSION_CHAR : converterVector . addElement ( new MessageFormatCommand ( ) ) ; break ; case PRIORITY_CONVERSION_CHAR : converterVector . addElement ( new PriorityFormatCommand ( ) ) ; break ; case RELATIVE_TIME_CONVERSION_CHAR : converterVector . addElement ( new TimeFormatCommand ( ) ) ; break ; case THREAD_CONVERSION_CHAR : converterVector . addElement ( new ThreadFormatCommand ( ) ) ; break ; case THROWABLE_CONVERSION_CHAR : converterVector . addElement ( new ThrowableFormatCommand ( ) ) ; break ; case PERCENT_CONVERSION_CHAR : NoFormatCommand noFormatCommand = new NoFormatCommand ( ) ; noFormatCommand . init ( "%" ) ; converterVector . addElement ( noFormatCommand ) ; break ; default : Log . e ( TAG , "Unrecognized conversion character " + currentChar ) ; break ; } currentIndex ++ ; } else { int percentIndex = pattern . indexOf ( "%" , currentIndex ) ; String noFormatString = "" ; if ( percentIndex != - 1 ) { noFormatString = pattern . substring ( currentIndex , percentIndex ) ; } else { noFormatString = pattern . substring ( currentIndex , patternLength ) ; } NoFormatCommand noFormatCommand = new NoFormatCommand ( ) ; noFormatCommand . init ( noFormatString ) ; converterVector . addElement ( noFormatCommand ) ; currentIndex = currentIndex + noFormatString . length ( ) ; } } commandArray = new FormatCommandInterface [ converterVector . size ( ) ] ; converterVector . copyInto ( commandArray ) ; patternParsed = true ; }
Parse the pattern.

This creates a command array that is executed when formatting the log
message.