Skip to content

Request to support quotes within quotes as defined by RFC 4180 #217

Closed
@brianrussell2

Description

@brianrussell2

In some cases, it is necessary to process CSV files that contain quotation marks within the field's enclosing double quotes. RFC 4180 explains this behavior as follows:

  1. If double-quotes are used to enclose fields, then a double-quote
    appearing inside a field must be escaped by preceding it with
    another double quote. For example:
   "aaa","b""bb","ccc"

When encountering such a file, my quick/hacky fix in the CDL.java file was as follows:

case ''':
q = c;
sb = new StringBuffer();
for (;;) {
c = x.next();
if (c == q ) {
//Fix - check to ensure that this is not an escaped quote
if(x.next() != '"')
{
x.back();
break;
}
}
if (c == 0 || c == '\n' || c == '\r') {
throw x.syntaxError("Missing close quote '" + q + "'.");
}
sb.append(c);
}
return sb.toString();

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions