예제 #1
0
        public RegEx(string regex, bool caseSensitive)
        {
            if (caseSensitive)
            {
                regex = regex.ToLower();
            }

            //convert regex to NFA:
            int index = -1;
            NFA nfa   = RegexToNFA(regex, ref index);

            if (index < regex.Length)
            {
                throw new ParseException("Error occurred while parsing the regular expression!");
            }

            if (nfa != null)
            {
                //make epsilon transitions superfluous:
                nfa.RemoveEpsilonTransitions();

                //convert NFA to DFA:
                transitionMatrix = nfa.GetDFATransitionMatrix(out startIndex);

                //manipulate transition matrix to make it case sensitive:
                if (caseSensitive)
                {
                    for (int x = 0; x < transitionMatrix.Length; x++)
                    {
                        for (int y = 0; y <= ('Z' - 'A'); y++)
                        {
                            transitionMatrix[x][(byte)(y + 'A')] = transitionMatrix[x][(byte)(y + 'a')];
                        }
                        transitionMatrix[x][(byte)('Ä')] = transitionMatrix[x][(byte)('ä')];
                        transitionMatrix[x][(byte)('Ö')] = transitionMatrix[x][(byte)('ö')];
                        transitionMatrix[x][(byte)('Ü')] = transitionMatrix[x][(byte)('ü')];
                    }
                }
            }
        }