[MLton] Bug in LargeInt.scan

Wesley W. Terpstra wesley@terpstra.ca
Mon, 15 Aug 2005 14:30:12 +0200


--Apple-Mail-1--227075388
Content-Transfer-Encoding: 7bit
Content-Type: text/plain;
	charset=US-ASCII;
	format=flowed

Although normal integers skip '0x' and '0X' for HEX, LargeInt doesn't.
Patch attached.


--Apple-Mail-1--227075388
Content-Transfer-Encoding: 7bit
Content-Type: application/octet-stream;
	x-unix-mode=0644;
	name="hex-fix.patch"
Content-Disposition: attachment;
	filename=hex-fix.patch

Index: basis-library/integer/int-inf.sml
===================================================================
--- basis-library/integer/int-inf.sml	(revision 3974)
+++ basis-library/integer/int-inf.sml	(working copy)
@@ -735,6 +735,20 @@
 	    in reader
 	    end
 	 
+	 (* Given a char reader and an unsigned reader, return an unsigned
+	  * reader. This includes skipping the option hex '0x'. *)
+	 fun toHexR (cread: (char, 'a) reader, uread: (bigInt, 'a) reader) 
+	    state =
+	    case cread state of
+		NONE => NONE
+	      | SOME (#"0", state') =>
+		(case cread state' of
+		     NONE => uread state
+		   | SOME (#"x", state'') => uread state''
+		   | SOME (#"X", state'') => uread state''
+		   | SOME _ => uread state)
+	      | SOME _ => uread state
+
 	 (*
 	  * Given a char reader and an unsigned reader, return a signed
 	  * reader.  This includes skipping any initial white space.
@@ -778,7 +792,9 @@
 	       let val dread = toDigR (dig, cread)
 		  val ckread = toChunkR (base, dpc, dread)
 		  val uread = toUnsR ckread
-		  val reader = toSign (cread, uread)
+		  val hread = if base <> 0wx10 then uread else
+			      toHexR (cread, uread)
+		  val reader = toSign (cread, hread)
 	       in reader
 	       end
 	 in

--Apple-Mail-1--227075388--