changeset 259:32964a4e7a33

Add ltrim method to string
author Michael Pavone <pavone@retrodev.com>
date Thu, 29 May 2014 18:51:15 -0700
parents fb922651db29
children 56409de95f55
files modules/string.tp samples/stringops.tp
diffstat 2 files changed, 20 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/modules/string.tp	Wed May 28 09:48:09 2014 -0700
+++ b/modules/string.tp	Thu May 29 18:51:15 2014 -0700
@@ -257,6 +257,25 @@
 		pieces append: self
 	}
 
+	ltrim <- {
+		l <- length
+		start <- 0
+		space <- " " byte: 0
+		tab <- "\t" byte: 0
+		nl <- "\n" byte: 0
+		cr <- "\r" byte: 0
+
+		while: {
+			if: start < l {
+				b <- byte: start
+				b = space || b = tab || b = nl || b = cr
+			}
+		} do: {
+			start <- start + 1
+		}
+		from: start
+	}
+
 	trim <- {
 		l <- length
 		start <- 0
--- a/samples/stringops.tp	Wed May 28 09:48:09 2014 -0700
+++ b/samples/stringops.tp	Thu May 29 18:51:15 2014 -0700
@@ -20,5 +20,6 @@
 
 		print: (string: ("12abcDEF" parseHex32)) . "\n"
 		print: (string: ("FFFFFFFFFF" parseHex64)) . "\n"
+		print: "'" . (" 	\nfoobar baz  " ltrim) . "'\n"
 	}
 }