public void CharIteration()
        {
            IStringEnumerator e = new CharEnumeratorEx("abcd");
            int i = 0;

            while (e.MoveNext())
            {
                switch (i)
                {
                case 0:
                    Assert.AreEqual("a", e.Current);
                    Assert.AreEqual("b", e.Next);
                    Assert.AreEqual("bcd", e.GetRemainingFromNext());
                    Assert.IsFalse(e.IsLast);
                    break;

                case 1:
                    Assert.AreEqual("b", e.Current);
                    Assert.AreEqual("c", e.Next);
                    Assert.AreEqual("cd", e.GetRemainingFromNext());
                    Assert.IsFalse(e.IsLast);
                    break;

                case 2:
                    Assert.AreEqual("c", e.Current);
                    Assert.AreEqual("d", e.Next);
                    Assert.AreEqual("d", e.GetRemainingFromNext());
                    Assert.IsFalse(e.IsLast);
                    break;

                case 3:
                    Assert.AreEqual("d", e.Current);
                    Assert.IsTrue(e.IsLast);
                    break;
                }
                i++;
            }
        }
        public sealed override ParserState Parse(IStringEnumerator argumentEnumerator, IOptionMap map, object options)
        {
            IStringEnumerator group = new CharEnumeratorEx(argumentEnumerator.Current.Substring(1));

            while (group.MoveNext())
            {
                OptionInfo option = map[group.Current];
                if (option == null)
                {
                    return(ParserState.Failure);
                }

                option.IsDefined = true;

                if (!option.IsBoolean)
                {
                    if (argumentEnumerator.IsLast && group.IsLast)
                    {
                        return(ParserState.Failure);
                    }

                    if (!group.IsLast)
                    {
                        if (option.SetValue(group.GetRemainingFromNext(), options))
                        {
                            return(ParserState.Success);
                        }
                        else
                        {
                            return(ParserState.Failure);
                        }
                    }

                    if (!argumentEnumerator.IsLast && !ArgumentParser.IsInputValue(argumentEnumerator.Next))
                    {
                        return(ParserState.Failure);
                    }
                    else
                    {
                        if (option.SetValue(argumentEnumerator.Next, options))
                        {
                            return(ParserState.Success | ParserState.MoveOnNextElement);
                        }
                        else
                        {
                            return(ParserState.Failure);
                        }
                    }
                }
                else
                {
                    if (!group.IsLast && map[group.Next] == null)
                    {
                        return(ParserState.Failure);
                    }
                    if (!option.SetValue(true, options))
                    {
                        return(ParserState.Failure);
                    }
                }
            }
            return(ParserState.Success);
        }
Esempio n. 3
0
        public override sealed ParserState Parse(IStringEnumerator argumentEnumerator, IOptionMap map, object options)
        {
            IStringEnumerator group = new CharEnumeratorEx(argumentEnumerator.Current.Substring(1));
            while (group.MoveNext())
            {
                OptionInfo option = map[group.Current];
                if (option == null)
                {
                    return ParserState.Failure;
                }

                option.IsDefined = true;

                if (!option.IsBoolean)
                {
                    if (argumentEnumerator.IsLast && group.IsLast)
                    {
                        return ParserState.Failure;
                    }

                    if (!group.IsLast)
                    {
                        if (option.SetValue(group.GetRemainingFromNext(), options))
                        {
                            return ParserState.Success;
                        }
                        else
                        {
                            return ParserState.Failure;
                        }
                    }

                    if (!argumentEnumerator.IsLast && !ArgumentParser.IsInputValue(argumentEnumerator.Next))
                    {
                        return ParserState.Failure;
                    }
                    else
                    {
                        if (option.SetValue(argumentEnumerator.Next, options))
                        {
                            return ParserState.Success | ParserState.MoveOnNextElement;
                        }
                        else
                        {
                            return ParserState.Failure;
                        }
                    }
                }
                else
                {
                    if (!group.IsLast && map[group.Next] == null)
                    {
                        return ParserState.Failure;
                    }
                    if (!option.SetValue(true, options))
                    {
                        return ParserState.Failure;
                    }
                }
            }
            return ParserState.Success;
        }