コード例 #1
0
        /// <summary>
        /// Return the EncodedLine Segments in the given segment
        /// </summary>
        /// <param name="segment">Segment to parse</param>
        /// <returns>An enumeration of <see cref="EncodedLine"/></returns>
        public static IEnumerable <EncodedLine> ReadLines(StringSegment segment)
        {
            CharReader reader     = new CharReader(segment);
            int        startIndex = reader.Position + 1;
            int        endIndex   = startIndex - 1;
            char       ch;

            while ((ch = reader.Read()) != CharReader.EOF)
            {
                switch (ch)
                {
                default:
                    endIndex = reader.Position;
                    break;

                case MimeStandard.CR:
                    if (reader.Read() != MimeStandard.LF)
                    {
                        throw new MimeException(MimeError.InvalidCRLF);
                    }

                    yield return(LineFromSegment(reader.GetSegment(startIndex, endIndex), true));

                    startIndex = reader.Position + 1;
                    endIndex   = reader.Position;
                    break;
                }
            }

            if (endIndex >= startIndex)
            {
                yield return(LineFromSegment(reader.GetSegment(startIndex, endIndex), false));
            }
        }
コード例 #2
0
ファイル: CharReaderFacts.cs プロジェクト: DM-TOR/nhin-d
 public void CharReaderShouldReadCharacters()
 {
     string source = "abc";
     CharReader reader = new CharReader(source);
     Assert.False(reader.IsDone);
     Assert.Equal('a', reader.Read());
     Assert.Equal('b', reader.Read());
     Assert.Equal('c', reader.Read());
     Assert.Equal(CharReader.EOF, reader.Read());
     Assert.True(reader.IsDone);
 }
コード例 #3
0
ファイル: MimeParser.cs プロジェクト: blinds52/nhind
        /// <summary>
        /// Advances the start position of <paramref name="text"/> to the first non-whitespace position
        /// </summary>
        /// <param name="text">The <see cref="StringSegment"/> potentially containing initial whitepace</param>
        /// <returns>A <see cref="StringSegment"/> with no intial whitespace (possibly an empty segment if the <paramref name="text"/> was empty or all whitespace)</returns>
        public static StringSegment SkipWhitespace(StringSegment text)
        {
            CharReader reader = new CharReader(text);
            char       ch;

            while ((ch = reader.Read()) != CharReader.EOF && MimeStandard.IsWhitespace(ch))
            {
                // quick skip
            }

            return(new StringSegment(text.Source, reader.Position, text.EndIndex));
        }
コード例 #4
0
ファイル: MimeParser.cs プロジェクト: blinds52/nhind
        /// <summary>
        /// Breaks the supplied <paramref name="entity"/> into constituent lines by CRLF.
        /// </summary>
        /// <param name="entity">The entity to parse into lines.</param>
        /// <returns>An enumeration of <see cref="StringSegment"/> instances, one for each parsed line</returns>
        public static IEnumerable <StringSegment> ReadLines(StringSegment entity)
        {
            CharReader reader     = new CharReader(entity);
            int        startIndex = reader.Position + 1;
            int        endIndex   = startIndex - 1;
            char       ch;

            while ((ch = reader.Read()) != CharReader.EOF)
            {
                switch (ch)
                {
                default:
                    endIndex = reader.Position;
                    break;

                case MimeStandard.CR:
                    //
                    // RFC 2822 mandates that CRLF be together always
                    //
                    if (reader.Read() != MimeStandard.LF)
                    {
                        throw new MimeException(MimeError.InvalidCRLF);
                    }

                    yield return(reader.GetSegment(startIndex, endIndex));

                    startIndex = reader.Position + 1;
                    endIndex   = reader.Position;
                    break;
                }
            }

            if (endIndex >= 0)
            {
                yield return(reader.GetSegment(startIndex, endIndex));
            }
        }
コード例 #5
0
        IEnumerable <char> DecodeLine()
        {
            m_lineReader = new CharReader(m_currentLine.Text);
            char ch;

            while ((ch = m_lineReader.Read()) != CharReader.EOF)
            {
                if (ch != EncodingChar)
                {
                    yield return(ch);
                }
                else
                {
                    char decodedChar = this.DecodeChar();
                    if (decodedChar != char.MinValue)
                    {
                        yield return(decodedChar);
                    }
                }
            }
        }
コード例 #6
0
        /// <summary>
        /// Return the EncodedLine Segments in the given segment
        /// </summary>
        /// <param name="segment">Segment to parse</param>
        /// <returns>An enumeration of <see cref="EncodedLine"/></returns>
        public static IEnumerable<EncodedLine> ReadLines(StringSegment segment)
        {
            CharReader reader = new CharReader(segment);
            int startIndex = reader.Position + 1;
            int endIndex = startIndex - 1;
            char ch;

            while ((ch = reader.Read()) != CharReader.EOF)
            {
                switch (ch)
                {
                    default:
                        endIndex = reader.Position;
                        break;

                    case MimeStandard.CR:
                        if (reader.Read() != MimeStandard.LF)
                        {
                            throw new MimeException(MimeError.InvalidCRLF);
                        }
                        
                        yield return LineFromSegment(reader.GetSegment(startIndex, endIndex), true);
                        startIndex = reader.Position + 1;
                        endIndex = reader.Position;
                        break;
                }
            }

            if (endIndex >= startIndex)
            {
                yield return LineFromSegment(reader.GetSegment(startIndex, endIndex), false);
            }            
        }
コード例 #7
0
 IEnumerable<char> DecodeLine()
 {
     m_lineReader = new CharReader(m_currentLine.Text);
     char ch;
     while ((ch = m_lineReader.Read()) != CharReader.EOF)
     {
         if (ch != EncodingChar)
         {
             yield return ch;
         }
         else
         {
             char decodedChar = this.DecodeChar();
             if (decodedChar != char.MinValue)
             {
                 yield return decodedChar;
             }
         }
     }
 }
コード例 #8
0
ファイル: CharReaderFacts.cs プロジェクト: DM-TOR/nhin-d
 public void CharReaderKeepsReadingAfterFoundPosition()
 {
     string source = "abc:123";
     CharReader reader = new CharReader(source);
     reader.ReadTo(':', false);
     Assert.Equal('1', reader.Read());
 }