public static boolean parseCompoundID ( String id , int dir , StringBuffer canonID , List < SingleID > list , UnicodeSet [ ] globalFilter ) { int [ ] pos = new int [ ] { 0 } ; int [ ] withParens = new int [ 1 ] ; list . clear ( ) ; UnicodeSet filter ; globalFilter [ 0 ] = null ; canonID . setLength ( 0 ) ; // Parse leading global filter, if any withParens [ 0 ] = 0 ; // parens disallowed filter = parseGlobalFilter ( id , pos , dir , withParens , canonID ) ; if ( filter != null ) { if ( ! Utility . parseChar ( id , pos , ID_DELIM ) ) { // Not a global filter; backup and resume canonID . setLength ( 0 ) ; pos [ 0 ] = 0 ; } if ( dir == FORWARD ) { globalFilter [ 0 ] = filter ; } } boolean sawDelimiter = true ; for ( ; ; ) { SingleID single = parseSingleID ( id , pos , dir ) ; if ( single == null ) { break ; } if ( dir == FORWARD ) { list . add ( single ) ; } else { list . add ( 0 , single ) ; } if ( ! Utility . parseChar ( id , pos , ID_DELIM ) ) { sawDelimiter = false ; break ; } } if ( list . size ( ) == 0 ) { return false ; } // Construct canonical ID for ( int i = 0 ; i < list . size ( ) ; ++ i ) { SingleID single = list . get ( i ) ; canonID . append ( single . canonID ) ; if ( i != ( list . size ( ) - 1 ) ) { canonID . append ( ID_DELIM ) ; } } // Parse trailing global filter, if any, and only if we saw // a trailing delimiter after the IDs. if ( sawDelimiter ) { withParens [ 0 ] = 1 ; // parens required filter = parseGlobalFilter ( id , pos , dir , withParens , canonID ) ; if ( filter != null ) { // Don't require trailing ';', but parse it if present Utility . parseChar ( id , pos , ID_DELIM ) ; if ( dir == REVERSE ) { globalFilter [ 0 ] = filter ; } } } // Trailing unparsed text is a syntax error pos [ 0 ] = PatternProps . skipWhiteSpace ( id , pos [ 0 ] ) ; if ( pos [ 0 ] != id . length ( ) ) { return false ; } return true ; }
Parse a compound ID consisting of an optional forward global filter a separator one or more single IDs delimited by separators an an optional reverse global filter . The separator is a semicolon . The global filters are UnicodeSet patterns . The reverse global filter must be enclosed in parentheses .