示例#1
0
        private static bool MatchedStringsEqual(MatchString actualString, MatchString expectedString)
        {
            if (actualString == null && expectedString == null)
            {
                return(true);
            }

            if (!(actualString != null && expectedString != null))
            {
                return(false);
            }

            if (actualString.Count != expectedString.Count)
            {
                return(false);
            }

            for (int i = 0; i < actualString.Count; i++)
            {
                if (!MatchedSubtringsEqual(actualString[i], expectedString[i]))
                {
                    return(false);
                }
            }

            return(true);
        }
        public MatchModel(IMatchModelMapper matchModelMapper, MatchString matchedText, string path)
        {
            _matchedText = matchedText;
            _path = path;
            _matchModelMapper = matchModelMapper;

            _textBlock = GetTextBlock(_matchedText);
        }
示例#3
0
        public MatchModel(IMatchModelMapper matchModelMapper, MatchString matchedText, string path)
        {
            _matchedText      = matchedText;
            _path             = path;
            _matchModelMapper = matchModelMapper;

            _textBlock = GetTextBlock(_matchedText);
        }
        public MatchModel GetMatchModel(MatchedFileSystemItem match)
        {
            //Clone the matched item name
            MatchString matchedItemName = new MatchString(match.MatchedItemName);
            string path = string.Format(CultureInfo.InvariantCulture, " -> {0}", match.FullPath);
            matchedItemName.Add(new MatchSubstring(path, false));

            return new MatchModel(this, matchedItemName, match.FullPath);
        }
示例#5
0
        public MatchModel GetMatchModel(MatchedFileSystemItem match)
        {
            //Clone the matched item name
            MatchString matchedItemName = new MatchString(match.MatchedItemName);
            string      path            = string.Format(CultureInfo.InvariantCulture, " -> {0}", match.FullPath);

            matchedItemName.Add(new MatchSubstring(path, false));

            return(new MatchModel(this, matchedItemName, match.FullPath));
        }
示例#6
0
// END CUT HERE
// BEGIN CUT HERE
    public static void Main()
    {
        MatchString ___test = new MatchString();

        ___test.run_test(-1);
        try {
        } catch (Exception e) {
//Console.WriteLine(e.StackTrace);
            Console.WriteLine(e.ToString());
        }
    }
示例#7
0
    // END CUT HERE
    // BEGIN CUT HERE
    public static void Main()
    {
        MatchString ___test = new MatchString();
        ___test.run_test(-1);
        try {

        } catch(Exception e) {
        //Console.WriteLine(e.StackTrace);
        Console.WriteLine(e.ToString());
        }
    }
        public MatchModel(IMatchModelMapper matchModelMapper, string text)
        {
            _path = null;
            _matchModelMapper = matchModelMapper;

            MatchSubstring substring = new MatchSubstring(text, false);
            List<MatchSubstring> substrings = new List<MatchSubstring> { substring };
            _matchedText = new MatchString(substrings);

            _textBlock = GetTextBlock(_matchedText);
        }
示例#9
0
        public void CompareUnequalLengths()
        {
            // Arrange - setup the test data
            string s1 = "eat";
            string s2 = "teas";

            // Act
            bool result = MatchString.Match(s1, s2);

            // Assert
            Assert.IsFalse(result);
        }
示例#10
0
        public void CompareKnownGood1()
        {
            // Arrange - setup the test data
            string s1 = "eat";
            string s2 = "tea";

            // Act
            bool result = MatchString.Match(s1, s2);

            // Assert
            Assert.IsTrue(result);
        }
示例#11
0
        public MatchModel(IMatchModelMapper matchModelMapper, string text)
        {
            _path             = null;
            _matchModelMapper = matchModelMapper;

            MatchSubstring        substring  = new MatchSubstring(text, false);
            List <MatchSubstring> substrings = new List <MatchSubstring> {
                substring
            };

            _matchedText = new MatchString(substrings);

            _textBlock = GetTextBlock(_matchedText);
        }
        public TextBlock GetTextBlock(MatchString matchedText, TextDecorationCollection matchDecoration, Brush matchColor)
        {
            TextBlock textBlock = new TextBlock();
            textBlock.HorizontalAlignment = HorizontalAlignment.Left;

            foreach (MatchSubstring matchSubstring in matchedText)
            {
                Run substringControl = new Run(matchSubstring.Value);
                if (matchSubstring.IsMatched)
                {
                    substringControl.TextDecorations = matchDecoration;
                    substringControl.Foreground = matchColor;
                }

                textBlock.Inlines.Add(substringControl);
            }

            return textBlock;
        }
示例#13
0
        public TextBlock GetTextBlock(MatchString matchedText, TextDecorationCollection matchDecoration, Brush matchColor)
        {
            TextBlock textBlock = new TextBlock();

            textBlock.HorizontalAlignment = HorizontalAlignment.Left;

            foreach (MatchSubstring matchSubstring in matchedText)
            {
                Run substringControl = new Run(matchSubstring.Value);
                if (matchSubstring.IsMatched)
                {
                    substringControl.TextDecorations = matchDecoration;
                    substringControl.Foreground      = matchColor;
                }

                textBlock.Inlines.Add(substringControl);
            }

            return(textBlock);
        }
示例#14
0
    public override int GetHashCode()
    {
        int hash = 1;

        if (Key.Length != 0)
        {
            hash ^= Key.GetHashCode();
        }
        if (MatchString.Length != 0)
        {
            hash ^= MatchString.GetHashCode();
        }
        if (FilterType != 0)
        {
            hash ^= FilterType.GetHashCode();
        }
        if (_unknownFields != null)
        {
            hash ^= _unknownFields.GetHashCode();
        }
        return(hash);
    }
示例#15
0
        private TestCaseData CreateTestCaseData(string folderName, string searchText, string matchedSubstring, string testName)
        {
            FileSystemItem        item = new FileSystemItem("C:\\" + folderName);
            MatchedFileSystemItem expectedMatch;

            if (string.IsNullOrEmpty(matchedSubstring))
            {
                expectedMatch = null;
            }
            else
            {
                MatchString matchString = new MatchString
                {
                    new MatchSubstring(matchedSubstring, true),
                    new MatchSubstring(folderName.Substring(matchedSubstring.Length), false),
                };
                expectedMatch = new MatchedFileSystemItem(item, matchString);
            }

            TestCaseData testCaseData = new TestCaseData(item, searchText, expectedMatch).SetName(testName);

            return(testCaseData);
        }
 public MatchedFileSystemItem(FileSystemItem fileSystemItem, MatchString matchedString)
 {
     Name = fileSystemItem.Name;
     FullPath = fileSystemItem.FullPath;
     MatchedItemName = matchedString;
 }
        private static bool MatchedStringsEqual(MatchString actualString, MatchString expectedString)
        {
            if (actualString == null && expectedString == null)
            {
                return true;
            }

            if (!(actualString != null && expectedString != null))
            {
                return false;
            }

            if (actualString.Count != expectedString.Count)
            {
                return false;
            }

            for (int i = 0; i < actualString.Count; i++)
            {
                if (!MatchedSubtringsEqual(actualString[i], expectedString[i]))
                {
                    return false;
                }
            }

            return true;
        }
        private TestCaseData CreateTestCaseData(string folderName, string searchText, string matchedSubstring, string testName)
        {
            FileSystemItem item = new FileSystemItem("C:\\" + folderName);
            MatchedFileSystemItem expectedMatch;
            if (string.IsNullOrEmpty(matchedSubstring))
            {
                expectedMatch = null;
            }
            else
            {
                MatchString matchString = new MatchString
                                  {
                                      new MatchSubstring(matchedSubstring, true),
                                      new MatchSubstring(folderName.Substring(matchedSubstring.Length), false),
                                  };
                expectedMatch = new MatchedFileSystemItem(item, matchString);
            }

            TestCaseData testCaseData = new TestCaseData(item, searchText, expectedMatch).SetName(testName);
            return testCaseData;
        }
        public IEnumerable<TestCaseData> GetMatchCases()
        {
            const string rootPath = @"C:\";

            FileSystemItem item;
            string searchText;
            MatchString matchString;
            MatchedFileSystemItem expectedMatch;
            TestCaseData testCaseData;

            yield return CreateTestCaseData("my doc", "y d", null, "Match just from word start (first word violation)");

            yield return CreateTestCaseData("my doc", "m d", "my d", "Simple match of two words");

            yield return CreateTestCaseData("my own doc", "m d", null, "Match just neighboring words");

            yield return CreateTestCaseData("my doc", "m o", null, "Match just from word start (second word violation)");

            item = new FileSystemItem(rootPath + "my own doc");
            searchText = "ow Do";
            matchString = new MatchString
                              {
                                  new MatchSubstring("my ", false),
                                  new MatchSubstring("own do", true),
                                  new MatchSubstring("c", false),
                              };
            expectedMatch = new MatchedFileSystemItem(item, matchString);
            testCaseData = new TestCaseData(item, searchText, expectedMatch).SetName("Simple match from the second word");
            yield return testCaseData;

            item = new FileSystemItem(rootPath + "my oWn dOc");
            searchText = "Ow Do";
            matchString = new MatchString
                              {
                                  new MatchSubstring("my ", false),
                                  new MatchSubstring("oWn dO", true),
                                  new MatchSubstring("c", false),
                              };
            expectedMatch = new MatchedFileSystemItem(item, matchString);
            testCaseData = new TestCaseData(item, searchText, expectedMatch).SetName("Simple match from the second word (ignored case)");
            yield return testCaseData;

            yield return CreateTestCaseData("myDoc", "m dO", "myDo", "Match camel/pascal casing");

            yield return CreateTestCaseData("my    Doc", "m do", "my    Do", "Ignore multiple spaces in item name");

            yield return CreateTestCaseData("my Doc", "m   do", "my Do", "Ignore multiple spaces in search text");

            item = new FileSystemItem(rootPath + "myOwnDoc");
            searchText = "o do";
            matchString = new MatchString
                              {
                                  new MatchSubstring("my", false),
                                  new MatchSubstring("OwnDo", true),
                                  new MatchSubstring("c", false)
                              };
            expectedMatch = new MatchedFileSystemItem(item, matchString);
            testCaseData = new TestCaseData(item, searchText, expectedMatch).SetName("Match camel/pascal casing in the middle");
            yield return testCaseData;

            yield return CreateTestCaseData("mydoc", "m do", null, "Do not match words not separated with space or camel case");
        }
 private TextBlock GetTextBlock(MatchString matchedText)
 {
     return _matchModelMapper.GetTextBlock(matchedText, TextDecorations.Underline, Brushes.Blue);
 }
示例#21
0
        public IEnumerable <TestCaseData> GetMatchCases()
        {
            const string rootPath = @"C:\";

            FileSystemItem        item;
            string                searchText;
            MatchString           matchString;
            MatchedFileSystemItem expectedMatch;
            TestCaseData          testCaseData;

            yield return(CreateTestCaseData("my doc", "y d", null, "Match just from word start (first word violation)"));

            yield return(CreateTestCaseData("my doc", "m d", "my d", "Simple match of two words"));

            yield return(CreateTestCaseData("my own doc", "m d", null, "Match just neighboring words"));

            yield return(CreateTestCaseData("my doc", "m o", null, "Match just from word start (second word violation)"));

            item        = new FileSystemItem(rootPath + "my own doc");
            searchText  = "ow Do";
            matchString = new MatchString
            {
                new MatchSubstring("my ", false),
                new MatchSubstring("own do", true),
                new MatchSubstring("c", false),
            };
            expectedMatch = new MatchedFileSystemItem(item, matchString);
            testCaseData  = new TestCaseData(item, searchText, expectedMatch).SetName("Simple match from the second word");
            yield return(testCaseData);

            item        = new FileSystemItem(rootPath + "my oWn dOc");
            searchText  = "Ow Do";
            matchString = new MatchString
            {
                new MatchSubstring("my ", false),
                new MatchSubstring("oWn dO", true),
                new MatchSubstring("c", false),
            };
            expectedMatch = new MatchedFileSystemItem(item, matchString);
            testCaseData  = new TestCaseData(item, searchText, expectedMatch).SetName("Simple match from the second word (ignored case)");
            yield return(testCaseData);

            yield return(CreateTestCaseData("myDoc", "m dO", "myDo", "Match camel/pascal casing"));

            yield return(CreateTestCaseData("my    Doc", "m do", "my    Do", "Ignore multiple spaces in item name"));

            yield return(CreateTestCaseData("my Doc", "m   do", "my Do", "Ignore multiple spaces in search text"));

            item        = new FileSystemItem(rootPath + "myOwnDoc");
            searchText  = "o do";
            matchString = new MatchString
            {
                new MatchSubstring("my", false),
                new MatchSubstring("OwnDo", true),
                new MatchSubstring("c", false)
            };
            expectedMatch = new MatchedFileSystemItem(item, matchString);
            testCaseData  = new TestCaseData(item, searchText, expectedMatch).SetName("Match camel/pascal casing in the middle");
            yield return(testCaseData);

            yield return(CreateTestCaseData("mydoc", "m do", null, "Do not match words not separated with space or camel case"));
        }
示例#22
0
文件: Trigger.cs 项目: mikabre/topkek
        public string ExecuteIfMatches(IrcMessage msg, IrcClient client)
        {
            try
            {
                string haystack = "";

                if (TriggerType == TriggerType.Raw)
                {
                    haystack = msg.RawMessage;
                }
                else
                {
                    haystack = new PrivateMessage(msg).Message;
                }

                if (Matches(haystack))
                {
                    if (TriggerResult == TriggerResult.Raw)
                    {
                        client.SendRawMessage(ResultString);
                    }
                    else if (TriggerResult == TriggerResult.Irc)
                    {
                        client.SendMessage(ResultString, new PrivateMessage(msg).Source);
                    }
                    else if (TriggerResult == TriggerResult.Modify)
                    {
                        string temp = haystack;

                        if (FixHomoglyphs)
                        {
                            temp = Table.Purify(temp);
                        }
                        if (Strip)
                        {
                            temp = Utilities.Sanitize(temp);
                        }
                        if (AsciiOnly)
                        {
                            temp = new string(temp.Where(c => (char.IsLetterOrDigit(c) || char.IsSymbol(c) || MatchString.Contains(c))).ToArray());
                        }

                        switch (TriggerMatchType)
                        {
                        case TriggerMatchType.Contains:
                            return(temp.Replace(MatchString, ResultString));

                        case TriggerMatchType.EndsWith:
                            return(temp.Substring(0, temp.Length - MatchString.Length) + ResultString);

                        case TriggerMatchType.StartsWith:
                            return(ResultString + temp.Substring(MatchString.Length));

                        case TriggerMatchType.Regex:
                            return(Regex.Replace(temp, MatchString, m => { return ResultString; }, Insensitive ? RegexOptions.IgnoreCase : RegexOptions.None));
                        }
                    }
                    else if (TriggerResult == TriggerResult.Rewrite)
                    {
                        return(ResultString);
                    }
                }
            }
            catch
            {
            }

            return("");
        }
示例#23
0
文件: Trigger.cs 项目: mikabre/topkek
        public bool Matches(string msg)
        {
            if (FixHomoglyphs)
            {
                msg = Table.Purify(msg);
            }

            if (Insensitive)
            {
                msg = msg.ToLower();
            }

            if (Strip)
            {
                msg = Utilities.Sanitize(msg);
            }

            if (AsciiOnly)
            {
                msg = new string(msg.Where(c => (char.IsLetterOrDigit(c) || char.IsSymbol(c) || MatchString.Contains(c))).ToArray());
            }

            bool matches = false;

            switch (TriggerMatchType)
            {
            case TriggerMatchType.Contains:
                matches = msg.Contains(MatchString);
                break;

            case TriggerMatchType.EndsWith:
                matches = msg.EndsWith(MatchString);
                break;

            case TriggerMatchType.StartsWith:
                matches = msg.StartsWith(MatchString);
                break;

            case TriggerMatchType.Regex:
                matches = Regex.IsMatch(msg, MatchString);
                break;
            }

            return(matches);
        }
示例#24
0
 public MatchedFileSystemItem(FileSystemItem fileSystemItem, MatchString matchedString)
 {
     Name            = fileSystemItem.Name;
     FullPath        = fileSystemItem.FullPath;
     MatchedItemName = matchedString;
 }
示例#25
0
 private TextBlock GetTextBlock(MatchString matchedText)
 {
     return(_matchModelMapper.GetTextBlock(matchedText, TextDecorations.Underline, Brushes.Blue));
 }