diff modules/string.tp @ 157:55e0dca7d3d7

Partial implementation of HTTP get requests
author Mike Pavone <pavone@retrodev.com>
date Sat, 10 Aug 2013 15:06:56 -0700
parents 6e579a75a0a9
children 38140b7dbe3d
line wrap: on
line diff
--- a/modules/string.tp	Sat Aug 10 14:50:38 2013 -0700
+++ b/modules/string.tp	Sat Aug 10 15:06:56 2013 -0700
@@ -187,6 +187,34 @@
 		pieces append: self
 	}
 
+	trim <- {
+		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
+		}
+		end <- l
+		while: {
+			if: end > 0 {
+				b <- byte: end
+				b = space || b = tab || b = nl || b = cr
+			}
+		} do: {
+			end <- end + 1
+		}
+		from: start withLength: (end - start)
+	}
+
 	isInteger? <- { false }
 	isString? <- { true }
 }