The purpose of this library is to process CSV records. Use tokenize_line to parse an entire line of comma seperated values
include csv.e public function tokenize_record(integer infile)
Takes a file descriptor which contains multiple fields. Returns a triple. If the read of the record is successful, the first member is 0 and the second member is a sequences of strings which describes the record. If the read is not successful the first member is an error code which can be EOF, UNTERMINATED_STRING or INVALID_LINE. The second member is then set to a string which is either the line or lines it tried to process into a line or 0. The third member is the line_count of lines that were loaded from the file descriptor.
Unlike tokenize_line, tokenize_record will read more lines until an unterminated string is terminated or the end of file is reached.
include csv.e public function tokenize_line(sequence line)
Takes a string which contains multiple fields. Returns a either a sequence of strings or an error code which can be UNTERMINATED_STRING or INVALID_LINE.
include csv.e function tokenize_string(sequence line)
Takes a string which contains a field entry string and possibly a comma seperator. Returns a pair of the form {error string, error code} or {string parsed, next character to read}. In the case of an error, the first member error string is an ASCII string describing the error and the second member is the error code which can be UNTERMINATED_STRING or INVALID_LINE. In the case of no error, the first member, string parsed, is the string between the commas and the second is the index of the next character to read. However, if it reads the last field, its next character to read will be the invalid value length(line)+1.
include csv.e public enum UNTERMINATED_STRING
line passed contains an unterminated string
include csv.e public enum INVALID_LINE
line passed contains invalid CSV
include csv.e public integer record_no
Maintain these variables, line_no which always count input lines and record_no which counts records. A record might contain a '\n' inside of a field
include csv.e public integer line_no
always counts input lines although you may have multiple lines in a record.
include csv.e public constant display_process_info_id
Pass this to crash_routine when processing a file, line_no, and record_no must be initialized before calling crash_routine with this id. Thereafter, line_no and record_no should be maintained by the user in processing the file.