Debian Codegraph @

texmf-dist/metapost/base/string.mp

raw
1 % $Id: string.mp,v 1.2 2004/09/19 21:47:11 karl Exp $
2 % Public domain.
3
4 % String manipulation routines for MetaPost
5 % It is harmless to input this file more than once.
6
7
8 vardef isdigit primary d =
9 ("0"<=d)and(d<="9") enddef;
10
11
12 % Number of initial characters of string s where `c <character>' is true
13 vardef cspan(expr s)(text c) =
14 0
15 for i=1 upto length s:
16 exitunless c substring (i-1,i) of s;
17 + 1
18 endfor
19 enddef;
20
21
22 % String s is composed of items separated by white space. Lop off the first
23 % item and the surrounding white space and return just the item.
24 vardef loptok suffix s =
25 save t, k;
26 k = cspan(s," ">=);
27 if k>0: s:=substring(k,infinity) of s; fi
28 k := cspan(s," "<);
29 string t;
30 t = substring (0,k) of s;
31 s := substring (k,infinity) of s;
32 s := substring (cspan(s," ">=),infinity) of s;
33 t
34 enddef;