コード例 #1
0
        /// <summary>
        /// Reads a single escaped field data value from the source. The source must be currently positioned on the opening double quote of the field data. On return, the source is either at the end of the input or is positioned on the first character that is not part of the field data (past the closing double quote).
        /// </summary>
        /// <param name="source">The source from which to read.</param>
        /// <returns>The field data value.</returns>
        private string ReadEscapedFieldValue(EnumeratorWrapper <char> source)
        {
            var sb = new StringBuilder();

            // Consume the '\"' character.
            source.MoveNext();

            while (source.More)
            {
                var ch = source.Current;
                if (ch == '\"')
                {
                    // A '\"' character within escaped field data may be the end of the escaped field data or it may be the first character of a 2DQUOTE escape sequence.
                    source.MoveNext();
                    if (source.Done || source.Current != '\"')
                    {
                        // The '\"' was the end of the escaped field data.
                        return(sb.ToString());
                    }
                }

                // Consume the next character of the field data.
                sb.Append(ch);
                source.MoveNext();
            }

            // The while loop was exited by reaching the end of the source sequence, so publish the last FieldData token (with a warning, since the ending double quote was never found).
            Warning("Lexer: Last entry in file is not complete; check for file truncation.");
            return(sb.ToString());
        }
コード例 #2
0
        /// <summary>
        /// Reads a single unescaped field data value from the source. The source must be currently positioned on the first character of the field data. On return, the source is either at the end of the input or is positioned on the first character that is not part of the field data.
        /// </summary>
        /// <param name="source">The source from which to read.</param>
        /// <returns>The field data value.</returns>
        private string ReadUnescapedFieldValue(EnumeratorWrapper <char> source)
        {
            var sb = new StringBuilder();

            // Consume the first character of the field data.
            sb.Append(source.Current);
            source.MoveNext();

            while (source.More)
            {
                var ch = source.Current;
                if (ch == this.fieldSeparator || ch == '\r' || ch == '\n')
                {
                    // Unescaped field data can be terminated by a FieldSeparator or EndOfRecord.
                    // Publish the FieldData token, but do not consume the characters for the FieldSeparator or EndOfRecord tokens.
                    return(sb.ToString());
                }

                // Consume the next character of the field data.
                sb.Append(ch);
                source.MoveNext();
            }

            // The while loop was exited by reaching the end of the source sequence, so publish the last FieldData token.
            return(sb.ToString());
        }
コード例 #3
0
        public void IterationTest()
        {
            var testValues = new[] {1, 2, 3};

            var enumerator = new List<int>(testValues.ToArray()).GetEnumerator();

            using(var enumeratorWrapper = new EnumeratorWrapper<string>(enumerator, value => value.ToString()))
            {
                foreach(var testValue in testValues)
                {
                    enumeratorWrapper.MoveNext();

                    Assert.AreEqual(testValue.ToString(CultureInfo.InvariantCulture), enumeratorWrapper.Current);
                }
            }
        }