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


C# IStringReader.ReadNext方法代码示例

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


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

示例1: VerifyReadingSimpleText

        private static void VerifyReadingSimpleText(IStringReader reader)
        {
            Assert.IsNotNull(reader);

            // read first line:
            var c = reader.ReadNext();
            Assert.AreEqual('a', c);
            Assert.AreEqual('a', reader.CurrentChar);
            Assert.AreEqual(0, reader.Line);
            Assert.AreEqual(0, reader.LineOffset);
            Assert.IsFalse(reader.IsEmpty);

            c = reader.ReadNext();
            Assert.AreEqual('\r', c);
            Assert.AreEqual(0, reader.Line);
            Assert.AreEqual(1, reader.LineOffset);
            Assert.IsFalse(reader.IsEmpty);

            c = reader.ReadNext();
            Assert.AreEqual('\n', c);
            Assert.AreEqual('\n', reader.CurrentChar);
            Assert.AreEqual(0, reader.Line);
            Assert.AreEqual(2, reader.LineOffset);
            Assert.IsFalse(reader.IsEmpty);

            c = reader.ReadNext();
            Assert.AreEqual('b', c);
            Assert.AreEqual('b', reader.CurrentChar);
            Assert.AreEqual(1, reader.Line);
            Assert.AreEqual(0, reader.LineOffset);
            Assert.IsFalse(reader.IsEmpty);

            c = reader.ReadNext();
            Assert.AreEqual('\r', c);
            Assert.AreEqual('\r', reader.CurrentChar);
            Assert.AreEqual(1, reader.Line);
            Assert.AreEqual(1, reader.LineOffset);
            Assert.IsFalse(reader.IsEmpty);

            c = reader.ReadNext();
            Assert.AreEqual('\n', c);
            Assert.AreEqual('\n', reader.CurrentChar);
            Assert.AreEqual(1, reader.Line);
            Assert.AreEqual(2, reader.LineOffset);
            Assert.IsFalse(reader.IsEof);
            Assert.IsFalse(reader.IsEmpty);

            c = reader.ReadNext();
            Assert.AreEqual('\0', c);
            Assert.AreEqual('\0', reader.CurrentChar);
            Assert.AreEqual(2, reader.Line);
            Assert.AreEqual(-1, reader.LineOffset);
            Assert.IsTrue(reader.IsEof);
            Assert.IsFalse(reader.IsEmpty);
        }
开发者ID:phofman,项目名称:codetitans-libs,代码行数:55,代码来源:StringReaderTests.cs

示例2: ReadCommentChars

        internal static StringHelperStatusCode ReadCommentChars(IStringReader reader, bool multiline)
        {
            if (multiline)
            {
                char previousChar;
                char currentChar = '\0';
                do
                {
                    previousChar = currentChar;
                    currentChar = reader.ReadNext();

                    if (reader.IsEof)
                        return StringHelperStatusCode.UnexpectedEoF;

                    if (previousChar == '*' && currentChar == '/')
                        return StringHelperStatusCode.Success;
                }
                while (true);
            }
            else
            {
                do
                {
                    var currentChar = reader.ReadNext();

                    if (reader.IsEof)
                        return StringHelperStatusCode.UnexpectedEoF;

                    if (currentChar == '\r' || currentChar == '\n')
                        return StringHelperStatusCode.Success;
                }
                while (true);
            }
        }
开发者ID:phofman,项目名称:codetitans-libs,代码行数:34,代码来源:StringHelper.cs

示例3: ReadKeywordChars

        /// <summary>
        /// Reads the keyword definition chars from given input.
        /// </summary>
        internal static StringHelperStatusCode ReadKeywordChars(IStringReader reader, StringBuilder output)
        {
            do
            {
                var currentChar = reader.ReadNext();

                if (char.IsLetter(currentChar))
                {
                    output.Append(currentChar);
                }
                else
                    break;
            }
            while (true);

            return StringHelperStatusCode.Success;
        }
开发者ID:phofman,项目名称:codetitans-libs,代码行数:20,代码来源:StringHelper.cs

示例4: ReadStringChars

        /// <summary>
        /// Reads the string from given input stream.
        /// </summary>
        internal static StringHelperStatusCode ReadStringChars(IStringReader reader, StringBuilder output, StringBuilder escapedUnicodeNumberBuffer, bool errorOnNewLine, out int lastLine, out int lastOffset)
        {
            bool escape = false;
            bool unicodeNumber = false;

            if (escapedUnicodeNumberBuffer == null)
                escapedUnicodeNumberBuffer = new StringBuilder();

            lastLine = reader.Line;
            lastOffset = reader.LineOffset;

            do
            {
                if (!unicodeNumber)
                {
                    lastLine = reader.Line;
                    lastOffset = reader.LineOffset;
                }

                var currentChar = reader.ReadNext();

                // verify if not an invalid character was found in text:
                if (reader.IsEof)
                    return StringHelperStatusCode.UnexpectedEoF;
                if (errorOnNewLine && (currentChar == '\r' || currentChar == '\n'))
                    return StringHelperStatusCode.UnexpectedNewLine;

                if (unicodeNumber)
                {
                    StringHelperStatusCode result = ReadStringUnicodeCharacter(currentChar, output, escapedUnicodeNumberBuffer, out unicodeNumber);

                    // if parsing Unicode character failed, immediatelly stop!
                    if (result != StringHelperStatusCode.Success)
                        return result;

                    continue;
                }

                if (currentChar == '\\' && !escape)
                {
                    escape = true;
                }
                else
                {
                    if (escape)
                    {
                        switch (currentChar)
                        {
                            case 'n':
                                output.Append('\n');
                                break;
                            case 'r':
                                output.Append('\r');
                                break;
                            case 't':
                                output.Append('\t');
                                break;
                            case '/':
                                output.Append('/');
                                break;
                            case '\\':
                                output.Append('\\');
                                break;
                            case 'f':
                                output.Append('\f');
                                break;
                            case 'U':
                            case 'u':
                                unicodeNumber = true;
                                break;
                            case '"':
                                output.Append('"');
                                break;
                            case '\'':
                                output.Append('\'');
                                break;
                            default:
                                return StringHelperStatusCode.UnknownEscapedChar;
                        }

                        escape = false;
                    }
                    else
                    {
                        if (currentChar == '"')
                            break;

                        output.Append(currentChar);
                    }
                }
            }
            while (true);

            // as the string might finish with a Unicode character...
            if (unicodeNumber)
                return AddUnicodeChar(output, escapedUnicodeNumberBuffer, false);

//.........这里部分代码省略.........
开发者ID:phofman,项目名称:codetitans-libs,代码行数:101,代码来源:StringHelper.cs

示例5: ReadIntegerNumberChars

        /// <summary>
        /// Reads characters that might be a number and copies them to given output.
        /// </summary>
        internal static StringHelperStatusCode ReadIntegerNumberChars(IStringReader reader, StringBuilder output)
        {
            do
            {
                var currentChar = reader.ReadNext();

                if (char.IsDigit(currentChar) || currentChar == '-' || currentChar == '+')
                {
                    output.Append(currentChar);
                }
                else
                    break;
            }
            while (true);

            return StringHelperStatusCode.Success;
        }
开发者ID:phofman,项目名称:codetitans-libs,代码行数:20,代码来源:StringHelper.cs

示例6: ReadWhiteChars

        /// <summary>
        /// Reads from the current input stream all the whitespaces.
        /// </summary>
        internal static StringHelperStatusCode ReadWhiteChars(IStringReader reader, out int count)
        {
            count = 0;

            do
            {
                char currentChar = reader.ReadNext();

                if (reader.IsEof)
                    return StringHelperStatusCode.UnexpectedEoF;

                if (!char.IsWhiteSpace(currentChar))
                    break;

                count++;
            }
            while (true);

            return StringHelperStatusCode.Success;
        }
开发者ID:phofman,项目名称:codetitans-libs,代码行数:23,代码来源:StringHelper.cs


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