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


C# StringParser.String方法代码示例

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


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

示例1: 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

示例2: HelloOrHello_StringParsing

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

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

示例3: 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

示例4: 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

示例5: Should_return_the_greediest_position_that_did_not_match

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

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

            var result = parser.ParseString("Hello");

            Assert.IsFalse(result.HasValue);

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

示例6: Should_skip_until_the_longest_is_found

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

            var p = new StringParser();

            Parser<string, string> parser = from x in p.SkipUntil(p.Longest(p.String("Hello"), p.String("Hello World")))
                                           select x;

            var result = parser.ParseString(subject);

            Assert.IsTrue(result.HasValue);

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

示例7: 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

示例8: HelloStringParsing

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

            _parser = from x in sp.String("Hello")
                      select x;
        }
开发者ID:modulexcite,项目名称:Parsnip,代码行数:7,代码来源:HelloStringParsing.cs

示例9: Should_not_match_if_the_peeked_value_not_matched

        public void Should_not_match_if_the_peeked_value_not_matched()
        {
            string subject = "0123456789";

            var p = new StringParser();

            var parser = from ws in p.String("01")
                         from peeked in p.String("789").Peek()
                         from value in p.String("234")
                         select new {peeked, value};

            var result = parser.ParseString(subject);

            Assert.IsFalse(result.HasValue, "Pattern should not matched");

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

示例10: Should_not_advance_the_input_itself

        public void Should_not_advance_the_input_itself()
        {
            string subject = "0123456789";

            var p = new StringParser();

            var parser = from ws in p.String("01")
                         from peeked in p.String("234").Peek()
                         from value in p.String("234")
                         select new {peeked, value};

            var result = parser.ParseString(subject);

            Assert.IsTrue(result.HasValue);

            Assert.AreEqual(result.Value.peeked, result.Value.value);
        }
开发者ID:modulexcite,项目名称:Parsnip,代码行数:17,代码来源:Peek_Specs.cs

示例11: Should_skip_until_the_world

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

            var p = new StringParser();

            var parser = from x in p.Skip(p.String("World"))
                                            from y in p.String("World")
                                           select new {x, y};

            var result = parser.ParseString(subject);

            Assert.IsTrue(result.HasValue);

            Assert.AreEqual("Hello ".ToCharArray(), result.Value.x);
            Assert.AreEqual("World", result.Value.y);
        }
开发者ID:modulexcite,项目名称:Parsnip,代码行数:17,代码来源:Greedy_Specs.cs

示例12: Hello_StringParsing

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

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

示例13: 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

示例14: Should_work

        public void Should_work()
        {
            string source = "ABC123";

            var sp = new StringParser();

            Parser<string, string> letters = from x in sp.String("ABC")
                                             select x;

            Parser<string, string> numbers = from x in sp.String("123")
                                             select x;

            var input = new StringInput(source);

            var lr = letters.Parse(input);
            Assert.IsTrue(lr.HasValue, "Should have letter value");

            var nr = numbers.Parse(lr.Next);
            Assert.IsTrue(nr.HasValue, "Should have number value");
        }
开发者ID:modulexcite,项目名称:Parsnip,代码行数:20,代码来源:Match_Specs.cs

示例15: 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


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