ref: 7967bd0a536faf789af27a559ea4aa21151d2eae
parent: da7d6df6faf18e289fe0f3f61524dcc7fddeef18
author: henesy <unknown>
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);