forked from titzer/virgil
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGlobMatcherDemo.v3
35 lines (29 loc) · 1.32 KB
/
GlobMatcherDemo.v3
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
// Copyright 2022 Ben L. Titzer. All rights reserved.
// See LICENSE for details of Apache 2.0 license.
def demo() {
// A {GlobMatcher} is a utility to match strings against patterns
// consisting of literal characters and the wildcards '?' and '*'.
var m = GlobMatcher.new("pattern");
if (m.matches("input")) System.puts("match1\n"); // false
if (m.matches("pat")) System.puts("match2\n"); // false
if (m.matches("pattern")) System.puts("match3\n"); // true
// The wildcard '?' matches any single character.
m = GlobMatcher.new("pat?ern");
if (m.matches("patxern")) System.puts("match4\n"); // true
if (m.matches("patkern")) System.puts("match5\n"); // true
if (m.matches("patern")) System.puts("match6\n"); // false
// The wildcard '*' matches zero or more characters.
m = GlobMatcher.new("pa*n");
if (m.matches("patxern")) System.puts("match7\n"); // true
if (m.matches("pan")) System.puts("match8\n"); // true
if (m.matches("patxer")) System.puts("match9\n"); // false
// The char '.' is a literal; it only matches a period.
m = GlobMatcher.new("pa.n");
if (m.matches("paxn")) System.puts("match10\n"); // false
if (m.matches("pa.n")) System.puts("match11\n"); // true
// Other patterns are not supported yet, e.g. {x,y} or [a-z];
// those characters are literals.
}
component GlobMatcherDemo {
def run = demo;
}