Beispiel #1
0
 public object Clone()
 {
     if (IsMatch)
     {
         MatchItem item = new MatchItem();
         KeyWords.CopyTo(item.KeyWords, 0);
         KeyWordIndexs.CopyTo(item.KeyWordIndexs, 0);
         item.IsMatch       = true;
         item.Data          = Data;
         item.KeyWordLength = KeyWordLength;
         return(item);
     }
     return(null);
 }
Beispiel #2
0
        private void OnRule(char[] source, Rule rule, IList <MatchItem> result)
        {
            IList <MatchItem> ruleitems = OnMatchs(rule.Data, rule.Count);

            for (int i = 0; i < ruleitems.Count; i++)
            {
                MatchItem ritem = ruleitems[i];
                MatchItem mitem = new MatchItem();
                mitem.IsMatch = true;
                mitem.Data    = source;
                for (int k = 0; k < ritem.KeyWordLength; k++)
                {
                    int index = rule.Indes[ritem.KeyWordIndexs[k]];
                    mitem.Add(source[index], index);
                }

                result.Add(mitem);
            }
        }
Beispiel #3
0
        private IList <MatchItem> OnMatchs(char[] data, int length, bool matchFirst = false)
        {
            IList <MatchItem> result = new List <MatchItem>();
            Rule rule  = Rule1;
            int  index = 0;

            while (index < length)
            {
                CharGroup group = mGroup[Utils.Cast(data[index])];
                if (group != null)
                {
                    MatchItem item = group.Match(data, index);
                    if (item.IsMatch)
                    {
                        result.Add((MatchItem)item.Clone());
                        index           = item.EndIndex() + 1;
                        rule.mLastIndex = -10;
                        if (matchFirst)
                        {
                            return(result);
                        }
                    }
                    else
                    {
                        rule.Add(data, index);
                        index++;
                    }
                }
                else
                {
                    rule.Add(data, index);
                    index++;
                }
            }
            if (rule.Count > 2)
            {
                OnRule(data, rule, result);
            }
            return(result);
        }
Beispiel #4
0
        private void Rule(MatchItem result, char[] data)
        {
            int      cindex = result.StartIndex();
            WordType ctype  = Utils.GetWordTypeWithChar(data[cindex]);

            if (ctype == WordType.EN || ctype == WordType.Number)
            {
                if (cindex > 1 && ctype == Utils.GetWordTypeWithChar(data[cindex - 1]))
                {
                    result.IsMatch = false;
                }
            }
            cindex = result.EndIndex();
            ctype  = Utils.GetWordTypeWithChar(data[cindex]);
            if (ctype == WordType.EN || ctype == WordType.Number)
            {
                if (cindex < data.Length - 1 && ctype == Utils.GetWordTypeWithChar(data[cindex + 1]))
                {
                    result.IsMatch = false;
                }
            }
        }
Beispiel #5
0
        public void Match(char[] data, int start, MatchItem result)
        {
            BlankType = KFilter.WordType.None;
            int blank = MaxBlank;
            int count = LstItems.Count;

BETIN:
            if (start >= data.Length)
            {
                result.IsMatch = false;
                return;
            }
            char     key  = Utils.Cast(data[start]);
            CharItem item = null;

            if (count == 1)
            {
                if (LstItems[0].Key == key)
                {
                    item = LstItems[0];
                }
            }
            else if (count == 2)
            {
                if (LstItems[0].Key == key)
                {
                    item = LstItems[0];
                }
                else
                {
                    if (LstItems[1].Key == key)
                    {
                        item = LstItems[1];
                    }
                }
            }
            else
            {
                Items.TryGetValue(key, out item);
            }

            if (item != null)
            {
                result.IsMatch = true;
                result.Add(key, start);

                if (!item.Eof)
                {
                    item.Match(data, start + 1, result);
                }
            }
            else
            {
                if (blank > 0 && (WordType & Utils.GetWordTypeWithChar(key)) == 0 && key != '\0')
                {
                    WordType chartype = Utils.GetWordTypeWithChar(key);
                    if (BlankType == KFilter.WordType.None)
                    {
                        BlankType = chartype;
                    }
                    else
                    {
                        if (BlankType != chartype)
                        {
                            blank--;
                        }
                        BlankType = chartype;
                    }
                    start++;
                    goto BETIN;
                }
                result.IsMatch = false;
            }
        }
Beispiel #6
0
        public MatchItem Match(char[] data, int index)
        {
            MatchItem result = MatchItem;

            BlankType = KFilter.WordType.None;
            result.Add(Key, index);
            int count = LstItems.Count;
            int blank = MaxBlank;

BETIN:
            index++;
            if (index < data.Length)
            {
                char     key  = Utils.Cast(data[index]);
                CharItem item = null;
                if (count < 4)
                {
                    for (int i = 0; i < count; i++)
                    {
                        item = LstItems[i];
                        if (item.Key == key)
                        {
                            break;
                        }
                        else
                        {
                            item = null;
                        }
                    }
                }
                else
                {
                    Items.TryGetValue(key, out item);
                }
                if (item != null)
                {
                    result.Data    = data;
                    result.IsMatch = true;
                    result.Add(key, index);

                    if (!item.Eof)
                    {
                        item.Match(data, index + 1, result);
                    }
                }
                else
                {
                    if (blank > 0 && (WordType & Utils.GetWordTypeWithChar(key)) == 0 && key != '\0')
                    {
                        WordType chartype = Utils.GetWordTypeWithChar(key);
                        if (BlankType == KFilter.WordType.None)
                        {
                            BlankType = chartype;
                        }
                        else
                        {
                            if (BlankType != chartype)
                            {
                                blank--;
                            }
                            BlankType = chartype;
                        }
                        goto BETIN;
                    }
                }
            }
            Rule(result, data);

            return(result);
        }