File tree Expand file tree Collapse file tree 1 file changed +7
-16
lines changed Expand file tree Collapse file tree 1 file changed +7
-16
lines changed Original file line number Diff line number Diff line change @@ -79,9 +79,13 @@ object FromDigits {
7979 }
8080 if (i == len) throw MalformedNumber ()
8181 while (i < len) {
82- val c = digits(i)
83- val d = digit2int(c, radix)
84- if (d < 0 ) throw MalformedNumber ()
82+ val ch = digits(i)
83+ val d =
84+ if (ch <= '9' ) ch - '0'
85+ else if ('a' <= ch && ch <= 'z' ) ch - 'a' + 10
86+ else if ('A' <= ch && ch <= 'Z' ) ch - 'A' + 10
87+ else - 1
88+ if (d < 0 || radix <= d) throw MalformedNumber ()
8589 if (value < 0 ||
8690 limit / (radix / divider) < value ||
8791 limit - (d / divider) < value * (radix / divider) &&
@@ -92,19 +96,6 @@ object FromDigits {
9296 if (negated) - value else value
9397 }
9498
95- /** Convert a character digit to an Int according to given base,
96- * -1 if no success
97- */
98- private def digit2int (ch : Char , base : Int ): Int = {
99- val num = (
100- if (ch <= '9' ) ch - '0'
101- else if ('a' <= ch && ch <= 'z' ) ch - 'a' + 10
102- else if ('A' <= ch && ch <= 'Z' ) ch - 'A' + 10
103- else - 1
104- )
105- if (0 <= num && num < base) num else - 1
106- }
107-
10899 /** Convert digit string to Int number
109100 * @param digits The string to convert
110101 * @param radix The radix
You can’t perform that action at this time.
0 commit comments