public static Object parsePattern ( String pattern ) { // Unfortunately, this method shares a fair amount of logic with Topic.parsePattern // but it is hard to figure out how to factor them. char [ ] accum = new char [ pattern . length ( ) ] ; int finger = 0 ; List tokens = new ArrayList ( ) ; boolean trivial = true ; for ( int i = 0 ; i < pattern . length ( ) ; i ++ ) { char c = pattern . charAt ( i ) ; if ( c == ' ' ) { finger = flush ( accum , finger , tokens ) ; tokens . add ( matchOne ) ; trivial = false ; } else if ( c == MatchSpace . SUBTOPIC_SEPARATOR_CHAR ) { // It's a normal character unless followed by another separator // or a "." if ( i == pattern . length ( ) - 1 ) { accum [ finger ++ ] = c ; } else { // Check to see if we have a double slash if ( pattern . charAt ( i + 1 ) == MatchSpace . SUBTOPIC_SEPARATOR_CHAR ) { // Double slash finger = flush ( accum , finger , tokens ) ; tokens . add ( matchMany ) ; trivial = false ; // Skip the second slash i ++ ; // If the next char is a '.', then we skip that too if ( pattern . charAt ( i + 1 ) == ' ' ) { // Skip the dot i ++ ; // Defect 307231, handle the allowable "//./" case if ( ( i + 1 ) < pattern . length ( ) && pattern . charAt ( i + 1 ) == MatchSpace . SUBTOPIC_SEPARATOR_CHAR ) { // Skip a subsequent slash i ++ ; } } } // Check for special "/." case which we jump over. Note that topic syntax // checking will already have disallowed invalid expressions such as "a/.b" // so if a "." follows a slash then it must be the final character, or it // must be followed by a separator. else if ( pattern . charAt ( i + 1 ) == ' ' ) { // skip the slash and the dot i ++ ; } else { accum [ finger ++ ] = c ; } } } else accum [ finger ++ ] = c ; } if ( trivial ) return new String ( accum , 0 , finger ) ; flush ( accum , finger , tokens ) ; return new TopicPattern ( tokens . iterator ( ) ) ; }
Parse a string topic pattern into a TopicPattern object