Ejemplo n.º 1
0
        public MatchItem Match(char[] data, int index)
        {
            MatchItem result = MatchItem;

            BlankType = Cactus.KAnalyze.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 == Cactus.KAnalyze.WordType.None)
                        {
                            BlankType = chartype;
                        }
                        else
                        {
                            if (BlankType != chartype)
                            {
                                blank--;
                            }
                            BlankType = chartype;
                        }
                        goto BETIN;
                    }
                }
            }
            Rule(result, data);

            return(result);
        }
Ejemplo n.º 2
0
        public void Match(char[] data, int start, MatchItem result)
        {
            BlankType = Cactus.KAnalyze.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 == Cactus.KAnalyze.WordType.None)
                    {
                        BlankType = chartype;
                    }
                    else
                    {
                        if (BlankType != chartype)
                        {
                            blank--;
                        }
                        BlankType = chartype;
                    }
                    start++;
                    goto BETIN;
                }
                result.IsMatch = false;
            }
        }