You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add new stripquoted keyword arg and fix stripwhitespace (#112)
* Add new stripquoted keyword arg and fix stripwhitespace
Fixes#109. As noted in that issue, stripping whitespace *within* quoted
strings, IMO, should be considered a bug, since one of the primary
reasons for quoting strings in various applications is to delineate the
exact characters that make up the string. This PR fixes
`stripwhitespace` to preserve whitepace encountered within strings, and
only strip whitespace for non-quoted strings (leading or trailing) and
leading/trailing around quoted fields.
On the other hand, there are legitimate use-cases for also stripping
whitespace within quoted strings, so we add a new opt-in `stripquoted`
keyword argument that allows the additional precision of also stripping
whitespace inside quotes. Note that passing `stripquoted=true` implies
`stripwhitespace=true`, so it can be considered a "stronger" version of
`stripewhitespace`.
* Update src/Parsers.jl
Co-authored-by: Nick Robinson <npr251@gmail.com>
* Update test/runtests.jl
Co-authored-by: Nick Robinson <npr251@gmail.com>
Co-authored-by: Nick Robinson <npr251@gmail.com>
Copy file name to clipboardExpand all lines: src/Parsers.jl
+9-6Lines changed: 9 additions & 6 deletions
Original file line number
Diff line number
Diff line change
@@ -53,7 +53,8 @@ end
53
53
* `quoted=false`: whether parsing should check for `openquotechar` and `closequotechar` characters to signal quoted fields
54
54
* `comment=nothing`: a string which, if matched at the start of a line, will make parsing consume the rest of the line
55
55
* `ignoreemptylines=false`: after parsing a value, if a newline is detected, another immediately proceeding newline will be checked for and consumed
56
-
* `stripwhitespace=false`: if true, leading and trailing whitespace is stripped from string fields
56
+
* `stripwhitespace=false`: if true, leading and trailing whitespace is stripped from string fields, note that for *quoted* strings however, whitespace is preserved within quotes (but ignored before/after quote characters). To also strip *within* quotes, see `stripquoted`
57
+
* `stripquoted=false`: if true, whitespace is also stripped within quoted strings. If true, `stripwhitespace` is also set to true.
57
58
* `debug=false`: if `true`, various debug logging statements will be printed while parsing; useful when diagnosing why parsing returns certain `Parsers.ReturnCode` values
asciival(wh1) &&asciival(wh2) ||throw(ArgumentError("whitespace characters must be ASCII"))
97
99
asciival(oq) &&asciival(cq) &&asciival(e) ||throw(ArgumentError("openquotechar, closequotechar, and escapechar must be ASCII characters"))
98
100
(oq == delim) || (cq == delim) || (e == delim) &&throw(ArgumentError("delim argument must be different than openquotechar, closequotechar, and escapechar arguments"))
@@ -134,7 +136,7 @@ function Options(
134
136
cmt =ptrlen(comment)
135
137
end
136
138
df = dateformat ===nothing?nothing: dateformat isa String ?Format(dateformat) : dateformat isa Dates.DateFormat ?Format(dateformat) : dateformat
137
-
returnOptions(refs, sent, ignorerepeated, ignoreemptylines, wh1 % UInt8, wh2 % UInt8, quoted, oq % UInt8, cq % UInt8, e % UInt8, del, decimal % UInt8, trues, falses, df, cmt, stripwhitespace)
0 commit comments