void tokenize(String pat,Vector targetStrings) throws javax.xml.transform.TransformerException {
  m_compiler.m_currentPattern=pat;
  m_patternMapSize=0;
  int initTokQueueSize=((pat.length() < OpMap.MAXTOKENQUEUESIZE) ? pat.length() : OpMap.MAXTOKENQUEUESIZE) * 5;
  m_compiler.m_opMap=new OpMapVector(initTokQueueSize,OpMap.BLOCKTOKENQUEUESIZE * 5,OpMap.MAPINDEX_LENGTH);
  int nChars=pat.length();
  int startSubstring=-1;
  int posOfNSSep=-1;
  boolean isStartOfPat=true;
  boolean isAttrName=false;
  boolean isNum=false;
  int nesting=0;
  for (int i=0; i < nChars; i++) {
    char c=pat.charAt(i);
switch (c) {
case '\"':
{
        if (startSubstring != -1) {
          isNum=false;
          isStartOfPat=mapPatternElemPos(nesting,isStartOfPat,isAttrName);
          isAttrName=false;
          if (-1 != posOfNSSep) {
            posOfNSSep=mapNSTokens(pat,startSubstring,posOfNSSep,i);
          }
 else {
            addToTokenQueue(pat.substring(startSubstring,i));
          }
        }
        startSubstring=i;
        for (i++; (i < nChars) && ((c=pat.charAt(i)) != '\"'); i++)         ;
        if (c == '\"' && i < nChars) {
          addToTokenQueue(pat.substring(startSubstring,i + 1));
          startSubstring=-1;
        }
 else {
          m_processor.error(XPATHErrorResources.ER_EXPECTED_DOUBLE_QUOTE,null);
        }
      }
    break;
case '\'':
  if (startSubstring != -1) {
    isNum=false;
    isStartOfPat=mapPatternElemPos(nesting,isStartOfPat,isAttrName);
    isAttrName=false;
    if (-1 != posOfNSSep) {
      posOfNSSep=mapNSTokens(pat,startSubstring,posOfNSSep,i);
    }
 else {
      addToTokenQueue(pat.substring(startSubstring,i));
    }
  }
startSubstring=i;
for (i++; (i < nChars) && ((c=pat.charAt(i)) != '\''); i++) ;
if (c == '\'' && i < nChars) {
addToTokenQueue(pat.substring(startSubstring,i + 1));
startSubstring=-1;
}
 else {
m_processor.error(XPATHErrorResources.ER_EXPECTED_SINGLE_QUOTE,null);
}
break;
case 0x0A:
case 0x0D:
case ' ':
case '\t':
if (startSubstring != -1) {
isNum=false;
isStartOfPat=mapPatternElemPos(nesting,isStartOfPat,isAttrName);
isAttrName=false;
if (-1 != posOfNSSep) {
posOfNSSep=mapNSTokens(pat,startSubstring,posOfNSSep,i);
}
 else {
addToTokenQueue(pat.substring(startSubstring,i));
}
startSubstring=-1;
}
break;
case '@':
isAttrName=true;
case '-':
if ('-' == c) {
if (!(isNum || (startSubstring == -1))) {
break;
}
isNum=false;
}
case '(':
case '[':
case ')':
case ']':
case '|':
case '/':
case '*':
case '+':
case '=':
case ',':
case '\\':
case '^':
case '!':
case '$':
case '<':
case '>':
if (startSubstring != -1) {
isNum=false;
isStartOfPat=mapPatternElemPos(nesting,isStartOfPat,isAttrName);
isAttrName=false;
if (-1 != posOfNSSep) {
posOfNSSep=mapNSTokens(pat,startSubstring,posOfNSSep,i);
}
 else {
addToTokenQueue(pat.substring(startSubstring,i));
}
startSubstring=-1;
}
 else if (('/' == c) && isStartOfPat) {
isStartOfPat=mapPatternElemPos(nesting,isStartOfPat,isAttrName);
}
 else if ('*' == c) {
isStartOfPat=mapPatternElemPos(nesting,isStartOfPat,isAttrName);
isAttrName=false;
}
if (0 == nesting) {
if ('|' == c) {
if (null != targetStrings) {
recordTokenString(targetStrings);
}
isStartOfPat=true;
}
}
if ((')' == c) || (']' == c)) {
nesting--;
}
 else if (('(' == c) || ('[' == c)) {
nesting++;
}
addToTokenQueue(pat.substring(i,i + 1));
break;
case ':':
if (i > 0) {
if (posOfNSSep == (i - 1)) {
if (startSubstring != -1) {
if (startSubstring < (i - 1)) addToTokenQueue(pat.substring(startSubstring,i - 1));
}
isNum=false;
isAttrName=false;
startSubstring=-1;
posOfNSSep=-1;
addToTokenQueue(pat.substring(i - 1,i + 1));
break;
}
 else {
posOfNSSep=i;
}
}
default :
if (-1 == startSubstring) {
startSubstring=i;
isNum=Character.isDigit(c);
}
 else if (isNum) {
isNum=Character.isDigit(c);
}
}
}
if (startSubstring != -1) {
isNum=false;
isStartOfPat=mapPatternElemPos(nesting,isStartOfPat,isAttrName);
if ((-1 != posOfNSSep) || ((m_namespaceContext != null) && (m_namespaceContext.handlesNullPrefixes()))) {
posOfNSSep=mapNSTokens(pat,startSubstring,posOfNSSep,nChars);
}
 else {
addToTokenQueue(pat.substring(startSubstring,nChars));
}
}
if (0 == m_compiler.getTokenQueueSize()) {
m_processor.error(XPATHErrorResources.ER_EMPTY_EXPRESSION,null);
}
 else if (null != targetStrings) {
recordTokenString(targetStrings);
}
m_processor.m_queueMark=0;
}

void tokenize ( String pat , Vector targetStrings ) throws javax . xml . transform . TransformerException { m_compiler . m_currentPattern = pat ; m_patternMapSize = 0 ; int initTokQueueSize = ( ( pat . length ( ) < OpMap . MAXTOKENQUEUESIZE ) ? pat . length ( ) : OpMap . MAXTOKENQUEUESIZE ) * 5 ; m_compiler . m_opMap = new OpMapVector ( initTokQueueSize , OpMap . BLOCKTOKENQUEUESIZE * 5 , OpMap . MAPINDEX_LENGTH ) ; int nChars = pat . length ( ) ; int startSubstring = - 1 ; int posOfNSSep = - 1 ; boolean isStartOfPat = true ; boolean isAttrName = false ; boolean isNum = false ; int nesting = 0 ; for ( int i = 0 ; i < nChars ; i ++ ) { char c = pat . charAt ( i ) ; switch ( c ) { case '\"' : { if ( startSubstring != - 1 ) { isNum = false ; isStartOfPat = mapPatternElemPos ( nesting , isStartOfPat , isAttrName ) ; isAttrName = false ; if ( - 1 != posOfNSSep ) { posOfNSSep = mapNSTokens ( pat , startSubstring , posOfNSSep , i ) ; } else { addToTokenQueue ( pat . substring ( startSubstring , i ) ) ; } } startSubstring = i ; for ( i ++ ; ( i < nChars ) && ( ( c = pat . charAt ( i ) ) != '\"' ) ; i ++ ) ; if ( c == '\"' && i < nChars ) { addToTokenQueue ( pat . substring ( startSubstring , i + 1 ) ) ; startSubstring = - 1 ; } else { m_processor . error ( XPATHErrorResources . ER_EXPECTED_DOUBLE_QUOTE , null ) ; } } break ; case '\'' : if ( startSubstring != - 1 ) { isNum = false ; isStartOfPat = mapPatternElemPos ( nesting , isStartOfPat , isAttrName ) ; isAttrName = false ; if ( - 1 != posOfNSSep ) { posOfNSSep = mapNSTokens ( pat , startSubstring , posOfNSSep , i ) ; } else { addToTokenQueue ( pat . substring ( startSubstring , i ) ) ; } } startSubstring = i ; for ( i ++ ; ( i < nChars ) && ( ( c = pat . charAt ( i ) ) != '\'' ) ; i ++ ) ; if ( c == '\'' && i < nChars ) { addToTokenQueue ( pat . substring ( startSubstring , i + 1 ) ) ; startSubstring = - 1 ; } else { m_processor . error ( XPATHErrorResources . ER_EXPECTED_SINGLE_QUOTE , null ) ; } break ; case 0x0A : case 0x0D : case ' ' : case '\t' : if ( startSubstring != - 1 ) { isNum = false ; isStartOfPat = mapPatternElemPos ( nesting , isStartOfPat , isAttrName ) ; isAttrName = false ; if ( - 1 != posOfNSSep ) { posOfNSSep = mapNSTokens ( pat , startSubstring , posOfNSSep , i ) ; } else { addToTokenQueue ( pat . substring ( startSubstring , i ) ) ; } startSubstring = - 1 ; } break ; case '@' : isAttrName = true ; case '-' : if ( '-' == c ) { if ( ! ( isNum || ( startSubstring == - 1 ) ) ) { break ; } isNum = false ; } case '(' : case '[' : case ')' : case ']' : case '|' : case '/' : case '*' : case '+' : case '=' : case ',' : case '\\' : case '^' : case '!' : case '$' : case '<' : case '>' : if ( startSubstring != - 1 ) { isNum = false ; isStartOfPat = mapPatternElemPos ( nesting , isStartOfPat , isAttrName ) ; isAttrName = false ; if ( - 1 != posOfNSSep ) { posOfNSSep = mapNSTokens ( pat , startSubstring , posOfNSSep , i ) ; } else { addToTokenQueue ( pat . substring ( startSubstring , i ) ) ; } startSubstring = - 1 ; } else if ( ( '/' == c ) && isStartOfPat ) { isStartOfPat = mapPatternElemPos ( nesting , isStartOfPat , isAttrName ) ; } else if ( '*' == c ) { isStartOfPat = mapPatternElemPos ( nesting , isStartOfPat , isAttrName ) ; isAttrName = false ; } if ( 0 == nesting ) { if ( '|' == c ) { if ( null != targetStrings ) { recordTokenString ( targetStrings ) ; } isStartOfPat = true ; } } if ( ( ')' == c ) || ( ']' == c ) ) { nesting -- ; } else if ( ( '(' == c ) || ( '[' == c ) ) { nesting ++ ; } addToTokenQueue ( pat . substring ( i , i + 1 ) ) ; break ; case ':' : if ( i > 0 ) { if ( posOfNSSep == ( i - 1 ) ) { if ( startSubstring != - 1 ) { if ( startSubstring < ( i - 1 ) ) addToTokenQueue ( pat . substring ( startSubstring , i - 1 ) ) ; } isNum = false ; isAttrName = false ; startSubstring = - 1 ; posOfNSSep = - 1 ; addToTokenQueue ( pat . substring ( i - 1 , i + 1 ) ) ; break ; } else { posOfNSSep = i ; } } default : if ( - 1 == startSubstring ) { startSubstring = i ; isNum = Character . isDigit ( c ) ; } else if ( isNum ) { isNum = Character . isDigit ( c ) ; } } } if ( startSubstring != - 1 ) { isNum = false ; isStartOfPat = mapPatternElemPos ( nesting , isStartOfPat , isAttrName ) ; if ( ( - 1 != posOfNSSep ) || ( ( m_namespaceContext != null ) && ( m_namespaceContext . handlesNullPrefixes ( ) ) ) ) { posOfNSSep = mapNSTokens ( pat , startSubstring , posOfNSSep , nChars ) ; } else { addToTokenQueue ( pat . substring ( startSubstring , nChars ) ) ; } } if ( 0 == m_compiler . getTokenQueueSize ( ) ) { m_processor . error ( XPATHErrorResources . ER_EMPTY_EXPRESSION , null ) ; } else if ( null != targetStrings ) { recordTokenString ( targetStrings ) ; } m_processor . m_queueMark = 0 ; }
walk through the expression and build a token queue , and a map of the top - level elements .
