shithub: mc

Download patch

ref: 7aca27d405eca757282f872411df3083c8b55af2
parent: 97342365dc551b4ef0c07fe092f74abc8bf1b063
author: Ori Bernstein <[email protected]>
date: Wed Aug 7 13:15:34 EDT 2013

Fix naming, and shuffle args around a bit.

--- a/libstd/intparse.myr
+++ b/libstd/intparse.myr
@@ -8,18 +8,31 @@
 	generic intparse	: (s : byte[:]	-> @a::(tcint,tcnum,tctest))
 ;;
 
-generic parseint = {s
+generic intparse = {s
 	if hasprefix(s, "0x")
-		-> parsebase(s[2:], 16)
+		-> intparsebase(s[2:], 16)
 	elif hasprefix(s, "0o")
-		-> parsebase(s[2:], 8)
+		-> intparsebase(s[2:], 8)
 	elif hasprefix(s, "0b")
-		-> parsebase(s[2:], 2)
+		-> intparsebase(s[2:], 2)
 	else
-		-> parsebase(s[2:], 10)
+		-> intparsebase(s[2:], 10)
 	;;
 }
 
+generic intparsebase = {s, base -> @a::(tcint,tcnum,tctest)
+	var v : @a::(tcint,tcnum,tctest)
+	var c
+	
+	assert(base <= 36, "Base for parsing values is too big")
+	v = 0
+	while s.len != 0
+		(c, s) = striter(s)
+		v *= base castto(@a::(tcint,tcnum,tctest))
+		v += charval(c, base)
+	;;
+	-> v
+}
 
 generic charval = {c, base -> @a :: (tcint,tcnum,tctest)
 	var v = -1
@@ -37,24 +50,3 @@
 	;;
 	-> v
 }
-
-generic parsebase = {s, base -> @a::(tcint,tcnum,tctest)
-	var v : @a::(tcint,tcnum,tctest)
-	var c
-	
-	assert(base <= 36, "Base for parsing values is too big")
-	v = 0
-	while s.len != 0
-		(c, s) = striter(s)
-		v *= base castto(@a::(tcint,tcnum,tctest))
-		v += charval(c, base)
-	;;
-	-> v
-}
-
-const hasprefix = {s, pre
-	if strncmp(s, pre, pre.len) == `Equal
-		-> true
-	;;
-}
-
--- a/libstd/strcmp.myr
+++ b/libstd/strcmp.myr
@@ -6,6 +6,7 @@
 
 	const strcmp	: (a : byte[:], b : byte[:] -> comparison)
 	const strncmp	: (a : byte[:], b : byte[:], n : size -> comparison)
+	const hasprefix	: (a : byte[:], b : byte[:] -> bool)
 ;;
 
 type comparison = union
@@ -44,5 +45,11 @@
 	a = a[:min(a.len, n)]
 	b = b[:min(b.len, n)]
 	-> strcmp(a, b)
+}
+
+const hasprefix = {s, pre
+	if strncmp(s, pre, pre.len) == `Equal
+		-> true
+	;;
 }