code: purgatorio

Download patch

ref: 15e065df12bf7ad79000d150cefa5038ee7416b3
parent: 76f5318cbd58fbe2bfc8cb51856bfa217c673bb7
author: henesy <devnull@localhost>
date: Tue Jun 1 13:55:39 EDT 2021

string.m: add hasws and containscl

--- a/appl/lib/string.b
+++ b/appl/lib/string.b
@@ -3,6 +3,8 @@
 include "sys.m";
 include "string.m";
 
+wscl: con "\t\n\v\f\r\u0085\u00A0";
+
 splitl(s: string, cl: string): (string, string)
 {
 	n := len s;
@@ -41,6 +43,19 @@
 			return (s[0:j]);
 	}
 	return s;
+}
+
+# Does 's' contain whitespace?
+hasws(s: string): int {
+	return containscl(s, wscl);
+}
+
+# Does 's' contain any characters in class 'cl'
+containscl(s: string, cl: string): int {
+	for(i := 0; i < len s; i++)
+		if(in(s[i], cl))
+			return 1;
+	return 0;
 }
 
 in(c: int, s: string): int
--- a/module/string.m
+++ b/module/string.m
@@ -15,7 +15,8 @@
 	splitr:		fn(s, cl: string): (string, string);
 	drop:		fn(s, cl: string): string;
 	take:		fn(s, cl: string): string;
-	in:		fn(c: int, cl: string): int;
+	in:			fn(c: int, cl: string): int;
+	containscl:	fn(s, cl: string): int;
 
 	# in these, the second string is a string to match, not a class
 	splitstrl:	fn(s, t: string): (string, string);
@@ -28,6 +29,7 @@
 
 	tolower:	fn(s: string): string;
 	toupper:	fn(s: string): string;
+	hasws:		fn(s: string): int;
 
 	# string to int returning value, remainder
 	toint:		fn(s: string, base: int): (int, string);