コード例 #1
0
ファイル: regex.cs プロジェクト: zuisom/PowerShell
 public override void ProcessEndOfString(
     int currentPatternPosition,
     PatternPositionsVisitor patternPositionsForEndOfStringPosition)
 {
     // '*' : (patternPosition, endOfString) => (patternPosition + 1, endOfString)
     patternPositionsForEndOfStringPosition.Add(currentPatternPosition + 1);
 }
コード例 #2
0
 internal bool IsMatch (string str)
 {
     int num3;
     var builder = new StringBuilder(str.Length);
     foreach (char ch in str)
         builder.Append(_characterNormalizer.Normalize(ch));
     str = builder.ToString();
     var patternPositionsForCurrentStringPosition = new PatternPositionsVisitor(_patternElements.Length);
     patternPositionsForCurrentStringPosition.Add(0);
     var patternPositionsForNextStringPosition = new PatternPositionsVisitor(_patternElements.Length);
     for (int i = 0; i < str.Length; i++) {
         int num2;
         char currentStringCharacter = str[i];
         patternPositionsForCurrentStringPosition.StringPosition = i;
         patternPositionsForNextStringPosition.StringPosition = i + 1;
         while (patternPositionsForCurrentStringPosition.MoveNext(out num2)) {
             _patternElements[num2].ProcessStringCharacter(currentStringCharacter, num2,
                 patternPositionsForCurrentStringPosition, patternPositionsForNextStringPosition);
         }
         PatternPositionsVisitor visitor3 = patternPositionsForCurrentStringPosition;
         patternPositionsForCurrentStringPosition = patternPositionsForNextStringPosition;
         patternPositionsForNextStringPosition = visitor3;
     }
     while (patternPositionsForCurrentStringPosition.MoveNext(out num3))
         _patternElements[num3].ProcessEndOfString(num3, patternPositionsForCurrentStringPosition);
     return patternPositionsForCurrentStringPosition.IsEndOfPattern;
 }
コード例 #3
0
ファイル: WildCardPattern.cs プロジェクト: qtuu/TestTools
        internal bool IsMatch(string str)
        {
            // - each state of NFA is represented by (patternPosition, stringPosition) tuple
            //     - state transitions are documented in
            //       ProcessStringCharacter and ProcessEndOfString methods
            // - the algorithm below tries to see if there is a path
            //   from (0, 0) to (lengthOfPattern, lengthOfString)
            //    - this is a regular graph traversal
            //    - there are O(1) edges per node (at most 2 edges)
            //      so the whole graph traversal takes O(number of nodes in the graph) =
            //      = O(lengthOfPattern * lengthOfString) time
            //    - for efficient remembering which states have already been visited,
            //      the traversal goes methodically from beginning to end of the string
            //      therefore requiring only O(lengthOfPattern) memory for remembering
            //      which states have been already visited
            //  - Wikipedia calls this algorithm the "NFA" algorithm at
            //    http://en.wikipedia.org/wiki/Regular_expression#Implementations_and_running_times

            var patternPositionsForCurrentStringPosition =
                new PatternPositionsVisitor(_patternElements.Length);

            patternPositionsForCurrentStringPosition.Add(0);

            var patternPositionsForNextStringPosition =
                new PatternPositionsVisitor(_patternElements.Length);

            for (int currentStringPosition = 0;
                 currentStringPosition < str.Length;
                 currentStringPosition++)
            {
                char currentStringCharacter = _characterNormalizer.Normalize(str[currentStringPosition]);
                patternPositionsForCurrentStringPosition.StringPosition = currentStringPosition;
                patternPositionsForNextStringPosition.StringPosition    = currentStringPosition + 1;

                while (patternPositionsForCurrentStringPosition.MoveNext(out int patternPosition))
                {
                    _patternElements[patternPosition].ProcessStringCharacter(
                        currentStringCharacter,
                        patternPosition,
                        patternPositionsForCurrentStringPosition,
                        patternPositionsForNextStringPosition);
                }

                // swap patternPositionsForCurrentStringPosition
                // with patternPositionsForNextStringPosition
                var tmp = patternPositionsForCurrentStringPosition;
                patternPositionsForCurrentStringPosition = patternPositionsForNextStringPosition;
                patternPositionsForNextStringPosition    = tmp;
            }

            while (patternPositionsForCurrentStringPosition.MoveNext(out int patternPosition2))
            {
                _patternElements[patternPosition2].ProcessEndOfString(
                    patternPosition2,
                    patternPositionsForCurrentStringPosition);
            }

            return(patternPositionsForCurrentStringPosition.ReachedEndOfPattern);
        }
コード例 #4
0
 public override void ProcessStringCharacter(char currentStringCharacter, int currentPatternPosition,
                                             PatternPositionsVisitor patternPositionsForCurrentStringPosition, PatternPositionsVisitor patternPositionsForNextStringPosition)
 {
     if (_regex.IsMatch(new string(currentStringCharacter, 1)))
     {
         base.ProcessStringCharacter(currentStringCharacter, currentPatternPosition,
                                     patternPositionsForCurrentStringPosition, patternPositionsForNextStringPosition);
     }
 }
コード例 #5
0
 public override void ProcessStringCharacter(
     char currentStringCharacter,
     int currentPatternPosition,
     PatternPositionsVisitor patternPositionsForCurrentStringPosition,
     PatternPositionsVisitor patternPositionsForNextStringPosition)
 {
     // '?' : (patternPosition, stringPosition) => (patternPosition + 1, stringPosition + 1)
     patternPositionsForNextStringPosition.Add(currentPatternPosition + 1);
 }
コード例 #6
0
 public override void ProcessStringCharacter(char currentStringCharacter, int currentPatternPosition,
                                             PatternPositionsVisitor patternPositionsForCurrentStringPosition, PatternPositionsVisitor patternPositionsForNextStringPosition)
 {
     if (_literalCharacter == currentStringCharacter)
     {
         base.ProcessStringCharacter(currentStringCharacter, currentPatternPosition,
                                     patternPositionsForCurrentStringPosition, patternPositionsForNextStringPosition);
     }
 }
コード例 #7
0
        internal bool IsMatch(string str)
        {
            int num3;
            var builder = new StringBuilder(str.Length);

            foreach (char ch in str)
            {
                builder.Append(_characterNormalizer.Normalize(ch));
            }
            str = builder.ToString();
            var patternPositionsForCurrentStringPosition = new PatternPositionsVisitor(_patternElements.Length);

            patternPositionsForCurrentStringPosition.Add(0);
            var patternPositionsForNextStringPosition = new PatternPositionsVisitor(_patternElements.Length);

            for (int i = 0; i < str.Length; i++)
            {
                int  num2;
                char currentStringCharacter = str[i];
                patternPositionsForCurrentStringPosition.StringPosition = i;
                patternPositionsForNextStringPosition.StringPosition    = i + 1;
                while (patternPositionsForCurrentStringPosition.MoveNext(out num2))
                {
                    _patternElements[num2].ProcessStringCharacter(currentStringCharacter, num2,
                                                                  patternPositionsForCurrentStringPosition, patternPositionsForNextStringPosition);
                }
                PatternPositionsVisitor visitor3 = patternPositionsForCurrentStringPosition;
                patternPositionsForCurrentStringPosition = patternPositionsForNextStringPosition;
                patternPositionsForNextStringPosition    = visitor3;
            }
            while (patternPositionsForCurrentStringPosition.MoveNext(out num3))
            {
                _patternElements[num3].ProcessEndOfString(num3, patternPositionsForCurrentStringPosition);
            }
            return(patternPositionsForCurrentStringPosition.IsEndOfPattern);
        }
コード例 #8
0
ファイル: regex.cs プロジェクト: 40a/PowerShell
        internal bool IsMatch(string str)
        {
            // - each state of NFA is represented by (patternPosition, stringPosition) tuple
            //     - state transitions are documented in
            //       ProcessStringCharacter and ProcessEndOfString methods
            // - the algorithm below tries to see if there is a path 
            //   from (0, 0) to (lengthOfPattern, lengthOfString)
            //    - this is a regular graph traversal
            //    - there are O(1) edges per node (at most 2 edges) 
            //      so the whole graph traversal takes O(number of nodes in the graph) =
            //      = O(lengthOfPattern * lengthOfString) time
            //    - for efficient remembering which states have already been visited, 
            //      the traversal goes methodically from beginning to end of the string
            //      therefore requiring only O(lengthOfPattern) memory for remembering
            //      which states have been already visited
            //  - Wikipedia calls this algorithm the "NFA" algorithm at
            //    http://en.wikipedia.org/wiki/Regular_expression#Implementations_and_running_times

            var patternPositionsForCurrentStringPosition =
                    new PatternPositionsVisitor(_patternElements.Length);
            patternPositionsForCurrentStringPosition.Add(0);

            var patternPositionsForNextStringPosition =
                    new PatternPositionsVisitor(_patternElements.Length);

            for (int currentStringPosition = 0;
                 currentStringPosition < str.Length;
                 currentStringPosition++)
            {
                char currentStringCharacter = _characterNormalizer.Normalize(str[currentStringPosition]);
                patternPositionsForCurrentStringPosition.StringPosition = currentStringPosition;
                patternPositionsForNextStringPosition.StringPosition = currentStringPosition + 1;

                int patternPosition;
                while (patternPositionsForCurrentStringPosition.MoveNext(out patternPosition))
                {
                    _patternElements[patternPosition].ProcessStringCharacter(
                        currentStringCharacter,
                        patternPosition,
                        patternPositionsForCurrentStringPosition,
                        patternPositionsForNextStringPosition);
                }

                // swap patternPositionsForCurrentStringPosition 
                // with patternPositionsForNextStringPosition
                var tmp = patternPositionsForCurrentStringPosition;
                patternPositionsForCurrentStringPosition = patternPositionsForNextStringPosition;
                patternPositionsForNextStringPosition = tmp;
            }

            int patternPosition2;
            while (patternPositionsForCurrentStringPosition.MoveNext(out patternPosition2))
            {
                _patternElements[patternPosition2].ProcessEndOfString(
                    patternPosition2,
                    patternPositionsForCurrentStringPosition);
            }

            return patternPositionsForCurrentStringPosition.ReachedEndOfPattern;
        }
コード例 #9
0
ファイル: regex.cs プロジェクト: 40a/PowerShell
 public override void ProcessEndOfString(
                 int currentPatternPosition,
                 PatternPositionsVisitor patternPositionsForEndOfStringPosition)
 {
     // '*' : (patternPosition, endOfString) => (patternPosition + 1, endOfString)
     patternPositionsForEndOfStringPosition.Add(currentPatternPosition + 1);
 }
コード例 #10
0
ファイル: regex.cs プロジェクト: 40a/PowerShell
            public override void ProcessStringCharacter(
                            char currentStringCharacter,
                            int currentPatternPosition,
                            PatternPositionsVisitor patternPositionsForCurrentStringPosition,
                            PatternPositionsVisitor patternPositionsForNextStringPosition)
            {
                // '*' : (patternPosition, stringPosition) => (patternPosition + 1, stringPosition)
                patternPositionsForCurrentStringPosition.Add(currentPatternPosition + 1);

                // '*' : (patternPosition, stringPosition) => (patternPosition, stringPosition + 1)
                patternPositionsForNextStringPosition.Add(currentPatternPosition);
            }
コード例 #11
0
ファイル: regex.cs プロジェクト: 40a/PowerShell
 public override void ProcessStringCharacter(
                 char currentStringCharacter,
                 int currentPatternPosition,
                 PatternPositionsVisitor patternPositionsForCurrentStringPosition,
                 PatternPositionsVisitor patternPositionsForNextStringPosition)
 {
     if (_regex.IsMatch(new string(currentStringCharacter, 1)))
     {
         base.ProcessStringCharacter(currentStringCharacter, currentPatternPosition,
                                     patternPositionsForCurrentStringPosition,
                                     patternPositionsForNextStringPosition);
     }
 }
コード例 #12
0
ファイル: regex.cs プロジェクト: 40a/PowerShell
 public override void ProcessStringCharacter(
                 char currentStringCharacter,
                 int currentPatternPosition,
                 PatternPositionsVisitor patternPositionsForCurrentStringPosition,
                 PatternPositionsVisitor patternPositionsForNextStringPosition)
 {
     if (_literalCharacter == currentStringCharacter)
     {
         base.ProcessStringCharacter(
                 currentStringCharacter,
                 currentPatternPosition,
                 patternPositionsForCurrentStringPosition,
                 patternPositionsForNextStringPosition);
     }
 }
コード例 #13
0
ファイル: regex.cs プロジェクト: 40a/PowerShell
 public abstract void ProcessStringCharacter(
                 char currentStringCharacter,
                 int currentPatternPosition,
                 PatternPositionsVisitor patternPositionsForCurrentStringPosition,
                 PatternPositionsVisitor patternPositionsForNextStringPosition);
コード例 #14
0
 public override void ProcessEndOfString (int currentPatternPosition, PatternPositionsVisitor patternPositionsForEndOfStringPosition)
 {}
コード例 #15
0
 public override void ProcessEndOfString(int currentPatternPosition, PatternPositionsVisitor patternPositionsForEndOfStringPosition)
 {
 }
コード例 #16
0
 public abstract void ProcessStringCharacter(
     char currentStringCharacter,
     int currentPatternPosition,
     PatternPositionsVisitor patternPositionsForCurrentStringPosition,
     PatternPositionsVisitor patternPositionsForNextStringPosition);
コード例 #17
0
 public abstract void ProcessEndOfString(
     int currentPatternPosition,
     PatternPositionsVisitor patternPositionsForEndOfStringPosition);
コード例 #18
0
ファイル: regex.cs プロジェクト: 40a/PowerShell
 public abstract void ProcessEndOfString(
                 int currentPatternPosition,
                 PatternPositionsVisitor patternPositionsForEndOfStringPosition);
コード例 #19
0
 public override void ProcessEndOfString(
     int currentPatternPosition,
     PatternPositionsVisitor patternPositionsForEndOfStringPosition)
 {
     // '?' : (patternPosition, endOfString) => <no transitions out of this state - cannot move beyond end of string>
 }
コード例 #20
0
ファイル: regex.cs プロジェクト: 40a/PowerShell
 public override void ProcessEndOfString(
                 int currentPatternPosition,
                 PatternPositionsVisitor patternPositionsForEndOfStringPosition)
 {
     // '?' : (patternPosition, endOfString) => <no transitions out of this state - cannot move beyond end of string>
 }