# CVS Parser ### State machine | Current State | Condition | Next State | Notes | | --- | --- | --- | --- | | | Initial state | lineStart | | | lineStart | `ws`[1](#fn1),[5](#fn5) | lineStart | Skip | | | `"` | quoted | Add a new row | | | `,`[2](#fn2) | fieldStart | Add a new row and add an empty field | | | else | normal | Add a new row and add character to text field | | fieldStart | `nl`[3](#fn3)| lineStart | Add an empty field to the last row | | | `ws`[5](#fn5) | fieldStart | `nl` already tested | | | `"` | quoted | Start quoted field | | | `,` | fieldStart | Add an empty field to the last row | | | else | normal | | | normal | `"` | quoted | Start quoted | | | `,` | fieldStart | Add a new field to the last row | | | `nl` | lineStart | Add a new field to the last row | | | `cr`[4](#fn4) | normal | skip | | | `space` | normal | Add to field text but trailing space may be removed later | | | else | normal | Add character to field text | | quoted | `"` | qdfound | | | | else | quoted | Add character to field text | | qdfound | `"` | quoted | Single `"` added to text | | | else | normal | Add character to field text | ### Footnotes - 1 `ws` is an abreviation for whitespace, it has many meanings but here it means carriage return, new line or, space. - 2 The parser can handle other field separators than a comma but it is the default. - 3 `nl` is an abreviation for new line, it is used to terminate a line of text together with `cr`. - 4 `cr` is an abreviation for carriage return. - 5 This line is skipped if `leavingWhiteSpace` is true