Parse a Serial Stream of Characters

I have a situation where I have a method that accepts ONE character at time from a serial source (all ASCII printable).

From this I need to build a string and sent to a display control (think Textarea)

BUT… the serial stream may contain sequences that need to be caught and interepetd and NOT be part of the text output … These will all begin with \ and end with ] and consist of 1 to 3 digts (\93]) … OR be “\B]” \I]" , "\U] or "\X]

The really tricky part is if the sequence begins with TWO \ then its text and not a format command, or it there are more than 3 digits or a character other than B,I,U or X before it encounters the ] character

Basicly this is a “terminal” emulator of sorts, only the serial data comes from the user via keyboard or from an input file, not from a serial port

Figured it out…

created a 2nd buffer to capture the format characters… if the format was started and an invalid char was attempted to be added, the the format buffer was sent as plain text, and rest… other wise when the end format (]) was detected, the colors etc were altered