@Test public void testAnySingle(){ Matcher matcher = new Matcher("."); assertFalse(matcher.match("")); assertFalse(matcher.match("ab")); assertTrue(matcher.match("a")); assertTrue(matcher.match("b")); assertTrue(matcher.match(".")); }
public boolean match(String txt) { Objects.requireNonNull(txt); int acceptanceState = regex.length(); Set<Integer> vertices = nfsm.findConnected(0); for (int i = 0; i < txt.length(); i++) { char current = txt.charAt(i); if (current == '*' || current == '|' || current == '(' || current == ')') { throw new IllegalArgumentException("text contains the metacharacter '" + txt.charAt(i) + "'"); } Set<Integer> match = new HashSet<>(); for (int v : vertices) { if (v == acceptanceState) { continue; } if ((regex.charAt(v) == txt.charAt(i)) || regex.charAt(v) == '.') { match.add(v + 1); } } if(match.isEmpty()){ return false; } vertices = nfsm.findConnected(match); } return vertices.contains(acceptanceState); }
Matcher { public boolean match(String txt) { Objects.requireNonNull(txt); int acceptanceState = regex.length(); Set<Integer> vertices = nfsm.findConnected(0); for (int i = 0; i < txt.length(); i++) { char current = txt.charAt(i); if (current == '*' || current == '|' || current == '(' || current == ')') { throw new IllegalArgumentException("text contains the metacharacter '" + txt.charAt(i) + "'"); } Set<Integer> match = new HashSet<>(); for (int v : vertices) { if (v == acceptanceState) { continue; } if ((regex.charAt(v) == txt.charAt(i)) || regex.charAt(v) == '.') { match.add(v + 1); } } if(match.isEmpty()){ return false; } vertices = nfsm.findConnected(match); } return vertices.contains(acceptanceState); } }
Matcher { public boolean match(String txt) { Objects.requireNonNull(txt); int acceptanceState = regex.length(); Set<Integer> vertices = nfsm.findConnected(0); for (int i = 0; i < txt.length(); i++) { char current = txt.charAt(i); if (current == '*' || current == '|' || current == '(' || current == ')') { throw new IllegalArgumentException("text contains the metacharacter '" + txt.charAt(i) + "'"); } Set<Integer> match = new HashSet<>(); for (int v : vertices) { if (v == acceptanceState) { continue; } if ((regex.charAt(v) == txt.charAt(i)) || regex.charAt(v) == '.') { match.add(v + 1); } } if(match.isEmpty()){ return false; } vertices = nfsm.findConnected(match); } return vertices.contains(acceptanceState); } Matcher(String regex); }
Matcher { public boolean match(String txt) { Objects.requireNonNull(txt); int acceptanceState = regex.length(); Set<Integer> vertices = nfsm.findConnected(0); for (int i = 0; i < txt.length(); i++) { char current = txt.charAt(i); if (current == '*' || current == '|' || current == '(' || current == ')') { throw new IllegalArgumentException("text contains the metacharacter '" + txt.charAt(i) + "'"); } Set<Integer> match = new HashSet<>(); for (int v : vertices) { if (v == acceptanceState) { continue; } if ((regex.charAt(v) == txt.charAt(i)) || regex.charAt(v) == '.') { match.add(v + 1); } } if(match.isEmpty()){ return false; } vertices = nfsm.findConnected(match); } return vertices.contains(acceptanceState); } Matcher(String regex); boolean match(String txt); }
Matcher { public boolean match(String txt) { Objects.requireNonNull(txt); int acceptanceState = regex.length(); Set<Integer> vertices = nfsm.findConnected(0); for (int i = 0; i < txt.length(); i++) { char current = txt.charAt(i); if (current == '*' || current == '|' || current == '(' || current == ')') { throw new IllegalArgumentException("text contains the metacharacter '" + txt.charAt(i) + "'"); } Set<Integer> match = new HashSet<>(); for (int v : vertices) { if (v == acceptanceState) { continue; } if ((regex.charAt(v) == txt.charAt(i)) || regex.charAt(v) == '.') { match.add(v + 1); } } if(match.isEmpty()){ return false; } vertices = nfsm.findConnected(match); } return vertices.contains(acceptanceState); } Matcher(String regex); boolean match(String txt);  }