コード例 #1
0
        //Copies the contents of one directory to another.
        public static void CopyDirectoryFiltered(string source, string target, bool overwrite,
                                                 string regExExcludeFilter, bool recursive)
        {
            RegexMatcher excluder = new RegexMatcher()
            {
                exclude = null
            };

            try
            {
                if (regExExcludeFilter != null)
                {
                    excluder.exclude = new Regex(regExExcludeFilter);
                }
            }
            catch (ArgumentException)
            {
                UnityEngine.Debug.Log("CopyDirectoryRecursive: Pattern '" + regExExcludeFilter +
                                      "' is not a correct Regular Expression. Not excluding any files.");

                return;
            }

            CopyDirectoryFiltered(source, target, overwrite, excluder.CheckInclude, recursive);
        }
コード例 #2
0
 public bool MatchSimpleTest(string text)
 {
     using (var rm = new RegexMatcher("(a|b)*c"))
     {
         return(rm.Matches(text));
     }
 }
コード例 #3
0
        void TestSerialization_comprehensive_(RegexOptions options)
        {
            var regexesFile = "../../../../Automata.Tests/Samples/matcher_test_set.txt";
            var regexes     = Array.ConvertAll(File.ReadAllLines(regexesFile), x => new Regex(x, options));
            int k           = regexes.Length;

            for (int i = 0; i < k; i++)
            {
                var          regex = regexes[i];
                RegexMatcher matcher;
                string       reasonwhyfailed;
                if (regex.TryCompile(out matcher, out reasonwhyfailed))
                {
                    matcher.Serialize("tmp.bin");
                    var matcher_ = RegexMatcher.Deserialize("tmp.bin");
                    var input    = matcher.GenerateRandomMatch();
                    var matches  = matcher.Matches(input);
                    var matches_ = matcher_.Matches(input);
                    Assert.IsTrue(matches_.Length == matches.Length);
                    Assert.AreEqual(matches[0], matches_[0]);
                }
                else
                {
                    Assert.Fail("Regex compilation failed: " + reasonwhyfailed);
                }
            }
        }
コード例 #4
0
        public void MatchesBothUrlAndBody()
        {
            var matcher = new RegexMatcher("abcde");

            Assert.True(matcher.Matches(new PathString("/foo/bar/ae/fx/"), new QueryString(), "content in body: abcde", null));
            Assert.True(matcher.Matches(new PathString("/foo/bar/abcde/fx/"), new QueryString(), "", null));
        }
コード例 #5
0
        public void IterationSetup()
        {
            var patternBuilder = new StringBuilder(new Bogus.Randomizer().AlphaNumeric(StringLength));

            var random = new Random();

            var singleCharacterLocations = Enumerable.Range(0, SingleCharacterMatchCount)
                                           .Select(x => random.Next(SingleCharacterStart, SingleCharacterEnd))
                                           .ToList();

            singleCharacterLocations.ForEach(x => patternBuilder[x] = '?');

            var multiCharacterLocations = Enumerable.Range(0, MultiCharacterMatchCount)
                                          .Select(x => random.Next(MultiCharacterStart, MultiCharacterEnd))
                                          .ToList();

            multiCharacterLocations.ForEach(x => patternBuilder[x] = '*');

            _pattern = patternBuilder.ToString();

            _fastWildcardMatcher  = new FastWildcardMatcher();
            _regexMatcher         = new RegexMatcher(_pattern, RegexOptions.None);
            _regexMatcherCompiled = new RegexMatcher(_pattern, RegexOptions.Compiled);
#if !NETCOREAPP
            _wildcardMatchMatcher = new WildcardMatchMatcher();
#endif

            _str = new Bogus.Randomizer().AlphaNumeric(StringLength);
        }
コード例 #6
0
        public void SetupContext()
        {
            var matcher = new RegexMatcher("^Some fake method name", typeof(RegexTestContext).GetMethod("MethodWithReturnValue"));

            TestText  = "Some fake method name";
            TestMatch = matcher.GetMatch(TestText);
        }
コード例 #7
0
        public void DigitsRegexMatcher()
        {
            var re = new RegexMatcher("\\d{3,}", 10);

            var res = re.MatchPassword("abc123def");

            Assert.AreEqual(1, res.Count());
            var m1 = res.First();

            Assert.AreEqual(3, m1.Begin);
            Assert.AreEqual(5, m1.End);
            Assert.AreEqual("123", m1.Token);

            res = re.MatchPassword("123456789a12345b1234567");
            Assert.AreEqual(3, res.Count());
            var m3 = res.ElementAt(2);

            Assert.AreEqual("1234567", m3.Token);

            res = re.MatchPassword("12");
            Assert.AreEqual(0, res.Count());

            res = re.MatchPassword("dfsdfdfhgjkdfngjl");
            Assert.AreEqual(0, res.Count());
        }
コード例 #8
0
 public bool MatchAdvancedTest(string text, string regexp)
 {
     using (var rm = new RegexMatcher(regexp))
     {
         return(rm.Matches(text));
     }
 }
コード例 #9
0
        public void SetupContext()
        {
            var matcher = new RegexMatcher("^Some fake method name (.+)",
                                           typeof(RegexTestContext).GetMethod("MethodWithParams"));

            TestText  = "Some fake method name and some other text";
            TestMatch = matcher.GetMatch(TestText);
        }
コード例 #10
0
 public void TestRegexMatcher()
 {
     Assert.IsFalse(RegexMatcher.IsMatch("ab01"));
     Assert.IsTrue(RegexMatcher.IsMatch("01ab"));
     Assert.IsFalse(RegexMatcher.IsMatch("0881abc"));
     Assert.IsTrue(RegexMatcher.IsMatch("0881ac"));
     Assert.IsFalse(RegexMatcher.IsMatch("013333a."));
 }
コード例 #11
0
        private string DescribeParameter(RegexMatcher matcher, int currentParam)
        {
            string s;
            var    param = ((MethodInfo)matcher.MemberInfo).GetParameters().ElementAt(currentParam);

            s = _parameterDescriber.DescribeParameter(param.ParameterType, param.Name);
            return(s);
        }
コード例 #12
0
        void SerializeAndPrintStats(RegexMatcher matcher, string info)
        {
            var t = System.Environment.TickCount;

            matcher.Serialize("test.soap", new SoapFormatter());
            t = System.Environment.TickCount - t;
            Console.WriteLine("{1} serializaton time={0}ms", t, info);
        }
コード例 #13
0
 public bool MatchWithCommentsAndSpace(string text)
 {
     using (var rm = new RegexMatcher("(?# space is ignored )(a | b)* c",
                                      RegexMatcher.URegexpFlag.COMMENTS))
     {
         return(rm.Matches(text));
     }
 }
コード例 #14
0
        /// <summary>
        /// Document Title
        /// </summary>
        /// <param name="Title">Title</param>
        /// <returns>ReportConfig object</returns>
        public ReportConfig DocumentTitle(string Title)
        {
            string docTitle = "<title>.*</title>";

            report.UpdateSource(report.Source.Replace(RegexMatcher.GetNthMatch(report.Source, docTitle, 0), docTitle.Replace(".*", Title)));

            return(this);
        }
コード例 #15
0
        public void RegexToStringWithHttpMethods()
        {
            var matcher = new RegexMatcher("foobar");

            matcher.SetMatchingHttpMethods("get post");

            Assert.Equal("Regex 'foobar' (GET,POST)", matcher.ToString());
        }
コード例 #16
0
        RegexMatcher DeserializeAndPrintStats(string info)
        {
            var t  = System.Environment.TickCount;
            var rm = RegexMatcher.Deserialize("test.soap", new SoapFormatter());

            t = System.Environment.TickCount - t;
            Console.WriteLine("{1} deserializaton time={0}ms", t, info);
            return(rm);
        }
コード例 #17
0
ファイル: Extensions.cs プロジェクト: JasonKoopmans/StringMix
        /// <summary>
        /// Given a list of tokens and a regex pattern, return a matchset using the RegExMatcher class
        /// </summary>
        /// <param name="tokens">
        /// A list of tokens that would come out of a call to .Tokenize()
        /// </param>
        /// <param name="RegExPattern">
        /// Just a string, but should represent a valid RegEx.  This expression will be tested
        /// against all of the different patterns of tokens that are present in the list of tokens.
        /// Because a token can be tagged with more than one meaning, a single set of tokens may produce
        /// more than one pattern
        /// </param>
        /// <returns>
        /// A MatchSet -- which is the original set of tokens along with a list of the patterns
        /// that matched the criteria that was offered.
        /// </returns>
        public static MatchSet Match(this List <TaggedToken> tokens, string RegExPattern)
        {
            RegexMatcher matcher = new RegexMatcher()
            {
                Expression = RegExPattern
            };

            return(Match(tokens, matcher));
        }
コード例 #18
0
        Tuple <int, int>[] MatchAndPrintStats(RegexMatcher matcher, string input, string info)
        {
            var t = System.Environment.TickCount;
            var m = matcher.Matches(input);

            t = System.Environment.TickCount - t;
            Console.WriteLine("{2}) Match count={0}, time={1}ms", m.Length, t, info);
            return(m);
        }
コード例 #19
0
        //covered by unit tests
        public static bool TryMatchSignature(string sig, out RegexMatcher matcher)
        {
            if (_regexList == null)
                SyntaxMatching.InitRegexList(out _regexList);

            matcher = _regexList.FirstOrDefault(reg => reg.IsMatchSuccessful(sig));

            return matcher!=null;
        }
コード例 #20
0
        public void TestRegexMatcher()
        {
            var aut = new RegexMatcher();

            Assert.IsFalse(aut.IsMatch("ab01"));
            Assert.IsTrue(aut.IsMatch("01ab"));
            Assert.IsFalse(aut.IsMatch("0881abc"));
            Assert.IsTrue(aut.IsMatch("0881ac"));
            Assert.IsFalse(aut.IsMatch("013333a."));
        }
コード例 #21
0
        public void RegexMatcher_GetIgnoreCase()
        {
            // Act
            bool case1 = new RegexMatcher("X").IgnoreCase;
            bool case2 = new RegexMatcher("X", true).IgnoreCase;

            // Assert
            Check.That(case1).IsFalse();
            Check.That(case2).IsTrue();
        }
コード例 #22
0
ファイル: RegexMatcher.cs プロジェクト: UsmanSabir/zxcvbn-cs
        public void MatchesNoMatch()
        {
            var re = new RegexMatcher("\\d{3,}", 10);

            var res = re.MatchPassword("12");

            res.Should().BeEmpty();

            res = re.MatchPassword("dfsdfdfhgjkdfngjl");
            res.Should().BeEmpty();
        }
コード例 #23
0
        public void RegexMatcher_GetName()
        {
            // Assign
            var matcher = new RegexMatcher("");

            // Act
            string name = matcher.Name;

            // Assert
            Check.That(name).Equals("RegexMatcher");
        }
コード例 #24
0
        public void RegexMatcher_IsMatch_IgnoreCase()
        {
            // Assign
            var matcher = new RegexMatcher("H.*o", true);

            // Act
            double result = matcher.IsMatch("hello");

            // Assert
            Check.That(result).IsEqualTo(1.0d);
        }
コード例 #25
0
        public void RegexMatcher_IsMatch_NullInput()
        {
            // Assign
            var matcher = new RegexMatcher("H.*o");

            // Act
            double result = matcher.IsMatch(null);

            // Assert
            Check.That(result).IsEqualTo(0.0d);
        }
コード例 #26
0
        public void RegexMatcher_IsMatch_RejectOnMatch()
        {
            // Assign
            var matcher = new RegexMatcher(MatchBehaviour.RejectOnMatch, "h.*o");

            // Act
            double result = matcher.IsMatch("hello");

            // Assert
            Check.That(result).IsEqualTo(0.0);
        }
コード例 #27
0
 public TokenDefenition(string regex, TokenType tokenType)
 {
     matcher = new RegexMatcher(regex);
     this.tokenType = tokenType;
 }
コード例 #28
0
        internal static void InitRegexList(out RegexMatcher[] regexList)
        {
            regexList = new[]
                        {
                            new RegexMatcher(ImplOperatorMarker,
                                m =>
                                    {
                                        string ret = m.Groups[1].ToString();
                                        string extras = StringConvertUtils.ConvertArgsToString(m.Groups[2].ToString());
                                        return String.Concat("implop_", ret, extras);
                                    }, "IMPLICIT OPERATOR"),

                            new RegexMatcher(ImplOperatorFromAssembly,
                                m =>
                                    {
                                        string ret = m.Groups[1].ToString();
                                        string extras = StringConvertUtils.ConvertArgsToString(m.Groups[2].ToString());
                                        return String.Concat("implop_", ret, extras);
                                    }, "IMPLICIT OPERATOR"),
                            new RegexMatcher(OperatorFromAssembly,
                                m =>
                                    {
                                        string name = StringConvertUtils.ConvertOperatorFromAssembly(m.Groups[2].ToString());
                                        string extras = StringConvertUtils.ConvertArgsToString(m.Groups[3].ToString());
                                        return String.Concat(name, extras);
                                    }, "OPERATOR"),
                            new RegexMatcher(IndexerMarker,
                                m =>
                                    {
                                        string extras = StringConvertUtils.ConvertArgsToString(m.Groups[2].ToString());
                                        return String.Concat("this", extras);
                                    }, "INDEXER"),
                            new RegexMatcher(MethodMarker,
                                m =>
                                    {
                                        string extras = StringConvertUtils.ConvertArgsToString(m.Groups[3].ToString());
                                        return String.Concat(m.Groups[2].ToString(), extras);
                                    }, "METHOD",
                                m => m.Groups[2].ToString()),
                            new RegexMatcher(OperatorMarker,
                                m =>
                                    {
                                        string name = StringConvertUtils.ConvertOperator(m.Groups[2].ToString());
                                        string extras = StringConvertUtils.ConvertArgsToString(m.Groups[3].ToString());
                                        return String.Concat(name, extras);
                                    }, "OPERATOR"),
                            new RegexMatcher(FieldAssignmentMarker, DefaultMatcher, "FIELD ASSIGNMENT"),
                            new RegexMatcher(FieldMarker, DefaultMatcher, "FIELD"),

                            new RegexMatcher(ConstMarker, DefaultMatcher, "CONST"),
                            new RegexMatcher(ConstructorMarker, ConstructorDestructorMatcher,
                                "CONSTRUCTOR",
                                m => "ctor"),

                            new RegexMatcher(DestructorMarker, ConstructorDestructorMatcher, "DESTRUCTOR"),
                            new RegexMatcher(ConstructorFromAssemblyMarker,
                                m =>
                                    {
                                        var sb = new StringBuilder(m.Groups[0].ToString());
                                        sb.Replace("Void .ctor(", "");
                                        sb.Replace(")", "");

                                        string args = StringConvertUtils.ConvertArgsToString(sb.ToString());
                                        return String.Concat("ctor", args);
                                    },
                                    "CONSTRUCTOR_ASSEMBLY"),
                            new RegexMatcher(EnumEntryAssignmentMarker,
                                m => m.Groups[1].ToString(), "ENUM_ENTRY"),
                            new RegexMatcher(EnumEntryNoAssignment,
                                m => m.Groups[1].ToString(), "ENUM_ENTRY_NOASS"),

                        };
        }
コード例 #29
0
 public TokenDefinition(string pattern, string token)
 {
     Matcher = new RegexMatcher(pattern);
     Token = token;
 }
コード例 #30
0
ファイル: QueryLexer.cs プロジェクト: stevesloka/bvcms
 public TokenDef(TokenType type, string regex)
 {
     Matcher = new RegexMatcher(regex);
     TokenType = type;
 }
コード例 #31
0
ファイル: Lexer.cs プロジェクト: h3ll5ur7er/Unification
 public TokenDefinition(Token token)
 {
     Token = token;
     Matcher = new RegexMatcher(token.Pattern());
 }