public NumberPattern parse ( String raw ) { this . buf . setLength ( 0 ) ; this . nodes = new ArrayList <> ( ) ; this . attached = false ; this . format = new Format ( ) ; // Length of the pattern. int length = raw . length ( ) ; // Position in the pattern. int i = 0 ; // Indicate we've seen a group separator and are "inside" a digit group. boolean inGroup = false ; // Indicate we're in the decimal portion of the format. boolean inDecimal = false ; while ( i < length ) { char ch = raw . charAt ( i ) ; switch ( ch ) { case ' ' : // Single-quote escaping of reserved characters. while ( i ++ < length ) { ch = raw . charAt ( i ) ; if ( ch == ' ' ) { break ; } buf . append ( ch ) ; } break ; case ' ' : pushText ( ) ; nodes . add ( NumberPattern . Symbol . MINUS ) ; break ; case ' ' : pushText ( ) ; nodes . add ( NumberPattern . Symbol . PERCENT ) ; break ; case ' ' : pushText ( ) ; nodes . add ( NumberPattern . Symbol . CURRENCY ) ; break ; case ' ' : // Optional digit placeholder. attach ( ) ; if ( inGroup ) { format . primaryGroupingSize ++ ; } else if ( inDecimal ) { format . maximumFractionDigits ++ ; } break ; case ' ' : // Digit grouping delimiter. attach ( ) ; if ( inGroup ) { format . secondaryGroupingSize = format . primaryGroupingSize ; format . primaryGroupingSize = 0 ; } else { inGroup = true ; } break ; case ' ' : // Decimal point character. inGroup = false ; attach ( ) ; inDecimal = true ; break ; case ' ' : // Required digit placeholder. If the number being formatted does not // contain a digit, a zero will be output. attach ( ) ; if ( inGroup ) { format . primaryGroupingSize ++ ; } else if ( inDecimal ) { format . minimumFractionDigits ++ ; format . maximumFractionDigits ++ ; } if ( ! inDecimal ) { format . minimumIntegerDigits ++ ; } break ; default : // Rest of characters are assumed to be static. buf . append ( ch ) ; break ; } i ++ ; } pushText ( ) ; return new NumberPattern ( raw , nodes , format ) ; }
Parse a number formatting pattern .