699 * <p>The method does not take steps to guard against the
700 * {@code CharSequence} being mutated while parsing.
701 *
702 * @param s the {@code CharSequence} containing the {@code int}
703 * representation to be parsed
704 * @param beginIndex the beginning index, inclusive.
705 * @param endIndex the ending index, exclusive.
706 * @param radix the radix to be used while parsing {@code s}.
707 * @return the signed {@code int} represented by the subsequence in
708 * the specified radix.
709 * @throws NullPointerException if {@code s} is null.
710 * @throws IndexOutOfBoundsException if {@code beginIndex} is
711 * negative, or if {@code beginIndex} is greater than
712 * {@code endIndex} or if {@code endIndex} is greater than
713 * {@code s.length()}.
714 * @throws NumberFormatException if the {@code CharSequence} does not
715 * contain a parsable {@code int} in the specified
716 * {@code radix}, or if {@code radix} is either smaller than
717 * {@link java.lang.Character#MIN_RADIX} or larger than
718 * {@link java.lang.Character#MAX_RADIX}.
719 * @since 1.9
720 */
721 public static int parseInt(CharSequence s, int beginIndex, int endIndex, int radix)
722 throws NumberFormatException {
723 s = Objects.requireNonNull(s);
724
725 if (beginIndex < 0 || beginIndex > endIndex || endIndex > s.length()) {
726 throw new IndexOutOfBoundsException();
727 }
728 if (radix < Character.MIN_RADIX) {
729 throw new NumberFormatException("radix " + radix +
730 " less than Character.MIN_RADIX");
731 }
732 if (radix > Character.MAX_RADIX) {
733 throw new NumberFormatException("radix " + radix +
734 " greater than Character.MAX_RADIX");
735 }
736
737 boolean negative = false;
738 int i = beginIndex;
739 int limit = -Integer.MAX_VALUE;
882 * <p>The method does not take steps to guard against the
883 * {@code CharSequence} being mutated while parsing.
884 *
885 * @param s the {@code CharSequence} containing the unsigned
886 * {@code int} representation to be parsed
887 * @param beginIndex the beginning index, inclusive.
888 * @param endIndex the ending index, exclusive.
889 * @param radix the radix to be used while parsing {@code s}.
890 * @return the unsigned {@code int} represented by the subsequence in
891 * the specified radix.
892 * @throws NullPointerException if {@code s} is null.
893 * @throws IndexOutOfBoundsException if {@code beginIndex} is
894 * negative, or if {@code beginIndex} is greater than
895 * {@code endIndex} or if {@code endIndex} is greater than
896 * {@code s.length()}.
897 * @throws NumberFormatException if the {@code CharSequence} does not
898 * contain a parsable unsigned {@code int} in the specified
899 * {@code radix}, or if {@code radix} is either smaller than
900 * {@link java.lang.Character#MIN_RADIX} or larger than
901 * {@link java.lang.Character#MAX_RADIX}.
902 * @since 1.9
903 */
904 public static int parseUnsignedInt(CharSequence s, int beginIndex, int endIndex, int radix)
905 throws NumberFormatException {
906 s = Objects.requireNonNull(s);
907
908 if (beginIndex < 0 || beginIndex > endIndex || endIndex > s.length()) {
909 throw new IndexOutOfBoundsException();
910 }
911 int start = beginIndex, len = endIndex - beginIndex;
912
913 if (len > 0) {
914 char firstChar = s.charAt(start);
915 if (firstChar == '-') {
916 throw new
917 NumberFormatException(String.format("Illegal leading minus sign " +
918 "on unsigned string %s.", s));
919 } else {
920 if (len <= 5 || // Integer.MAX_VALUE in Character.MAX_RADIX is 6 digits
921 (radix == 10 && len <= 9)) { // Integer.MAX_VALUE in base 10 is 10 digits
922 return parseInt(s, start, start + len, radix);
|
699 * <p>The method does not take steps to guard against the
700 * {@code CharSequence} being mutated while parsing.
701 *
702 * @param s the {@code CharSequence} containing the {@code int}
703 * representation to be parsed
704 * @param beginIndex the beginning index, inclusive.
705 * @param endIndex the ending index, exclusive.
706 * @param radix the radix to be used while parsing {@code s}.
707 * @return the signed {@code int} represented by the subsequence in
708 * the specified radix.
709 * @throws NullPointerException if {@code s} is null.
710 * @throws IndexOutOfBoundsException if {@code beginIndex} is
711 * negative, or if {@code beginIndex} is greater than
712 * {@code endIndex} or if {@code endIndex} is greater than
713 * {@code s.length()}.
714 * @throws NumberFormatException if the {@code CharSequence} does not
715 * contain a parsable {@code int} in the specified
716 * {@code radix}, or if {@code radix} is either smaller than
717 * {@link java.lang.Character#MIN_RADIX} or larger than
718 * {@link java.lang.Character#MAX_RADIX}.
719 * @since 9
720 */
721 public static int parseInt(CharSequence s, int beginIndex, int endIndex, int radix)
722 throws NumberFormatException {
723 s = Objects.requireNonNull(s);
724
725 if (beginIndex < 0 || beginIndex > endIndex || endIndex > s.length()) {
726 throw new IndexOutOfBoundsException();
727 }
728 if (radix < Character.MIN_RADIX) {
729 throw new NumberFormatException("radix " + radix +
730 " less than Character.MIN_RADIX");
731 }
732 if (radix > Character.MAX_RADIX) {
733 throw new NumberFormatException("radix " + radix +
734 " greater than Character.MAX_RADIX");
735 }
736
737 boolean negative = false;
738 int i = beginIndex;
739 int limit = -Integer.MAX_VALUE;
882 * <p>The method does not take steps to guard against the
883 * {@code CharSequence} being mutated while parsing.
884 *
885 * @param s the {@code CharSequence} containing the unsigned
886 * {@code int} representation to be parsed
887 * @param beginIndex the beginning index, inclusive.
888 * @param endIndex the ending index, exclusive.
889 * @param radix the radix to be used while parsing {@code s}.
890 * @return the unsigned {@code int} represented by the subsequence in
891 * the specified radix.
892 * @throws NullPointerException if {@code s} is null.
893 * @throws IndexOutOfBoundsException if {@code beginIndex} is
894 * negative, or if {@code beginIndex} is greater than
895 * {@code endIndex} or if {@code endIndex} is greater than
896 * {@code s.length()}.
897 * @throws NumberFormatException if the {@code CharSequence} does not
898 * contain a parsable unsigned {@code int} in the specified
899 * {@code radix}, or if {@code radix} is either smaller than
900 * {@link java.lang.Character#MIN_RADIX} or larger than
901 * {@link java.lang.Character#MAX_RADIX}.
902 * @since 9
903 */
904 public static int parseUnsignedInt(CharSequence s, int beginIndex, int endIndex, int radix)
905 throws NumberFormatException {
906 s = Objects.requireNonNull(s);
907
908 if (beginIndex < 0 || beginIndex > endIndex || endIndex > s.length()) {
909 throw new IndexOutOfBoundsException();
910 }
911 int start = beginIndex, len = endIndex - beginIndex;
912
913 if (len > 0) {
914 char firstChar = s.charAt(start);
915 if (firstChar == '-') {
916 throw new
917 NumberFormatException(String.format("Illegal leading minus sign " +
918 "on unsigned string %s.", s));
919 } else {
920 if (len <= 5 || // Integer.MAX_VALUE in Character.MAX_RADIX is 6 digits
921 (radix == 10 && len <= 9)) { // Integer.MAX_VALUE in base 10 is 10 digits
922 return parseInt(s, start, start + len, radix);
|