[Mono-bugs] [Bug 655934] TextReader: ReadToEnd and ReadLine not implemented correctly

bugzilla_noreply at novell.com bugzilla_noreply at novell.com
Sat Feb 5 16:34:24 EST 2011


https://bugzilla.novell.com/show_bug.cgi?id=655934

https://bugzilla.novell.com/show_bug.cgi?id=655934#c1


Steve Bjorg <steveb at mindtouch.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |steveb at mindtouch.com

--- Comment #1 from Steve Bjorg <steveb at mindtouch.com> 2011-02-05 21:34:23 UTC ---
Here is an implementation of the missing methods.

public override string ReadToEnd() {
    var result = new StringBuilder();
    for(var c = Read(); c >= 0; c = Read()) {
        result.Append((char)c);
    }
    return result.ToString();
}

public override string ReadLine() {
    StringBuilder result = null;
    for(var c = Read(); c >= 0; c = Read()) {

        // lazy initialize string buffer so we can detect the case where we had
already reached the end of the reader
        result = result ?? new StringBuilder();

        // check simple character line ending
        if(c == '\r') {
            if(Peek() == '\n') {
                Read();
            }
            break;
        } else if(c == '\n') {
            break;
        } else {
            result.Append((char)c);

            // check if buffered sequence matches Environment.NewLine
            if(result.Length >= Environment.NewLine.Length) {
                if(result.ToString(result.Length - Environment.NewLine.Length,
Environment.NewLine.Length) == Environment.NewLine) {
                    result.Remove(result.Length - Environment.NewLine.Length,
Environment.NewLine.Length);
                    break;
                }
            }
        }
    }
    return (result != null) ? result.ToString() : null;
}

-- 
Configure bugmail: https://bugzilla.novell.com/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the QA contact for the bug.
You are the assignee for the bug.


More information about the mono-bugs mailing list