Create a finite state machine describing the behavior for a class that has
the responsibility to parse a single line from a Comma Separated Values
file. The file will have the structure given below. Be sure to label states
with a descriptive name in the context of parsing a single line from a CSV
file. All transitions should be labeled with the event that triggers the
transition, and show actions that will be executed, if appropriate, before
entering the next state. Be sure to define behavior that is robust to format
errors in the line being parsed.
A line break indicates the end of a line.
Empty fields are allowed.
Two fields on a line are separated by a comma. There is no comma after the
last field on the line.
Double-quotes may or may not enclose a field. Double-quotes enclosing a
field are not part of the field value.
Commas can only be present in a field if the field is enclosed in
double-quotes. A double-quote within an enclosed field must be escaped
with a double-quote, i.e. the double-quote within the field is represented
by two double-quotes in a row. A double-quote in a non-enclosed field is
considered a regular character.
A line ending in a comma indicates an empty last field on the line. A line
with just a line break is a blank line with no fields. A line that has a
single empty field must use an enclosed field with no characters between
the enclosing double-quote characters to indicate that single empty field.
Notes
Create your state machine using the tool of your choice and submit the PDF
file to the dropbox, or draw it on paper/a whiteboard and submit a photo
of the drawing.
Assume that you have access to the line from the CSV file on a
character-by-character basis and that reading a character from the line
creates a unique event for that character, i.e. there are separate events
for the letter 'a', 'b', 'c', etc.
Assume that the line break, whatever the character or character sequence
may be, is indicated by the new line "nl" character.
When the line is correctly parsed, the field values should be returned in
an array with the first element of the array containing the value of the
first field on the line.
If you encounter a need to parse a CSV formated file, you usually do not
need to deal with it on a character level. There are tools for most
programming languages to do the parsing for you at a higher level.