Re: CSV reader: is it possible to disable trim?
Shiro Kawai <[email protected]> Mon, 18 May 2026 07:23:45 -1000
| Newsgroups | gmane.lisp.scheme.gauche |
|---|---|
| Message-ID | <CALN0JNEyudUjagz7=r2=Q9yfxL+GF4YJRAy92fNyHs=4EhG3uQ@mail.gmail.com> |
--===============4861120143379656652== Content-Type: multipart/alternative; boundary="000000000000ce6ad806521ad310" --000000000000ce6ad806521ad310 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Thanks, patch applied. --shiro On Mon, May 18, 2026 at 2:35=E2=80=AFAM Jens Thiele <[email protected]> wrote: > Shiro Kawai <[email protected]> writes: > > > https://github.com/shirok/Gauche/issues/1271 > > > > Decided not to change the default, but made it customizable with a > > parameter and/or optional argument. > > Changing the default can cause hard-to-surface bugs in existing code. > > Let me know if this fix works. > > did some tests, looks good, thanks! > > I also tried to proofread the documenation updates, but please note I am > not a native speaker... > > diff --git a/doc/modutil.texi b/doc/modutil.texi > index bff32566b..c1919b954 100644 > --- a/doc/modutil.texi > +++ b/doc/modutil.texi > @@ -29448,7 +29448,7 @@ resets the attributes. > @c EN > Provides a function to parse/generate CSV (comma separated value) tables= , > including the format defined in RFC4180. You can customize the > -separator and quoter character to deal with variations of CSV formats. > +separator and quote character to deal with variations of CSV formats. > > CSV table is consisted by a series of @var{records}, separated by > a newline. Each record contains number of @var{fields}, separated > @@ -29471,7 +29471,7 @@ CSV =E3=81=AE=E8=A1=A8=E3=81=AF=E3=80=81=E6=94=B9= =E8=A1=8C=E3=81=A7=E5=8C=BA=E5=88=87=E3=82=89=E3=82=8C=E3=81=9F @var{record= } =E3=81=AE=E9=80=A3=E7=B6=9A=E3=81=A7=E6=A7=8B=E6=88=90=E3=81=95=E3=82=8C > @c COMMON > > @c EN > -By default, whitespaces around an nunquoted field value is ignored. > +By default, whitespaces around an unquoted field value are ignored. > You can customize this behavior with @code{csv-trim-unquoted-charset} > parameter or @var{trim-charset} optional argument of > @code{make-csv-reader}. > @@ -29539,11 +29539,11 @@ The default value is @code{#\"}. > > @c EN > The optional @var{trim-charset} argument must be a charset or @code{#f}. > -If it is a charset, those characters surrounding @emph{unquoted} field > value > +If it is a charset, those characters surrounding @emph{unquoted} field > values > are trimmed. The default value is the value of the parameter > @code{csv-trim-unquoted-charset}, whose initial value is @code{#[\s]}, > causing whitespaces around > -unquoted field value are trimmed. If it is @code{#f}, no trimming is > done. > +unquoted field values are trimmed. If it is @code{#f}, no trimming is > done. > Whitespaces within quotes are never be trimmed. Note that if this > argument > is a charset, its characters can appear between separater character and > quoted > field---they're just ignored. If this argument is @code{#f}, however, > @@ -29567,8 +29567,8 @@ extra characters between separator and quoted > field triggers an error. > Note: The default behavior of trimming whitespaces is for the backward > compatibility. RFC 4180 states whitespaces in unquoted fields > should not be ignored. It doesn't allow whitespaces between a separator > -character and a quoted field. Set @code{csv-trim-unquoted-charset} to > -@code{#f} or pass @code{#f} to @var{trim-charset} argument makes the > +character and a quoted field. Setting @code{csv-trim-unquoted-charset} = to > +@code{#f} or passing @code{#f} to @var{trim-charset} argument makes the > maximum comformance to RFC4180. > @c JP > =E8=A8=BB: =E7=A9=BA=E7=99=BD=E6=96=87=E5=AD=97=E3=82=92=E3=83=87=E3=83= =95=E3=82=A9=E3=83=AB=E3=83=88=E3=81=A7=E5=8F=96=E3=82=8A=E9=99=A4=E3=81=8F= =E6=8C=AF=E3=82=8B=E8=88=9E=E3=81=84=E3=81=AF=E5=BE=8C=E6=96=B9=E4=BA=92=E6= =8F=9B=E6=80=A7=E3=81=AE=E3=81=9F=E3=82=81=E3=81=A7=E3=81=99=E3=80=82 > diff --git a/tests/text.scm b/tests/text.scm > index 24e58ef05..5e5c681f9 100644 > --- a/tests/text.scm > +++ b/tests/text.scm > @@ -35,7 +35,7 @@ > (call-with-input-string " abc, \" de,f \" , \"gh\ni\", \"jkl\= "" > (make-csv-reader #\,))) > > -(test* "csv-reader (do not arrow extra spaces w/o trimming" > +(test* "csv-reader (do not allow extra spaces w/o trimming)" > (test-error <error> #/quote char in a field/) > (parameterize ([csv-trim-unquoted-charset #f]) > (call-with-input-string "abc , \"def\" , \"ghi\" " > > > _______________________________________________ > Gauche-devel mailing list > [email protected] > https://lists.sourceforge.net/lists/listinfo/gauche-devel > --000000000000ce6ad806521ad310 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable <div dir=3D"ltr"><div class=3D"gmail_default" style=3D"font-size:large">Tha= nks, patch applied.</div><div class=3D"gmail_default" style=3D"font-size:la= rge"><br></div><div class=3D"gmail_default" style=3D"font-size:large">--shi= ro</div><div class=3D"gmail_default" style=3D"font-size:large"><br></div></= div><br><div class=3D"gmail_quote gmail_quote_container"><div dir=3D"ltr" c= lass=3D"gmail_attr">On Mon, May 18, 2026 at 2:35=E2=80=AFAM Jens Thiele <= ;<a href=3D"mailto:[email protected]">[email protected]</a>> wrote:<br></div><= blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-l= eft:1px solid rgb(204,204,204);padding-left:1ex">Shiro Kawai <<a href=3D= "mailto:[email protected]" target=3D"_blank">[email protected]</a>&= gt; writes:<br> <br> > <a href=3D"https://github.com/shirok/Gauche/issues/1271" rel=3D"norefe= rrer" target=3D"_blank">https://github.com/shirok/Gauche/issues/1271</a><br= > ><br> > Decided not to change the default, but made it customizable with a<br> > parameter and/or optional argument.<br> > Changing the default can cause hard-to-surface bugs in existing code.<= br> > Let me know if this fix works.<br> <br> did some tests, looks good, thanks!<br> <br> I also tried to proofread the documenation updates, but please note I am<br= > not a native speaker...<br> <br> diff --git a/doc/modutil.texi b/doc/modutil.texi<br> index bff32566b..c1919b954 100644<br> --- a/doc/modutil.texi<br> +++ b/doc/modutil.texi<br> @@ -29448,7 +29448,7 @@ resets the attributes.<br> =C2=A0@c EN<br> =C2=A0Provides a function to parse/generate CSV (comma separated value) tab= les,<br> =C2=A0including the format defined in RFC4180.=C2=A0 You can customize the<= br> -separator and quoter character to deal with variations of CSV formats.<br> +separator and quote character to deal with variations of CSV formats.<br> <br> =C2=A0CSV table is consisted by a series of @var{records}, separated by<br> =C2=A0a newline.=C2=A0 Each record contains number of @var{fields}, separat= ed<br> @@ -29471,7 +29471,7 @@ CSV =E3=81=AE=E8=A1=A8=E3=81=AF=E3=80=81=E6=94=B9= =E8=A1=8C=E3=81=A7=E5=8C=BA=E5=88=87=E3=82=89=E3=82=8C=E3=81=9F @var{record= } =E3=81=AE=E9=80=A3=E7=B6=9A=E3=81=A7=E6=A7=8B=E6=88=90=E3=81=95=E3=82=8C<= br> =C2=A0@c COMMON<br> <br> =C2=A0@c EN<br> -By default, whitespaces around an nunquoted field value is ignored.<br> +By default, whitespaces around an unquoted field value are ignored.<br> =C2=A0You can customize this behavior with @code{csv-trim-unquoted-charset}= <br> =C2=A0parameter or @var{trim-charset} optional argument of<br> =C2=A0@code{make-csv-reader}.<br> @@ -29539,11 +29539,11 @@ The default value is @code{#\"}.<br> <br> =C2=A0@c EN<br> =C2=A0The optional @var{trim-charset} argument must be a charset or @code{#= f}.<br> -If it is a charset, those characters surrounding @emph{unquoted} field val= ue<br> +If it is a charset, those characters surrounding @emph{unquoted} field val= ues<br> =C2=A0are trimmed.=C2=A0 The default value is the value of the parameter<br= > =C2=A0@code{csv-trim-unquoted-charset}, whose initial value is @code{#[\s]}= ,<br> =C2=A0causing whitespaces around<br> -unquoted field value are trimmed.=C2=A0 If it is @code{#f}, no trimming is= done.<br> +unquoted field values are trimmed.=C2=A0 If it is @code{#f}, no trimming i= s done.<br> =C2=A0Whitespaces within quotes are never be trimmed.=C2=A0 Note that if th= is argument<br> =C2=A0is a charset, its characters can appear between separater character a= nd quoted<br> =C2=A0field---they're just ignored.=C2=A0 If this argument is @code{#f}= , however,<br> @@ -29567,8 +29567,8 @@ extra characters between separator and quoted field= triggers an error.<br> =C2=A0Note: The default behavior of trimming whitespaces is for the backwar= d<br> =C2=A0compatibility.=C2=A0 RFC 4180 states whitespaces in unquoted fields<b= r> =C2=A0should not be ignored.=C2=A0 It doesn't allow whitespaces between= a separator<br> -character and a quoted field.=C2=A0 Set @code{csv-trim-unquoted-charset} t= o<br> -@code{#f} or pass @code{#f} to @var{trim-charset} argument makes the<br> +character and a quoted field.=C2=A0 Setting @code{csv-trim-unquoted-charse= t} to<br> +@code{#f} or passing @code{#f} to @var{trim-charset} argument makes the<br= > =C2=A0maximum comformance to RFC4180.<br> =C2=A0@c JP<br> =C2=A0=E8=A8=BB: =E7=A9=BA=E7=99=BD=E6=96=87=E5=AD=97=E3=82=92=E3=83=87=E3= =83=95=E3=82=A9=E3=83=AB=E3=83=88=E3=81=A7=E5=8F=96=E3=82=8A=E9=99=A4=E3=81= =8F=E6=8C=AF=E3=82=8B=E8=88=9E=E3=81=84=E3=81=AF=E5=BE=8C=E6=96=B9=E4=BA=92= =E6=8F=9B=E6=80=A7=E3=81=AE=E3=81=9F=E3=82=81=E3=81=A7=E3=81=99=E3=80=82<br= > diff --git a/tests/text.scm b/tests/text.scm<br> index 24e58ef05..5e5c681f9 100644<br> --- a/tests/text.scm<br> +++ b/tests/text.scm<br> @@ -35,7 +35,7 @@<br> =C2=A0 =C2=A0 =C2=A0 =C2=A0 (call-with-input-string "=C2=A0 =C2=A0abc,= =C2=A0 \" de,f \"=C2=A0 , \"gh\ni\", \"jkl\"&= quot;<br> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (make-csv-reader #\,)))<br> <br> -(test* "csv-reader (do not arrow extra spaces w/o trimming"<br> +(test* "csv-reader (do not allow extra spaces w/o trimming)"<br> =C2=A0 =C2=A0 =C2=A0 =C2=A0 (test-error <error> #/quote char in a fie= ld/)<br> =C2=A0 =C2=A0 =C2=A0 =C2=A0 (parameterize ([csv-trim-unquoted-charset #f])<= br> =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 (call-with-input-string "abc=C2=A0 = ,=C2=A0 \"def\"=C2=A0 , \"ghi\"=C2=A0 "<br> <br> <br> _______________________________________________<br> Gauche-devel mailing list<br> <a href=3D"mailto:[email protected]" target=3D"_blank">Gau= [email protected]</a><br> <a href=3D"https://lists.sourceforge.net/lists/listinfo/gauche-devel" rel= =3D"noreferrer" target=3D"_blank">https://lists.sourceforge.net/lists/listi= nfo/gauche-devel</a><br> </blockquote></div> --000000000000ce6ad806521ad310-- --===============4861120143379656652== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline --===============4861120143379656652== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Gauche-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/gauche-devel --===============4861120143379656652==--