public void TestStringMatcher() { DfaState <int> dfa; { var builder = new DfaBuilder <int>(); builder.AddPattern(Pattern.Regex("a[ab]*b"), 1); builder.AddPattern(Pattern.Regex("a[ab]*c"), 2); dfa = builder.Build(null); } var matcher = new StringMatcher <int>("bbbbbaaaaaaaaaaaaaaaaaaaaaaaabbbbcaaaaaaabbbaaaaaaa"); var found = matcher.FindNext(dfa, out var result); Assert.True(found); Assert.Equal(2, result); Assert.Equal("aaaaaaaaaaaaaaaaaaaaaaaabbbbc", matcher.LastMatch); Assert.Equal(5, matcher.LastMatchStart); Assert.Equal(34, matcher.LastMatchEnd); found = matcher.FindNext(dfa, out result); Assert.True(found); Assert.Equal(1, result); Assert.Equal("aaaaaaabbb", matcher.LastMatch); found = matcher.FindNext(dfa, out result); Assert.False(found); Assert.Equal(0, result); matcher.SetPositions(15, 20, 33); Assert.Equal("aaaaa", matcher.LastMatch); matcher.FindNext(dfa, out result); Assert.Equal("aaaaaaaaabbbb", matcher.LastMatch); found = matcher.FindNext(dfa, out result); Assert.False(found); }
private int TimeMatcher(string src, string patString) { DfaState <bool> startState; { var builder = new DfaBuilder <bool>(); builder.AddPattern(Pattern.Regex(patString), true); startState = builder.Build(null); } var count = 0; var stopWatch = new Stopwatch(); stopWatch.Start(); for (var t = stopWatch.ElapsedMilliseconds; t < SpinUp + 1000; t = stopWatch.ElapsedMilliseconds) { var m = new StringMatcher <bool>(src); if (m.FindNext(startState, out _)) { throw new Exception("not supposed to find a match"); } if (t >= SpinUp) { ++count; } } return(count); }
public void Matcher() { var m = new StringMatcher <bool>(src); if (m.FindNext(startState, out _)) { throw new DfaException("not supposed to find a match"); } }