Skip to content

Commit dea68c1

Browse files
committed
updated comments
1 parent 13d9b50 commit dea68c1

File tree

1 file changed

+19
-18
lines changed

1 file changed

+19
-18
lines changed

src/fread.c

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -34,28 +34,29 @@ static char quote, dec;
3434
static int linesForDecDot; // when dec='auto', track the balance of fields in favor of dec='.' vs dec=',', ties go to '.'
3535
static bool eol_one_r; // only true very rarely for \r-only files
3636

37-
// Quote rule:
38-
// 0 = Fields may be quoted, any quote inside the field is doubled. This is
39-
// the CSV standard. For example: <<...,"hello ""world""",...>>
40-
// 1 = Fields may be quoted, any quotes inside are escaped with a backslash.
41-
// For example: <<...,"hello \"world\"",...>>
42-
// 2 = Fields may be quoted, but any quotes inside will appear verbatim and
43-
// not escaped in any way. It is not always possible to parse the file
44-
// unambiguously, but we give it a try anyways. A quote will be presumed
45-
// to mark the end of the field iff it is followed by the field separator.
46-
// Under this rule eol characters cannot appear inside the field.
47-
// For example: <<...,"hello "world"",...>>
48-
// 3 = Fields are not quoted at all. Any quote characters appearing anywhere
49-
// inside the field will be treated as any other regular characters.
50-
// Example: <<...,hello "world",...>>
51-
//
52-
5337
enum quoteRule
5438
{
39+
// Fields may be quoted, any quote inside the field is doubled.This is
40+
// the CSV standard. For example: <<...,"hello ""world""",...>>
5541
QUOTE_RULE_EMBEDDED_QUOTES_DOUBLED,
42+
43+
// Fields may be quoted, any quotes inside are escaped with a backslash.
44+
// For example: <<...,"hello \"world\"",...>>
5645
QUOTE_RULE_EMBEDDED_QUOTES_ESCAPED,
46+
47+
// Fields may be quoted, but any quotes inside will appear verbatim and
48+
// not escaped in any way. It is not always possible to parse the file
49+
// unambiguously, but we give it a try anyways. A quote will be presumed
50+
// to mark the end of the field iff it is followed by the field separator.
51+
// Under this rule eol characters cannot appear inside the field.
52+
// For example: <<...,"hello "world"",...>>
5753
QUOTE_RULE_HYBRID,
54+
55+
// Fields are not quoted at all.Any quote characters appearing anywhere
56+
// inside the field will be treated as any other regular characters.
57+
// Example: <<...,hello "world",...>>
5858
QUOTE_RULE_IGNORE_QUOTES,
59+
5960
QUOTE_RULE_COUNT
6061
};
6162

@@ -589,7 +590,7 @@ static void Field(FieldParseContext *ctx)
589590
*ctx->ch = ch;
590591
} else {
591592
*ctx->ch = ch;
592-
if (ch == eof && quoteRule != QUOTE_RULE_HYBRID) { target->off--; target->len++; } // test 1324 where final field has open quote but not ending quote; include the open quote like quote rule 2
593+
if (ch == eof && quoteRule != QUOTE_RULE_HYBRID) { target->off--; target->len++; } // test 1324 where final field has open quote but not ending quote; include the open quote like QUOTE_RULE_HYBRID
593594
while(target->len > 0 && ((ch[-1] == ' ' && stripWhite) || ch[-1] == '\0')) { target->len--; ch--; } // test 1551.6; trailing whitespace in field [67,V37] == "\"\"A\"\" ST "
594595
}
595596
// Does end-of-field correspond to end-of-possible-NA?
@@ -1840,7 +1841,7 @@ int freadMain(freadMainArgs _args)
18401841
ASSERT(topSep == 127, "Single column input has topSep=%d", topSep);
18411842
sep = topSep;
18421843
// no self healing quote rules, as we don't have >1 field to disambiguate
1843-
// choose quote rule 0 or 1 based on for which 100 rows gets furthest into file
1844+
// choose QUOTE_RULE_EMBEDDED_QUOTES_DOUBLED or QUOTE_RULE_EMBEDDED_QUOTES_ESCAPED based on for which 100 rows gets furthest into file
18441845
for (quoteRule = QUOTE_RULE_EMBEDDED_QUOTES_DOUBLED; quoteRule <= QUOTE_RULE_EMBEDDED_QUOTES_ESCAPED; quoteRule++) { // #loop_counter_not_local_scope_ok
18451846
int thisRow = 0, thisncol = 0;
18461847
ch = pos;

0 commit comments

Comments
 (0)