Permalink
Browse files

stopped treating single quotes like quotes

  • Loading branch information...
1 parent 3e71665 commit be4e202dd3e5fd4690f40962445245112862894b @masak committed Aug 20, 2009
Showing with 12 additions and 15 deletions.
  1. +0 −3 TODO
  2. +4 −8 lib/Text/CSV.pm
  3. +8 −4 t/03-quotes.t
View
3 TODO
@@ -1,8 +1,5 @@
Some new ideas await tuits:
-* Similarly, make single quotes not quote things by default. Perhaps
- not even a flag is needed in this case.
-
* Fields with embedded double-quote characters must be enclosed within
double-quote characters, and each of the embedded double-quote
characters must be represented by a pair of double-quote characters.
View
@@ -2,19 +2,15 @@ grammar Text::CSV::Line {
regex TOP { ^ <value> ** ',' $ }
regex value {
| <pure_text>
- | \s* \' <single_quote_contents> \' \s*
- | \s* \" <double_quote_contents> \" \s*
+ | \s* \" <quoted_contents> \" \s*
}
- regex single_quote_contents { <pure_text> ** [ <[",]> | \h ] }
- regex double_quote_contents { <pure_text> ** [ <[',]> | \h ] }
- regex pure_text { [<!before <['",]>> .]+ }
+ regex quoted_contents { <pure_text> ** [ <[,]> | \h ] }
+ regex pure_text { [<!before <[",]>> .]+ }
}
class Text::CSV {
sub extract_text($m, :$trim) {
- my $text = ($m<single_quote_contents>
- // $m<double_quote_contents>
- // $m).Str;
+ my $text = ($m<quoted_contents> // $m).Str;
return $trim ?? $text.trim !! $text;
}
View
@@ -9,18 +9,22 @@ sub ok_becomes($input, $output, $description = '') {
ok_becomes q[[[foo,bar,baz
'foo','bar','baz'
-'foo','bar' , 'baz']]], [ [<foo bar baz>] xx 3 ], 'single quotes';
+'foo','bar' , 'baz']]],
+ [ [<foo bar baz>],
+ ["'foo'", "'bar'", "'baz'"],
+ ["'foo'", "'bar' ", " 'baz'"] ],
+ 'single quotes carry no special significance';
ok_becomes q[[[foo,bar,baz
"foo","bar","baz"
"foo","bar" , "baz"]]], [ [<foo bar baz>] xx 3 ], 'double quotes';
-dies_ok { Text::CSV.read(q[[[foo,ba'r,ba'z]]]) },
- 'mid-string single quotes illegal';
+lives_ok { Text::CSV.read(q[[[foo,ba'r,ba'z]]]) },
+ 'mid-string single quotes legal';
dies_ok { Text::CSV.read(q[[[foo,ba"r,ba"z]]]) },
'mid-string double quotes illegal';
-is +Text::CSV.read(q[[[foo,'bar,baz']]])[0], 2, 'can single-quote commas';
+is +Text::CSV.read(q[[[foo,'bar,baz']]])[0], 3, 'cannot single-quote commas';
is +Text::CSV.read(q[[[foo,"bar,baz"]]])[0], 2, 'can double-quote commas';
done_testing;

0 comments on commit be4e202

Please sign in to comment.