1 package io.github.reggert.reb4j.charclass;
2
3 import static fj.Ord.charOrd;
4
5 import io.github.reggert.reb4j.AbstractQuantifiableSequenceableAlternative;
6 import io.github.reggert.reb4j.Alternative;
7 import io.github.reggert.reb4j.Expression;
8 import io.github.reggert.reb4j.Quantifiable;
9 import io.github.reggert.reb4j.Sequenceable;
10
11 import java.lang.Character.UnicodeBlock;
12
13
14 import fj.data.LazyString;
15 import fj.data.Set;
16
17
18
19
20
21 public abstract class CharClass extends AbstractQuantifiableSequenceableAlternative
22 implements Expression, Quantifiable, Sequenceable, Alternative
23 {
24 private static final long serialVersionUID = 1L;
25
26
27
28
29
30 protected abstract LazyString unitableForm();
31
32
33
34
35
36 protected abstract LazyString independentForm();
37
38 @Override
39 public final LazyString expression()
40 {return independentForm();}
41
42 @Override
43 public Integer boundedLength()
44 {
45 return 1;
46 }
47
48 @Override
49 public boolean repetitionInvalidatesBounds()
50 {
51 return false;
52 }
53
54 @Override
55 public boolean possiblyZeroLength()
56 {
57 return false;
58 }
59
60
61
62
63
64 public abstract CharClass negated();
65
66
67
68
69
70 public Union union(final Union right)
71 {return Union.union(this, right);}
72
73
74
75
76
77 public Union union(final CharClass right)
78 {return Union.union(this, right);}
79
80
81
82
83
84 public Intersection intersect(final CharClass right)
85 {return Intersection.intersect(this, right);}
86
87
88
89
90
91 public Intersection intersect(final Intersection right)
92 {return Intersection.intersect(this, right);}
93
94
95
96
97 public static SingleChar character(final char c)
98 {return new SingleChar(c);}
99
100
101
102
103 public static MultiChar characters(final char c1, final char c2, final char... cs)
104 {
105 Set<Character> set = Set.set(charOrd, c1, c2);
106 for (final char c : cs)
107 set = set.insert(c);
108 return new MultiChar(set);
109 }
110
111
112
113
114
115
116
117
118
119
120
121
122 public static CharRange range(final char first, final char last)
123 {return new CharRange(first, last);}
124
125
126
127
128 public static abstract class Perl
129 {
130 private Perl() {}
131
132
133
134
135 public static final PredefinedClass DIGIT = new PredefinedClass('d');
136
137
138
139
140 public static final PredefinedClass SPACE = new PredefinedClass('s');
141
142
143
144
145 public static final PredefinedClass WORD = new PredefinedClass('w');
146 }
147
148
149
150
151 public static abstract class Posix
152 {
153 private Posix() {}
154
155
156
157
158 public static final NamedPredefinedClass LOWER = new NamedPredefinedClass("Lower");
159
160
161
162
163 public static final NamedPredefinedClass UPPER = new NamedPredefinedClass("Upper");
164
165
166
167
168 public static final NamedPredefinedClass ALPHA = new NamedPredefinedClass("Alpha");
169
170
171
172
173 public static final NamedPredefinedClass DIGIT = new NamedPredefinedClass("Digit");
174
175
176
177
178 public static final NamedPredefinedClass ALNUM = new NamedPredefinedClass("Alnum");
179
180
181
182
183 public static final NamedPredefinedClass PUNCT = new NamedPredefinedClass("Punct");
184
185
186
187
188 public static final NamedPredefinedClass GRAPH = new NamedPredefinedClass("Graph");
189
190
191
192
193 public static final NamedPredefinedClass PRINT = new NamedPredefinedClass("Print");
194
195
196
197
198 public static final NamedPredefinedClass BLANK = new NamedPredefinedClass("Blank");
199
200
201
202
203 public static final NamedPredefinedClass CONTROL = new NamedPredefinedClass("Cntrl");
204
205
206
207
208 public static final NamedPredefinedClass HEX_DIGIT = new NamedPredefinedClass("XDigit");
209
210
211
212
213 public static final NamedPredefinedClass SPACE = new NamedPredefinedClass("Space");
214 }
215
216
217
218
219
220 public static abstract class Java
221 {
222 private Java() {}
223
224
225
226
227 public static final NamedPredefinedClass LOWER_CASE = new NamedPredefinedClass("javaLowerCase");
228
229
230
231
232 public static final NamedPredefinedClass UPPER_CASE = new NamedPredefinedClass("javaUpperCase");
233
234
235
236
237 public static final NamedPredefinedClass WHITESPACE = new NamedPredefinedClass("javaWhitespace");
238
239
240
241
242 public static final NamedPredefinedClass MIRROR = new NamedPredefinedClass("javaMirrored");
243 }
244
245
246
247
248
249 public static abstract class Unicode
250 {
251 private Unicode() {}
252 private static NamedPredefinedClass z (final String className)
253 {return new NamedPredefinedClass(className);}
254
255
256
257
258
259 public static NamedPredefinedClass block(final UnicodeBlock unicodeBlock)
260 {return z("In" + unicodeBlock.toString());}
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300 public static abstract class Letter
301 {
302 private Letter() {}
303
304
305
306
307 public static final NamedPredefinedClass UPPER_CASE = z("Lu");
308
309
310
311
312 public static final NamedPredefinedClass LOWER_CASE = z("Ll");
313
314
315
316
317 public static final NamedPredefinedClass TITLE_CASE = z("Lt");
318
319
320
321
322 public static final NamedPredefinedClass MODIFIER = z("Lm");
323
324
325
326
327 public static final NamedPredefinedClass OTHER = z("Lo");
328 }
329
330
331
332
333
334 public static abstract class Mark
335 {
336 private Mark() {}
337
338
339
340
341 public static final NamedPredefinedClass NONSPACING = z("Mn");
342
343
344
345
346 public static final NamedPredefinedClass SPACING_COMBINING = z("Mc");
347
348
349
350
351 public static final NamedPredefinedClass ENCLOSING = z("Me");
352 }
353
354
355
356
357
358 public static abstract class Number
359 {
360 private Number() {}
361
362
363
364
365 public static final NamedPredefinedClass DECIMAL_DIGIT = z("Nd");
366
367
368
369
370 public static final NamedPredefinedClass LETTER = z("Nl");
371
372
373
374
375 public static final NamedPredefinedClass OTHER = z("No");
376 }
377
378
379
380
381
382 public static abstract class Separator
383 {
384 private Separator() {}
385
386
387
388
389 public static final NamedPredefinedClass SPACE = z("Zs");
390
391
392
393
394 public static final NamedPredefinedClass LINE = z("Zl");
395
396
397
398
399 public static final NamedPredefinedClass PARAGRAPH = z("Zp");
400 }
401
402
403
404
405
406
407 public static abstract class Other
408 {
409 private Other() {}
410
411
412
413
414 public static final NamedPredefinedClass CONTROL = z("Cc");
415
416
417
418
419 public static final NamedPredefinedClass FORMAT = z("Cf");
420
421
422
423
424 public static final NamedPredefinedClass SURROGATE = z("Cs");
425
426
427
428
429 public static final NamedPredefinedClass PRIVATE_USE = z("Co");
430
431
432
433
434 public static final NamedPredefinedClass NOT_ASSIGNED = z("Cn");
435 }
436
437
438
439
440
441
442 public static abstract class Punctuation
443 {
444
445
446
447 public static final NamedPredefinedClass CONNECTOR = z("Pc");
448
449
450
451
452 public static final NamedPredefinedClass DASH = z("Pd");
453
454
455
456
457 public static final NamedPredefinedClass OPEN = z("Po");
458
459
460
461
462 public static final NamedPredefinedClass CLOSE = z("Pe");
463
464
465
466
467 public static final NamedPredefinedClass INITIAL_QUOTE = z("Pi");
468
469
470
471
472 public static final NamedPredefinedClass FINAL_QUOTE = z("Pf");
473
474
475
476
477 public static final NamedPredefinedClass OTHER = z("Po");
478 }
479
480
481
482
483
484
485 public static abstract class Symbol
486 {
487
488
489
490 public static final NamedPredefinedClass MATH = z("Sm");
491
492
493
494
495 public static final NamedPredefinedClass CURRENCY = z("Sc");
496
497
498
499
500 public static final NamedPredefinedClass MODIFIER = z("Sk");
501
502
503
504
505 public static final NamedPredefinedClass OTHER = z("So");
506 }
507 }
508 }