shithub: mc

Download patch

ref: c4830c9459bd863aefd7966ea3b542b45d60560e
parent: dc52d457fd6efb778cb91a7912e5c1329d8c34ef
author: Ori Bernstein <[email protected]>
date: Sat Oct 19 10:55:14 EDT 2013

Add support for printing booleans

--- a/libstd/fmt.myr
+++ b/libstd/fmt.myr
@@ -11,6 +11,7 @@
   as described below:
 
 	  %s	- A string, ie, a utf8 encoded byte slice.
+	  %t	- A boolean
 	  %b	- A byte.
 	  %w	- A 16 bit integer
 	  %i	- A 32 bit integer
@@ -87,6 +88,7 @@
 	var c
 	var n
 	var s_val : byte[:]
+	var t_val : bool
 	var b_val : int8
 	var w_val : int16
 	var i_val : int32
@@ -105,6 +107,10 @@
 				(s_val, ap) = vanext(ap)
 				n += strfmt(buf[n:], s_val)
 				;;
+			't':
+				(t_val, ap) = vanext(ap)
+				n += boolfmt(buf[n:], t_val)
+				;;
 			/* format integers */
 			'b':
 				(b_val, ap) = vanext(ap)
@@ -152,6 +158,18 @@
 	;;
 	-> i
 }
+
+const boolfmt = {buf, val
+	var s
+
+	if val
+		s = "true"
+	else
+		s = "false"
+	;;
+	-> strfmt(buf, s)
+}
+
 
 const digitchars = [
 '0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f'