|
From: Timothy J. H. <tim...@ma...> - 2004-06-06 23:27:32
|
I've modified string->number so that in the base 10 case it allows
leading zeroes...
The following Unit tests all pass in the current version of JScheme...
"06/06/2004" ;; literal syntax, TJH
;; Default literal syntax is for Java literals,
;; but string->number will treat leading zeroes as decimal if base 10
is specified
(equal? (.getClass '081) jsint.Symbol.class)
(equal? (.getClass '0123Dig) jsint.Symbol.class)
(equal? (.getClass '0123) java.lang.Integer.class)
(equal? (string->number "081" 10) 81)
(equal? (string->number "010") 10)
(equal? (string->number "010" 8) 8)
(equal? (tryCatch (string->number "081" 8) (lambda(e) 'error)) 'error)
(equal? (string->number "08") #f)
(equal? (string->number "08" 10) 8)
(equal? (string->number "10") 8)
(equal? (string->number "10" 10) 10)
The implementation of string->number in the base 10 case is
> public static Object schemeStringToNumber(String tok, int rdx) {
> try { return U.toNum(Long.parseLong(tok, rdx)); }
> catch (NumberFormatException e) {
> try {
> if (rdx!=10)
> return U.FALSE;
> else return new Double(tok); }
> catch (NumberFormatException e2)
> { return U.FALSE; }
> }
> }
>
---Tim---
|