private NFSubstitution extractSubstitution ( NFRuleSet owner , NFRule predecessor ) { NFSubstitution result ; int subStart ; int subEnd ; // search the rule's rule text for the first two characters of // a substitution token subStart = indexOfAnyRulePrefix ( ruleText ) ; // if we didn't find one, create a null substitution positioned // at the end of the rule text if ( subStart == - 1 ) { return null ; } // special-case the ">>>" token, since searching for the > at the // end will actually find the > in the middle if ( ruleText . startsWith ( ">>>" , subStart ) ) { subEnd = subStart + 2 ; } else { // otherwise the substitution token ends with the same character // it began with char c = ruleText . charAt ( subStart ) ; subEnd = ruleText . indexOf ( c , subStart + 1 ) ; // special case for '<%foo<<' if ( c == ' ' && subEnd != - 1 && subEnd < ruleText . length ( ) - 1 && ruleText . charAt ( subEnd + 1 ) == c ) { // ordinals use "=#,##0==%abbrev=" as their rule. Notice that the '==' in the middle // occurs because of the juxtaposition of two different rules. The check for '<' is a hack // to get around this. Having the duplicate at the front would cause problems with // rules like "<<%" to format, say, percents... ++ subEnd ; } } // if we don't find the end of the token (i.e., if we're on a single, // unmatched token character), create a null substitution positioned // at the end of the rule if ( subEnd == - 1 ) { return null ; } // if we get here, we have a real substitution token (or at least // some text bounded by substitution token characters). Use // makeSubstitution() to create the right kind of substitution result = NFSubstitution . makeSubstitution ( subStart , this , predecessor , owner , this . formatter , ruleText . substring ( subStart , subEnd + 1 ) ) ; // remove the substitution from the rule text ruleText = ruleText . substring ( 0 , subStart ) + ruleText . substring ( subEnd + 1 ) ; return result ; }
Searches the rule s rule text for the first substitution token creates a substitution based on it and removes the token from the rule s rule text .