예제 #1
0
 public void AddToLookupTable(Pattern pattern)
 {
     if (pattern.IsComplex)
     {
         ComplexPatterns.Add(pattern);
         return;
     }
     else
     {
         this.tmpSimplePatterns.Add(pattern);
     }
 }
예제 #2
0
        /// <summary>
///
/// </summary>
/// <param name="Pattern"></param>
/// <returns></returns>
        public Pattern Add(Pattern Pattern)
        {
            if (this.Parent != null && this.Parent.Parent != null && this.Parent.Parent.Parent != null)
            {
                Pattern.Separators = this.Parent.Parent.Parent.Separators;
                this.Parent.Parent.Parent.ChangeVersion();
            }

            if (!Pattern.IsComplex && !Pattern.ContainsSeparator)
            {
                //store pattern in lookuptable if it is a simple pattern
                string s = "";

                if (Pattern.StringPattern.Length >= 2)
                {
                    s = Pattern.StringPattern.Substring(0, 2);
                }
                else
                {
                    s = Pattern.StringPattern.Substring(0, 1) + " ";
                }

                s = s.ToLower();

                if (Pattern.StringPattern.Length == 1)
                {
                    SimplePatterns1Char[Pattern.StringPattern] = Pattern;
                }
                else
                {
                    if (SimplePatterns2Char[s] == null)
                    {
                        SimplePatterns2Char[s] = new PatternCollection();
                    }
                    PatternCollection ar = (PatternCollection)SimplePatterns2Char[s];
                    ar.Add(Pattern);
                }

                if (this.CaseSensitive)
                {
                    SimplePatterns[Pattern.LowerStringPattern] = Pattern;
                }
                else
                {
                    SimplePatterns[Pattern.StringPattern] = Pattern;
                }

//				if (SimplePatterns[s]==null)
//					SimplePatterns.Add (s,new ArrayList ());
//
//				ArrayList bb=(ArrayList) SimplePatterns[s];
//
//				bb.Add (Pattern);
            }
            else
            {
                ComplexPatterns.Add(Pattern);
            }

            mPatterns.Add(Pattern);
            if (Pattern.Parent == null)
            {
                Pattern.Parent = this;
            }
            else
            {
                throw(new Exception("Pattern already assigned to another PatternList"));
            }
            return(Pattern);
        }
예제 #3
0
        public void BuildLookupTable()
        {
            IComparer comparer = new PatternComparer();

            this.tmpSimplePatterns.Sort(comparer);
            foreach (Pattern p in tmpSimplePatterns)
            {
                if (p.StringPattern.Length <= 2)
                {
                    char c = p.StringPattern[0];

                    if (!p.Parent.CaseSensitive)
                    {
                        char c1 = char.ToLower(c);
                        if (LookupTable[c1] == null)
                        {
                            LookupTable[c1] = new PatternCollection();
                        }

                        PatternCollection patterns = LookupTable[c1] as PatternCollection;
                        if (!patterns.Contains(p))
                        {
                            patterns.Add(p);
                        }

                        char c2 = char.ToUpper(c);
                        if (LookupTable[c2] == null)
                        {
                            LookupTable[c2] = new PatternCollection();
                        }

                        patterns = LookupTable[c2] as PatternCollection;
                        if (!patterns.Contains(p))
                        {
                            patterns.Add(p);
                        }
                    }
                    else
                    {
                        if (LookupTable[c] == null)
                        {
                            LookupTable[c] = new PatternCollection();
                        }

                        PatternCollection patterns = LookupTable[c] as PatternCollection;
                        if (!patterns.Contains(p))
                        {
                            patterns.Add(p);
                        }
                    }
                }
                else
                {
                    string c = p.StringPattern.Substring(0, 3).ToLower();

                    if (LookupTable[c] == null)
                    {
                        LookupTable[c] = new PatternCollection();
                    }

                    PatternCollection patterns = LookupTable[c] as PatternCollection;
                    if (!patterns.Contains(p))
                    {
                        patterns.Add(p);
                    }
                }
            }
        }