当前位置: 首页>>代码示例>>C#>>正文


C# StringParser.Whitespace方法代码示例

本文整理汇总了C#中StringParser.Whitespace方法的典型用法代码示例。如果您正苦于以下问题:C# StringParser.Whitespace方法的具体用法?C# StringParser.Whitespace怎么用?C# StringParser.Whitespace使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在StringParser的用法示例。


在下文中一共展示了StringParser.Whitespace方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CommandLineParser

            public CommandLineParser()
            {
                var p = new StringParser();

                Id = from ws in p.SkipWhitespace()
                     from c in p.Char(char.IsLetter)
                     from cs in p.Char(char.IsLetterOrDigit).ZeroOrMore()
                     select new string(c, 1) + new string(cs);

                Key = from ws in p.SkipWhitespace()
                     from c in p.Char(char.IsLetter)
                     from cs in (p.Char(char.IsLetterOrDigit).Or(p.Char('.'))).ZeroOrMore()
                     select new string(c, 1) + new string(cs);

                //                Value = from v in (p.Char(x => !char.IsWhiteSpace(x))).ZeroOrMore()
                //                        select new string(v);
                Value = from v in (p.Char().Except(p.Whitespace())).ZeroOrMore()
                        select new string(v);

                Definition = (from ws in p.SkipWhitespace()
                              from c in p.Char('-', '/')
                              from id in Id
                              from eq in p.Char(':', '=')
                              from v in Value
                              select new Definition(id, v));
            }
开发者ID:modulexcite,项目名称:Parsnip,代码行数:26,代码来源:CommandLine_Spcs.cs

示例2: Should_choose_the_greediest_one

        public void Should_choose_the_greediest_one()
        {
            string subject = "Hello, World";

            var p = new StringParser();

            Parser<string, string> first = from x in p.String("Hello")
                                           select x;

            Assert.IsTrue(first.ParseString(subject).HasValue, "First did not match");

            Parser<string, string> second = from x in p.String("Hello")
                                            from y in p.Char(',')
                                            from ws in p.Whitespace()
                                            from z in p.String("World")
                                            select x + z;

            Assert.IsTrue(second.ParseString(subject).HasValue, "Second did not match");

            Parser<string, string> parser = p.Longest(first, second);

            Result<string, string> result = parser.ParseString(subject);

            Assert.IsTrue(result.HasValue, "Neither matched");

            Assert.AreEqual("HelloWorld", result.Value, "Longest parser should have matched");
        }
开发者ID:modulexcite,项目名称:Parsnip,代码行数:27,代码来源:Greedy_Specs.cs

示例3: Hello__StringParsing

        public Hello__StringParsing()
        {
            var sp = new StringParser();

            _parser = from x in sp.String("Hello")
                      from y in sp.Char(',')
                      from z in sp.Whitespace()
                      select x;
        }
开发者ID:modulexcite,项目名称:Parsnip,代码行数:9,代码来源:Hello__StringParsing.cs

示例4: Hello__WorldStringParsing

        public Hello__WorldStringParsing()
        {
            var sp = new StringParser();

            _parser = from hello in sp.String("Hello")
                      from comma in sp.Char(',')
                      from ws in sp.Whitespace()
                      from world in sp.String("World")
                      select hello;
        }
开发者ID:modulexcite,项目名称:Parsnip,代码行数:10,代码来源:Hello__WorldStringParsing.cs

示例5: Hello__World___StringParsing

        public Hello__World___StringParsing()
        {
            var sp = new StringParser();

            _parser = from hello in sp.String("Hello")
                      from comma in sp.Char(',')
                      from ws in sp.Whitespace()
                      from world in sp.String("World")
                      from period in sp.Char('.')
                      from nl in sp.NewLine()
                      select hello;
        }
开发者ID:modulexcite,项目名称:Parsnip,代码行数:12,代码来源:Hello__World___StringParsing.cs

示例6: Should_match_a_series_of_integers

        public void Should_match_a_series_of_integers()
        {
            string text = "123 456 789";

            var p = new StringParser();

            var parser = from a in p.Int32()
                         from ws in p.Whitespace()
                         from b in p.Int32()
                         from ws2 in p.Whitespace()
                         from c in p.Int32()
                         select new {a, b, c};

            var result = parser.ParseString(text);

            Assert.IsTrue(result.HasValue);

            Assert.AreEqual(123, result.Value.a);
            Assert.AreEqual(456, result.Value.b);
            Assert.AreEqual(789, result.Value.c);
        }
开发者ID:modulexcite,项目名称:Parsnip,代码行数:21,代码来源:ValueType_Specs.cs

示例7: Should_select_all_whitespace_before_value

        public void Should_select_all_whitespace_before_value()
        {
            string subject = "   \t\r\n\tHello";

            var p = new StringParser();

            var parser = from ws in p.Whitespace()
                         from value in p.String("Hello")
                         select value;

            var result = parser.ParseString(subject);

            Assert.IsTrue(result.HasValue);
        }
开发者ID:modulexcite,项目名称:Parsnip,代码行数:14,代码来源:Char_Specs.cs

示例8: Should_return_the_greediest_position_that_did_not_match_including_whitespace

        public void Should_return_the_greediest_position_that_did_not_match_including_whitespace()
        {
            var sp = new StringParser();

            var parser = from x in sp.String("Hello")
                         from _ in sp.Whitespace()
                         from y in sp.String("World")
                         select y;

            var result = parser.ParseString("Hello\t W0rld");

            Assert.IsFalse(result.HasValue);

            Assert.AreEqual(7, result.Next.Offset);
        }
开发者ID:modulexcite,项目名称:Parsnip,代码行数:15,代码来源:Position_Specs.cs

示例9: Should_capture_sequential_items

        public void Should_capture_sequential_items()
        {
            string subject = "Hello World";

            var p = new StringParser();

            Parser<string, string> parser = from x in p.String("Hello")
                                           from y in p.Whitespace().Then(p.String("World"))
                                           select x + y;

            var result = parser.ParseString(subject);

            Assert.IsTrue(result.HasValue);

            Assert.AreEqual("HelloWorld", result.Value);
        }
开发者ID:modulexcite,项目名称:Parsnip,代码行数:16,代码来源:Greedy_Specs.cs


注:本文中的StringParser.Whitespace方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。