[Mono-bugs] [Bug 321988] System.IO.Ports.SerialPort ReadLine behaviour differs from MS .NET implementation

bugzilla_noreply at novell.com bugzilla_noreply at novell.com
Mon Nov 5 09:48:37 EST 2007


https://bugzilla.novell.com/show_bug.cgi?id=321988#c4


Miguel de Icaza <miguel at novell.com> changed:

           What    |Removed                                         |Added
----------------------------------------------------------------------------
                 CC|                                                |miguel at novell.com




--- Comment #4 from Miguel de Icaza <miguel at novell.com>  2007-11-05 07:48:36 MST ---
I believe this is a better implementation using a trivial state machine:

                public string ReadLine ()
                {
                        CheckOpen ();
                        List<byte> bytes_read = new List<byte>();
                        byte [] buff = new byte [1];
                        int nl_state = 0;
                        int nl_final = new_line.Length;

                        while (true){
                                int n = stream.Read (buff, 0, 1);

                                if (n == -1)
                                        break;

                                if (buff [0] == new_line [nl_state]){
                                        if (++nl_state == nl_final)
                                                break;
                                } else
                                        nl_state = 0;
                                bytes_read.Add (buff [0]);
                        } 
                        return new String (encoding.GetChars
(bytes_read.ToArray ()));
                }


-- 
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