1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
|
/*************************************************************************
*
* HTCd - Copyright (C) 1998-2006 Henrik Rydberg
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <ops/operator.h>
#include <ops/nnstyle.h>
#include <mt/mset.h>
OP2_IMPL(intersect) { mset a(L),b(R),c; c.Intersection(a,b); out<<c; }
OP2_IMPL(union) { mset a(L),b(R),c; c.Union(a,b); out<<c; }
OP2_IMPL(difference) { mset a(L),b(R),c; c.Difference(a,b); out<<c; }
OP2_IMPL(concats) {
if(L.nempty()&&R.nempty()) out<<L<<" "<<R;
else if(L.nempty()) out<<L;
else out<<R;
}
OP1_IMPL(lcase) {mstring s=a;s.tolower();out<<s;}
OP1_IMPL(ucase) {mstring s=a;s.toupper();out<<s;}
OP1_IMPL(nncase) {out<<nncase(a);}
OP1_IMPL(skipws) {out<<a.right_first_not_of(cset_ws);}
OP2_IMPL(eqnn) {out<<(nncomp(L,R)==0);}
OP2_IMPL(nenn) {out<<(nncomp(L,R)!=0);}
OP1_IMPL(first) {out<<First(a);}
OP1_IMPL(last) {out<<Last(a);}
OP1_IMPL(rest) {out<<Rest(a);}
OP1_IMPL(count) {
sref first,rest=a; int n=0;
while(Split(first,rest)) n++;
out<<n;
}
OP2_IMPL(nth) {
sref first,rest=L; int n=atoi(R);
while(n-->0&&Split(first,rest));
out<<first;
}
OP2_IMPL(which) {
sref first,rest=L; int n=0;
while(Split(first,rest)) { n++; if(first==R) { out<<n; return; } }
out<<0;
}
OP2_IMPL(cnt) {out<<(L.find(R)>=0);}
OP2_IMPL(cntn) {out<<(L.find(R,cset_lcase)>=0);}
OP2_IMPL(concat) {out<<L<<R;}
OP2_IMPL(leftand) {out<<L.leftand_first(R);}
OP2_IMPL(left) {out<<L.left_first(R);}
OP2_IMPL(right) {out<<L.right_first(R);}
OP2_IMPL(past) {out<<L.past_first(R);}
OP2_IMPL(rleftand) {out<<L.leftand_last(R);}
OP2_IMPL(rleft) {out<<L.left_last(R);}
OP2_IMPL(rright) {out<<L.right_last(R);}
OP2_IMPL(rpast) {out<<L.past_last(R);}
void opAddString(opmap& M)
{
OP_ADD(32,lcase,
"Lower case\n"
"Syntax: lcase (string)\n"
"Returns: (string)\n"
);
OP_ADD(32,ucase,
"Upper case\n"
"Syntax: ucase (string)\n"
"Returns: (string)\n"
);
OP_ADD(32,nncase,
"NN-style case\n"
"Syntax: nncase (string)\n"
"Returns: (string)\n"
"\n"
"NN-style converts names to <lastname> <initials>\n"
);
OP_ADD(32,skipws,
"Skip whitespace\n"
"Syntax: skipws (string)\n"
"Returns: (string)\n"
"\n"
"Skips trailing whitespace\n"
);
OP_ADD(32,first,
"First element in list\n"
"Syntax: first (list)\n"
"Returns: (string)\n"
"\n"
"Elements are separated by whitespace\n"
);
OP_ADD(32,last,
"Last element in list\n"
"Syntax: last (list)\n"
"Returns: (string)\n"
"\n"
"Elements are separated by whitespace\n"
);
OP_ADD(32,rest,
"Rest of elements in list\n"
"Syntax: rest (list)\n"
"Returns: (list)\n"
"\n"
"Elements are separated by whitespace\n"
);
OP_ADD(32,count,
"Count elements in list\n"
"Syntax: count (list)\n"
"Returns: (int)\n"
"\n"
"Elements are separated by whitespace\n"
);
OP_ADD(30,nth,
"Nth element in list\n"
"Syntax: (list) nth (int)\n"
"Returns: (string)\n"
"\n"
"First element is denoted 1\n"
"Elements out of range returns empty\n"
"Elements are separated by whitespace\n"
);
OP_ADD(30,which,
"Which element in list\n"
"Syntax: (list) a which (string) b\n"
"Returns: (int)\n"
"\n"
"Which element in a is b (0 if not found)\n"
"First element is denoted 1\n"
"Elements are separated by whitespace\n"
);
OP_ADD(28,left,
"Left of substring\n"
"Syntax: (string) a left (string) b\n"
"Returns: (string)\n"
"\n"
"Everything in a to the left of first b, of a if b not found in a\n"
);
OP_ADD(28,leftand,
"Left of substring inclusive\n"
"Syntax: (string) a leftand (string) b\n"
"Returns: (string)\n"
"\n"
"Everything in a to the left of first b inclusive, of a if b not found in a\n"
);
OP_ADD(28,right,
"Right of substring inclusive\n"
"Syntax: (string) a right (string) b\n"
"Returns: (string)\n"
"\n"
"Everything in a to the right of first b inclusive, of empty if b not found in a\n"
);
OP_ADD(28,past,
"Right of substring\n"
"Syntax: (string) a past (string) b\n"
"Returns: (string)\n"
"\n"
"Everything in a to the right of first b, of empty if b not found in a\n"
);
OP_ADD(28,rleft,
"Left of substring (reversed)\n"
"Syntax: (string) a rleft (string) b\n"
"Returns: (string)\n"
"\n"
"Everything in a to the left of last b, of a if b not found in a\n"
);
OP_ADD(28,rleftand,
"Left of substring inclusive, (reversed)\n"
"Syntax: (string) a rleftand (string) b\n"
"Returns: (string)\n"
"\n"
"Everything in a to the left of last b inclusive, of a if b not found in a\n"
);
OP_ADD(28,rright,
"Right of substring inclusive (reversed)\n"
"Syntax: (string) a rright (string) b\n"
"Returns: (string)\n"
"\n"
"Everything in a to the right of last b inclusive, of empty if b not found in a\n"
);
OP_ADD(28,rpast,
"Right of substring (reversed)\n"
"Syntax: (string) a rpast (string) b\n"
"Returns: (string)\n"
"\n"
"Everything in a to the right of last b, of empty if b not found in a\n"
);
OP_ADDN(24,concat,++,
"String concatenation\n"
"Syntax: (string) ++ (string)\n"
"Returns: (string)\n"
);
OP_ADDN(24,concats,+++,
"List concatenation\n"
"Syntax: (list) +++ (list)\n"
"Returns: (list)\n"
"\n"
"Lists are concatenated with space\n"
);
OP_ADD(18,cnt,
"Contains substring\n"
"Syntax: (string) a cnt (string) b\n"
"Returns: (int)\n"
"\n"
"Nonzero if b found in a\n"
);
OP_ADD(18,cntn,
"Contains substring, case insensitive\n"
"Syntax: (string) a cnt (string) b\n"
"Returns: (int)\n"
"\n"
"Nonzero if b found in a\n"
);
OP_ADD(18,eqnn,
"NN-style equal\n"
"Syntax: (string) eqnn (string)\n"
"Returns: (int)\n"
"\n"
"NN-style converts names to <lastname> <initials>\n"
);
OP_ADD(18,nenn,
"NN-style not equal\n"
"Syntax: (string) eqnn (string)\n"
"Returns: (int)\n"
"\n"
"NN-style converts names to <lastname> <initials>\n"
);
OP_ADDN(10,intersect,&&&,
"List intersection\n"
"Syntax: (list) a &&& (list) b\n"
"Returns: (list)\n"
"\n"
"Finds the set intersection of a and b\n"
);
OP_ADDN(9,difference,---,
"List difference\n"
"Syntax: (list) a &&& (list) b\n"
"Returns: (list)\n"
"\n"
"Finds the set difference of a and b\n"
);
OP_ADDN(9,union,|||,
"List union\n"
"Syntax: (list) a &&& (list) b\n"
"Returns: (list)\n"
"\n"
"Finds the set union of a and b\n"
);
}
|