當前位置: 首頁>>代碼示例>>C#>>正文


C# Text.Advance方法代碼示例

本文整理匯總了C#中Text.Advance方法的典型用法代碼示例。如果您正苦於以下問題:C# Text.Advance方法的具體用法?C# Text.Advance怎麽用?C# Text.Advance使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Text的用法示例。


在下文中一共展示了Text.Advance方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: CanGetCurrentPosition

        public void CanGetCurrentPosition()
        {
            var empty = new Text("");
            empty.Advance(0).Position.ShouldBe(new Position(1, 1));
            empty.Advance(1).Position.ShouldBe(new Position(1, 1));

            var lines = new StringBuilder()
                .AppendLine("Line 1")//Index 0-5, \n
                .AppendLine("Line 2")//Index 7-12, \n
                .AppendLine("Line 3");//Index 14-19, \n
            var list = new Text(lines.ToString());

            list.Advance(0).Position.ShouldBe(new Position(1, 1));
            list.Advance(5).Position.ShouldBe(new Position(1, 6));
            list.Advance(6).Position.ShouldBe(new Position(1, 7));

            list.Advance(7).Position.ShouldBe(new Position(2, 1));
            list.Advance(12).Position.ShouldBe(new Position(2, 6));
            list.Advance(13).Position.ShouldBe(new Position(2, 7));

            list.Advance(14).Position.ShouldBe(new Position(3, 1));
            list.Advance(19).Position.ShouldBe(new Position(3, 6));
            list.Advance(20).Position.ShouldBe(new Position(3, 7));

            list.Advance(21).Position.ShouldBe(new Position(4, 1));
            list.Advance(1000).Position.ShouldBe(new Position(4, 1));
        }
開發者ID:plioi,項目名稱:parsley,代碼行數:27,代碼來源:TextTests.cs

示例2: CanMatchLeadingCharactersByPredicate

        public void CanMatchLeadingCharactersByPredicate()
        {
            Predicate<char> letters = Char.IsLetter;
            Predicate<char> digits = Char.IsDigit;
            Predicate<char> alphanumerics = Char.IsLetterOrDigit;

            var empty = new Text("");
            empty.Match(letters).ShouldFail();

            var abc123 = new Text("abc123");
            abc123.Match(digits).ShouldFail();
            abc123.Match(letters).ShouldSucceed("abc");
            abc123.Match(alphanumerics).ShouldSucceed("abc123");

            abc123.Advance(2).Match(digits).ShouldFail();
            abc123.Advance(2).Match(letters).ShouldSucceed("c");
            abc123.Advance(2).Match(alphanumerics).ShouldSucceed("c123");

            abc123.Advance(3).Match(digits).ShouldSucceed("123");
            abc123.Advance(3).Match(letters).ShouldFail();
            abc123.Advance(3).Match(alphanumerics).ShouldSucceed("123");

            abc123.Advance(6).Match(digits).ShouldFail();
            abc123.Advance(6).Match(letters).ShouldFail();
            abc123.Advance(6).Match(alphanumerics).ShouldFail();
        }
開發者ID:plioi,項目名稱:parsley,代碼行數:26,代碼來源:TextTests.cs

示例3: CanAdvanceAheadNCharacters

        public void CanAdvanceAheadNCharacters()
        {
            var empty = new Text("");
            empty.Advance(0).ToString().ShouldBe("");
            empty.Advance(1).ToString().ShouldBe("");

            var abc = new Text("abc");
            abc.Advance(0).ToString().ShouldBe("abc");
            abc.Advance(1).ToString().ShouldBe("bc");
            abc.Advance(2).ToString().ShouldBe("c");
            abc.Advance(3).ToString().ShouldBe("");
            abc.Advance(4).ToString().ShouldBe("");
            abc.Advance(100).ToString().ShouldBe("");
        }
開發者ID:plioi,項目名稱:parsley,代碼行數:14,代碼來源:TextTests.cs

示例4: CanMatchLeadingCharactersByTokenRegex

        public void CanMatchLeadingCharactersByTokenRegex()
        {
            var end = new TokenRegex(@"$");
            var letters = new TokenRegex(@"[a-z]+");
            var digits = new TokenRegex(@"[0-9]+");
            var alphanumerics = new TokenRegex(@"[a-z0-9]+");

            var empty = new Text("");
            empty.Match(letters).ShouldFail();
            empty.Match(end).ShouldSucceed("");

            var abc123 = new Text("abc123");
            abc123.Match(digits).ShouldFail();
            abc123.Match(letters).ShouldSucceed("abc");
            abc123.Match(alphanumerics).ShouldSucceed("abc123");

            abc123.Advance(2).Match(digits).ShouldFail();
            abc123.Advance(2).Match(letters).ShouldSucceed("c");
            abc123.Advance(2).Match(alphanumerics).ShouldSucceed("c123");

            abc123.Advance(3).Match(digits).ShouldSucceed("123");
            abc123.Advance(3).Match(letters).ShouldFail();
            abc123.Advance(3).Match(alphanumerics).ShouldSucceed("123");

            abc123.Advance(6).Match(digits).ShouldFail();
            abc123.Advance(6).Match(letters).ShouldFail();
            abc123.Advance(6).Match(alphanumerics).ShouldFail();
        }
開發者ID:plioi,項目名稱:parsley,代碼行數:28,代碼來源:TextTests.cs


注:本文中的Text.Advance方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。