summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/metapost/base/string.mp
diff options
context:
space:
mode:
Diffstat (limited to 'Master/texmf-dist/metapost/base/string.mp')
-rw-r--r--Master/texmf-dist/metapost/base/string.mp31
1 files changed, 31 insertions, 0 deletions
diff --git a/Master/texmf-dist/metapost/base/string.mp b/Master/texmf-dist/metapost/base/string.mp
new file mode 100644
index 00000000000..2cf5a7ff4dd
--- /dev/null
+++ b/Master/texmf-dist/metapost/base/string.mp
@@ -0,0 +1,31 @@
+% String manipulation routines for MetaPost
+% It is harmless to input this file more than once.
+
+
+vardef isdigit primary d =
+ ("0"<=d)and(d<="9") enddef;
+
+
+% Number of initial characters of string s where `c <character>' is true
+vardef cspan(expr s)(text c) =
+ 0
+ for i=1 upto length s:
+ exitunless c substring (i-1,i) of s;
+ + 1
+ endfor
+enddef;
+
+
+% String s is composed of items separated by white space. Lop off the first
+% item and the surrounding white space and return just the item.
+vardef loptok suffix s =
+ save t, k;
+ k = cspan(s," ">=);
+ if k>0: s:=substring(k,infinity) of s; fi
+ k := cspan(s," "<);
+ string t;
+ t = substring (0,k) of s;
+ s := substring (k,infinity) of s;
+ s := substring (cspan(s," ">=),infinity) of s;
+ t
+enddef;