Exemple #1
0
        public void Add(string value, int start, WordItem wi)
        {
            if (start < value.Length)
            {
                char key = Utils.Cast(value[start]);

                CharItem item = null;
                if (!Items.TryGetValue(key, out item))
                {
                    item           = new CharItem(key);
                    item.WordType |= wi.Type;
                    item.MaxBlank  = MaxBlank;
                    Items.Add(key, item);
                    LstItems.Add(item);
                }
                if (start + 1 == value.Length)
                {
                    item.Eof = true;
                }
                else
                {
                    item.Add(value, start + 1, wi);
                }
            }
        }
Exemple #2
0
        public void Add(string value)
        {
            int  index = 1;
            char key   = Utils.Cast(value[index]);

            WordItem wi = new WordItem(value);

            WordType = WordType | wi.Type;

            CharItem item = null;

            if (!Items.TryGetValue(key, out item))
            {
                item           = new CharItem(key);
                item.MaxBlank  = MaxBlank;
                item.WordType |= wi.Type;
                Items.Add(key, item);
                LstItems.Add(item);
            }
            if (index + 1 == value.Length)
            {
                item.Eof = true;
            }
            else
            {
                item.Add(value, index + 1, wi);
            }
        }
Exemple #3
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;
            }
        }
Exemple #4
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);
        }