private static int parseArgNumber ( CharSequence s , int start , int limit ) { // If the identifier contains only ASCII digits, then it is an argument _number_ // and must not have leading zeros (except "0" itself). // Otherwise it is an argument _name_. if ( start >= limit ) { return ARG_NAME_NOT_VALID ; } int number ; // Defer numeric errors until we know there are only digits. boolean badNumber ; char c = s . charAt ( start ++ ) ; if ( c == ' ' ) { if ( start == limit ) { return 0 ; } else { number = 0 ; badNumber = true ; // leading zero } } else if ( ' ' <= c && c <= ' ' ) { number = c - ' ' ; badNumber = false ; } else { return ARG_NAME_NOT_NUMBER ; } while ( start < limit ) { c = s . charAt ( start ++ ) ; if ( ' ' <= c && c <= ' ' ) { if ( number >= Integer . MAX_VALUE / 10 ) { badNumber = true ; // overflow } number = number * 10 + ( c - ' ' ) ; } else { return ARG_NAME_NOT_NUMBER ; } } // There are only ASCII digits. if ( badNumber ) { return ARG_NAME_NOT_VALID ; } else { return number ; } }
Validates and parses an argument name or argument number string . This internal method assumes that the input substring is a pattern identifier .