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


C# StringSegment.Substring方法代码示例

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


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

示例1: StringSegment_Substring_InvalidOffsetAndLength

        public void StringSegment_Substring_InvalidOffsetAndLength()
        {
            // Arrange
            var segment = new StringSegment("Hello, World!", 1, 3);

            // Act & Assert
            Assert.Throws<ArgumentOutOfRangeException>(() => segment.Substring(2, 3));
        }
开发者ID:leloulight,项目名称:Common,代码行数:8,代码来源:StringSegmentTest.cs

示例2: StringSegment_Substring_Valid

        public void StringSegment_Substring_Valid()
        {
            // Arrange
            var segment = new StringSegment("Hello, World!", 1, 4);

            // Act
            var result = segment.Substring(offset: 1, length: 2);

            // Assert
            Assert.Equal("ll", result);
        }
开发者ID:leloulight,项目名称:Common,代码行数:11,代码来源:StringSegmentTest.cs

示例3: StringSegment_Substring_Invalid

        public void StringSegment_Substring_Invalid()
        {
            // Arrange
            var segment = new StringSegment();

            // Act & Assert
            Assert.Throws<ArgumentOutOfRangeException>(() => segment.Substring(0, 0));
        }
开发者ID:leloulight,项目名称:Common,代码行数:8,代码来源:StringSegmentTest.cs

示例4: ParseColor

        /// <summary>
        /// Parses a <see cref="Color"/> value from the specified string segment.
        /// </summary>
        private static Color ParseColor(StringSegment text)
        {
            if (text.Length != 8)
                throw new FormatException();

            var a = (Int32)GetHexNumberValue(text.Substring(0, 2));
            var r = (Int32)GetHexNumberValue(text.Substring(2, 2));
            var g = (Int32)GetHexNumberValue(text.Substring(4, 2));
            var b = (Int32)GetHexNumberValue(text.Substring(6, 2));

            return new Color(r, g, b, a);
        }
开发者ID:prshreshtha,项目名称:ultraviolet,代码行数:15,代码来源:TextLayoutEngine.cs

示例5: GetFittedSubstring

        /// <summary>
        /// Given a string and an available space, returns the largest substring which will fit within that space.
        /// </summary>
        private Boolean GetFittedSubstring(SpriteFontFace font, Int32 maxLineWidth, ref StringSegment tokenText, ref Size2 tokenSize, ref LayoutState state, Boolean hyphenate)
        {
            var substringAvailableWidth = maxLineWidth - state.PositionX;
            var substringWidth = 0;
            var substringLength = 0;

            for (int glyphIndex = 0; glyphIndex < tokenText.Length - 1; glyphIndex++)
            {
                var glyph1 = tokenText[glyphIndex];
                var glyph2 = tokenText[glyphIndex + 1];
                var glyphWidth = 0;

                if (hyphenate)
                {
                    glyphWidth = font.MeasureGlyph(glyph1, '-').Width + font.MeasureGlyph('-').Width;
                }
                else
                {
                    glyphWidth = font.MeasureGlyph(glyph1).Width;
                }

                if (substringAvailableWidth - glyphWidth < 0)
                    break;

                var glyphSize = font.MeasureGlyph(glyph1, glyph2);
                substringAvailableWidth -= glyphSize.Width;
                substringWidth += glyphSize.Width;
                substringLength++;
            }

            tokenText = substringLength > 0 ? tokenText.Substring(0, substringLength) : StringSegment.Empty;
            tokenSize = new Size2(substringWidth, tokenSize.Height);

            return substringLength > 0;
        }
开发者ID:prshreshtha,项目名称:ultraviolet,代码行数:38,代码来源:TextLayoutEngine.cs

示例6: ParseCommandToken

        /// <summary>
        /// Parses a command token.
        /// </summary>
        /// <param name="tokenText">The text associated with the lexer token.</param>
        /// <param name="sourceOffset">The offset of the first character in the source text that produced the token.</param>
        /// <param name="sourceLength">The number of characters in the source text that produced the token.</param>
        /// <returns>The parsed token.</returns>
        private static TextParserToken ParseCommandToken(StringSegment tokenText, Int32 sourceOffset, Int32 sourceLength)
        {
            // Toggle bold style.
            if (tokenText == "|b|")
            {
                return new TextParserToken(TextParserTokenType.ToggleBold, StringSegment.Empty, sourceOffset, sourceLength);
            }

            // Toggle italic style.
            if (tokenText == "|i|")
            {
                return new TextParserToken(TextParserTokenType.ToggleItalic, StringSegment.Empty, sourceOffset, sourceLength);
            }

            // Set the current color.
            if (tokenText.Length == 12 && tokenText.Substring(0, 3) == "|c:")
            {
                var hexcode = tokenText.Substring(3, 8);
                return new TextParserToken(TextParserTokenType.PushColor, hexcode, sourceOffset, sourceLength);
            }

            // Clear the current color.
            if (tokenText == "|c|")
            {
                return new TextParserToken(TextParserTokenType.PopColor, StringSegment.Empty, sourceOffset, sourceLength);
            }

            // Set the current font.
            if (tokenText.Length >= 8 && tokenText.Substring(0, 6) == "|font:")
            {
                var name = tokenText.Substring(6, tokenText.Length - 7);
                return new TextParserToken(TextParserTokenType.PushFont, name, sourceOffset, sourceLength);
            }

            // Clear the current font.
            if (tokenText == "|font|")
            {
                return new TextParserToken(TextParserTokenType.PopFont, StringSegment.Empty, sourceOffset, sourceLength);
            }

            // Set the current glyph shader.
            if (tokenText.Length >= 10 && tokenText.Substring(0, 8) == "|shader:")
            {
                var name = tokenText.Substring(8, tokenText.Length - 9);
                return new TextParserToken(TextParserTokenType.PushGlyphShader, name, sourceOffset, sourceLength);
            }

            // Clear the current glyph shader.
            if (tokenText == "|shader|")
            {
                return new TextParserToken(TextParserTokenType.PopGlyphShader, StringSegment.Empty, sourceOffset, sourceLength);
            }

            // Set the preset style.
            if (tokenText.Length >= 9 && tokenText.Substring(0, 7) == "|style:")
            {
                var name = tokenText.Substring(7, tokenText.Length - 8);
                return new TextParserToken(TextParserTokenType.PushStyle, name, sourceOffset, sourceLength);
            }

            // Clear the preset style.
            if (tokenText == "|style|")
            {
                return new TextParserToken(TextParserTokenType.PopStyle, StringSegment.Empty, sourceOffset, sourceLength);
            }

            // Emit an inline icon.
            if (tokenText.Length >= 8 && tokenText.Substring(0, 6) == "|icon:")
            {
                var name = tokenText.Substring(6, tokenText.Length - 7);
                return new TextParserToken(TextParserTokenType.Icon, name, sourceOffset, sourceLength);
            }

            // Unrecognized or invalid command.
            return new TextParserToken(TextParserTokenType.Text, tokenText, sourceOffset, sourceLength);
        }
开发者ID:prshreshtha,项目名称:ultraviolet,代码行数:83,代码来源:TextParser.cs

示例7: ParseColor

        /// <summary>
        /// Parses a <see cref="Color"/> value from the specified string segment.
        /// </summary>
        private static Color ParseColor(StringSegment text)
        {
            if (text.Length != 8)
                throw new FormatException();

            var a = StringSegmentConversion.ParseHexadecimalInt32(text.Substring(0, 2));
            var r = StringSegmentConversion.ParseHexadecimalInt32(text.Substring(2, 2));
            var g = StringSegmentConversion.ParseHexadecimalInt32(text.Substring(4, 2));
            var b = StringSegmentConversion.ParseHexadecimalInt32(text.Substring(6, 2));

            return new Color(r, g, b, a);
        }
开发者ID:RUSshy,项目名称:ultraviolet,代码行数:15,代码来源:TextLayoutEngine.cs

示例8: TestSubstringToEnd

 public void TestSubstringToEnd()
 {
     var segment = new StringSegment(TestContent);
     for (int i = 0; i < TestContent.Length; i++)
     {
         Assert.Equal(TestContent.Substring(i), segment.Substring(i));
     }
 }
开发者ID:DM-TOR,项目名称:nhin-d,代码行数:8,代码来源:StringSegmentFacts.cs

示例9: TestSubstring

 public void TestSubstring(string content)
 {
     int length = content.Length;
     var segment = new StringSegment(content);
     for (int i = 0; i < content.Length; i++)
     {
         Assert.Equal(content.Substring(0, i), segment.Substring(0, i));
         Assert.Equal(content.Substring(i, length - i), segment.Substring(i, length - i));
     }
 }
开发者ID:DM-TOR,项目名称:nhin-d,代码行数:10,代码来源:StringSegmentFacts.cs

示例10: ParseCommandToken

        /// <summary>
        /// Parses a command token.
        /// </summary>
        /// <param name="tokenText">The text associated with the lexer token.</param>
        /// <param name="sourceOffset">The offset of the first character in the source text that produced the token.</param>
        /// <param name="sourceLength">The number of characters in the source text that produced the token.</param>
        /// <returns>The parsed token.</returns>
        private static TextParserToken ParseCommandToken(StringSegment tokenText, Int32 sourceOffset, Int32 sourceLength)
        {
            // Toggle bold style.
            if (tokenText == "|b|")
            {
                return new TextParserToken(TextParserTokenType.ToggleBold, StringSegment.Empty, sourceOffset, sourceLength);
            }

            // Toggle italic style.
            if (tokenText == "|i|")
            {
                return new TextParserToken(TextParserTokenType.ToggleItalic, StringSegment.Empty, sourceOffset, sourceLength);
            }

            // Set the current color.
            if (tokenText.Length == 12 && tokenText.Substring(0, 3) == "|c:")
            {
                var hexcode = tokenText.Substring(3, 8);
                return new TextParserToken(TextParserTokenType.PushColor, hexcode, sourceOffset, sourceLength);
            }

            // Clear the current color.
            if (tokenText == "|c|")
            {
                return new TextParserToken(TextParserTokenType.PopColor, StringSegment.Empty, sourceOffset, sourceLength);
            }

            // Set the current font.
            if (tokenText.Length >= 8 && tokenText.Substring(0, 6) == "|font:")
            {
                var name = tokenText.Substring(6, tokenText.Length - 7);
                return new TextParserToken(TextParserTokenType.PushFont, name, sourceOffset, sourceLength);
            }

            // Clear the current font.
            if (tokenText == "|font|")
            {
                return new TextParserToken(TextParserTokenType.PopFont, StringSegment.Empty, sourceOffset, sourceLength);
            }

            // Set the current glyph shader.
            if (tokenText.Length >= 10 && tokenText.Substring(0, 8) == "|shader:")
            {
                var name = tokenText.Substring(8, tokenText.Length - 9);
                return new TextParserToken(TextParserTokenType.PushGlyphShader, name, sourceOffset, sourceLength);
            }

            // Clear the current glyph shader.
            if (tokenText == "|shader|")
            {
                return new TextParserToken(TextParserTokenType.PopGlyphShader, StringSegment.Empty, sourceOffset, sourceLength);
            }

            // Set the current link.
            if (tokenText.Length >= 8 && tokenText.Substring(0, 6) == "|link:")
            {
                var target = tokenText.Substring(6, tokenText.Length - 7);
                return new TextParserToken(TextParserTokenType.PushLink, target, sourceOffset, sourceLength);
            }

            // Clear the current link.
            if (tokenText == "|link|")
            {
                return new TextParserToken(TextParserTokenType.PopLink, StringSegment.Empty, sourceOffset, sourceLength);
            }

            // Set the preset style.
            if (tokenText.Length >= 9 && tokenText.Substring(0, 7) == "|style:")
            {
                var name = tokenText.Substring(7, tokenText.Length - 8);
                return new TextParserToken(TextParserTokenType.PushStyle, name, sourceOffset, sourceLength);
            }

            // Clear the preset style.
            if (tokenText == "|style|")
            {
                return new TextParserToken(TextParserTokenType.PopStyle, StringSegment.Empty, sourceOffset, sourceLength);
            }

            // Emit an inline icon.
            if (tokenText.Length >= 8 && tokenText.Substring(0, 6) == "|icon:")
            {
                var name = tokenText.Substring(6, tokenText.Length - 7);
                return new TextParserToken(TextParserTokenType.Icon, name, sourceOffset, sourceLength);
            }

            // Emit a custom command.
            lock (customCommands)
            {
                for (int i = customCommands.Count - 1; i >= 0; i--)
                {
                    var command = customCommands[i];
                    if (tokenText.Length >= 2 + command.Length && tokenText.Substring(1, command.Length) == command)
//.........这里部分代码省略.........
开发者ID:RUSshy,项目名称:ultraviolet,代码行数:101,代码来源:TextParser.cs


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