r48466 - in /trunk/libtext-csv-xs-perl: CSV_XS.pm CSV_XS.xs ChangeLog META.yml debian/changelog t/12_acc.t t/15_flags.t

gregoa at users.alioth.debian.org gregoa at users.alioth.debian.org
Tue Dec 8 22:36:24 UTC 2009


Author: gregoa
Date: Tue Dec  8 22:36:19 2009
New Revision: 48466

URL: http://svn.debian.org/wsvn/pkg-perl/?sc=1&rev=48466
Log:
New upstream release.

Modified:
    trunk/libtext-csv-xs-perl/CSV_XS.pm
    trunk/libtext-csv-xs-perl/CSV_XS.xs
    trunk/libtext-csv-xs-perl/ChangeLog
    trunk/libtext-csv-xs-perl/META.yml
    trunk/libtext-csv-xs-perl/debian/changelog
    trunk/libtext-csv-xs-perl/t/12_acc.t
    trunk/libtext-csv-xs-perl/t/15_flags.t

Modified: trunk/libtext-csv-xs-perl/CSV_XS.pm
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libtext-csv-xs-perl/CSV_XS.pm?rev=48466&op=diff
==============================================================================
--- trunk/libtext-csv-xs-perl/CSV_XS.pm (original)
+++ trunk/libtext-csv-xs-perl/CSV_XS.pm Tue Dec  8 22:36:19 2009
@@ -30,7 +30,7 @@
 use Carp;
 
 use vars   qw( $VERSION @ISA );
-$VERSION = "0.69";
+$VERSION = "0.70";
 @ISA     = qw( DynaLoader );
 bootstrap Text::CSV_XS $VERSION;
 
@@ -59,6 +59,7 @@
     sep_char		=> ',',
     eol			=> '',
     always_quote	=> 0,
+    quote_space		=> 1,
     binary		=> 0,
     keep_meta_info	=> 0,
     allow_loose_quotes	=> 0,
@@ -82,6 +83,20 @@
     );
 my $last_new_err = Text::CSV_XS->SetDiag (0);
 
+sub _check_sanity
+{
+    my $attr = shift;
+    for (qw( sep_char quote_char escape_char )) {
+	exists $attr->{$_} && defined $attr->{$_} && $attr->{$_} =~ m/[\r\n]/ and
+	    return 1003;
+	}
+    $attr->{allow_whitespace} and
+      (defined $attr->{quote_char}  && $attr->{quote_char}  =~ m/^[ \t]$/) ||
+      (defined $attr->{escape_char} && $attr->{escape_char} =~ m/^[ \t]$/) and
+	return 1002;
+    return 0;
+    } # _check_sanity
+
 sub new
 {
     $last_new_err = SetDiag (undef, 1000,
@@ -103,10 +118,8 @@
 	}
 
     my $self  = {%def_attr, %{$attr}};
-    if ($self->{allow_whitespace} and
-	    (defined $self->{quote_char}  && $self->{quote_char}  =~ m/^[ \t]$/) ||
-	    (defined $self->{escape_char} && $self->{escape_char} =~ m/^[ \t]$/)) {
-	$last_new_err = SetDiag (undef, 1002);
+    if (my $ec = _check_sanity ($self)) {
+	$last_new_err = SetDiag (undef, $ec);
 	return;
 	}
 
@@ -134,16 +147,19 @@
     verbatim		=> 22,
     empty_is_undef	=> 23,
     auto_diag		=> 24,
-    _is_bound		=> 25,	# 25 .. 28
+    quote_space		=> 25,
+    _is_bound		=> 26,	# 26 .. 29
     );
 
 # A `character'
 sub _set_attr_C
 {
-    my ($self, $name, $val) = @_;
+    my ($self, $name, $val, $ec) = @_;
     defined $val or $val = 0;
     $] >= 5.008002 and utf8::decode ($val);
     $self->{$name} = $val;
+    $ec = _check_sanity ($self) and
+	croak ($self->SetDiag ($ec));
     $self->_cache_set ($_cache_id{$name}, $val);
     } # _set_attr_C
 
@@ -171,8 +187,6 @@
     my $self = shift;
     if (@_) {
 	my $qc = shift;
-	defined $qc && $qc =~ m/^[ \t]$/ && $self->{allow_whitespace} and
-	    croak ($self->SetDiag (1002));
 	$self->_set_attr_C ("quote_char", $qc);
 	}
     $self->{quote_char};
@@ -183,8 +197,6 @@
     my $self = shift;
     if (@_) {
 	my $ec = shift;
-	defined $ec && $ec =~ m/^[ \t]$/ && $self->{allow_whitespace} and
-	    croak ($self->SetDiag (1002));
 	$self->_set_attr_C ("escape_char", $ec);
 	}
     $self->{escape_char};
@@ -215,6 +227,13 @@
     @_ and $self->_set_attr_X ("always_quote", shift);
     $self->{always_quote};
     } # always_quote
+
+sub quote_space
+{
+    my $self = shift;
+    @_ and $self->_set_attr_X ("quote_space", shift);
+    $self->{quote_space};
+    } # quote_space
 
 sub binary
 {
@@ -902,6 +921,13 @@
 to handle in external applications. (Poor creatures who aren't using
 Text::CSV_XS. :-)
 
+=item quote_space
+
+By default, a space in a field would trigger quotation. As no rule
+exists this to be forced in CSV, nor any for the opposite, the default
+is true for safety. You can exclude the space from this trigger by
+setting this option to 0.
+
 =item keep_meta_info
 
 By default, the parsing of input lines is as simple and fast as
@@ -972,6 +998,7 @@
      sep_char            => ',',
      eol                 => $\,
      always_quote        => 0,
+     quote_space         => 1,
      binary              => 0,
      keep_meta_info      => 0,
      allow_loose_quotes  => 0,
@@ -1550,6 +1577,11 @@
 Using C<allow_whitespace> when either C<escape_char> or C<quote_char> is
 equal to SPACE or TAB is too ambiguous to allow.
 
+=item 1003 "INI - \r or \n in main attr not allowed"
+
+Using default C<eol> characters in either C<sep_char>, C<quote_char>, or
+C<escape_char> is not allowed.
+
 =item 2010 "ECR - QUO char inside quotes followed by CR not part of EOL"
 
 When C<eol> has been set to something specific, other than the default,

Modified: trunk/libtext-csv-xs-perl/CSV_XS.xs
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libtext-csv-xs-perl/CSV_XS.xs?rev=48466&op=diff
==============================================================================
--- trunk/libtext-csv-xs-perl/CSV_XS.xs (original)
+++ trunk/libtext-csv-xs-perl/CSV_XS.xs Tue Dec  8 22:36:19 2009
@@ -51,8 +51,9 @@
 #define CACHE_ID_verbatim		22
 #define CACHE_ID_empty_is_undef		23
 #define CACHE_ID_auto_diag		24
-#define CACHE_ID__is_bound		25
-#define CACHE_ID__has_ahead		29
+#define CACHE_ID_quote_space		25
+#define CACHE_ID__is_bound		26
+#define CACHE_ID__has_ahead		30
 
 #define CSV_FLAGS_QUO	0x0001
 #define CSV_FLAGS_BIN	0x0002
@@ -99,6 +100,9 @@
     byte	empty_is_undef;
     byte	verbatim;
     byte	auto_diag;
+
+    byte	quote_space;
+    byte	first_safe_char;
 
     long	is_bound;
 
@@ -122,8 +126,9 @@
     char	buffer[BUFFER_SIZE];
     } csv_t;
 
-#define bool_opt(o) \
-    (((svp = hv_fetchs (self, o, FALSE)) && *svp) ? SvTRUE (*svp) : 0)
+#define bool_opt_def(o,d) \
+    (((svp = hv_fetchs (self, o, FALSE)) && *svp) ? SvTRUE (*svp) : d)
+#define bool_opt(o) bool_opt_def (o, 0)
 
 typedef struct {
     int   xs_errno;
@@ -135,6 +140,7 @@
     { 1000, "INI - constructor failed"						},
     { 1001, "INI - sep_char is equal to quote_char or escape_char"		},
     { 1002, "INI - allow_whitespace with escape_char or quote_char SP or TAB"	},
+    { 1003, "INI - \r or \n in main attr not allowed"				},
 
     /* Parse errors */
     { 2010, "ECR - QUO char inside quotes followed by CR not part of EOL"	},
@@ -261,6 +267,7 @@
     if ( idx == CACHE_ID_binary			||
          idx == CACHE_ID_keep_meta_info		||
          idx == CACHE_ID_always_quote		||
+         idx == CACHE_ID_quote_space		||
          idx == CACHE_ID_allow_loose_quotes	||
          idx == CACHE_ID_allow_loose_escapes	||
          idx == CACHE_ID_allow_double_quoted	||
@@ -335,6 +342,7 @@
     _cache_show_byte ("allow_loose_quotes",	CACHE_ID_allow_loose_quotes);
     _cache_show_byte ("allow_whitespace",	CACHE_ID_allow_whitespace);
     _cache_show_byte ("always_quote",		CACHE_ID_always_quote);
+    _cache_show_byte ("quote_space",		CACHE_ID_quote_space);
     _cache_show_byte ("auto_diag",		CACHE_ID_auto_diag);
     _cache_show_byte ("blank_is_undef",		CACHE_ID_blank_is_undef);
     _cache_show_byte ("empty_is_undef",		CACHE_ID_empty_is_undef);
@@ -395,6 +403,7 @@
 	csv->keep_meta_info		= csv->cache[CACHE_ID_keep_meta_info	];
 	csv->always_quote		= csv->cache[CACHE_ID_always_quote	];
 	csv->auto_diag			= csv->cache[CACHE_ID_auto_diag	];
+	csv->quote_space		= csv->cache[CACHE_ID_quote_space	];
 
 	csv->allow_loose_quotes		= csv->cache[CACHE_ID_allow_loose_quotes];
 	csv->allow_loose_escapes	= csv->cache[CACHE_ID_allow_loose_escapes];
@@ -484,6 +493,7 @@
 	csv->binary			= bool_opt ("binary");
 	csv->keep_meta_info		= bool_opt ("keep_meta_info");
 	csv->always_quote		= bool_opt ("always_quote");
+	csv->quote_space		= bool_opt_def ("quote_space", 1);
 	csv->allow_loose_quotes		= bool_opt ("allow_loose_quotes");
 	csv->allow_loose_escapes	= bool_opt ("allow_loose_escapes");
 	csv->allow_double_quoted	= bool_opt ("allow_double_quoted");
@@ -505,6 +515,7 @@
 
 	csv->cache[CACHE_ID_keep_meta_info]		= csv->keep_meta_info;
 	csv->cache[CACHE_ID_always_quote]		= csv->always_quote;
+	csv->cache[CACHE_ID_quote_space]		= csv->quote_space;
 
 	csv->cache[CACHE_ID_allow_loose_quotes]		= csv->allow_loose_quotes;
 	csv->cache[CACHE_ID_allow_loose_escapes]	= csv->allow_loose_escapes;
@@ -532,6 +543,8 @@
     csv->size = 0;
     csv->used = 0;
 
+    csv->first_safe_char = csv->quote_space ? 0x21 : 0x20;
+
     if (csv->is_bound) {
 	if ((svp = hv_fetchs (self, "_BOUND_COLUMNS", FALSE)) && _is_arrayref (*svp))
 	    csv->bound = *svp;
@@ -622,7 +635,7 @@
 		for (ptr2 = ptr, l = len; l; ++ptr2, --l) {
 		    byte	c = *ptr2;
 
-		    if (c <= 0x20 || (c >= 0x7f && c <= 0xa0)  ||
+		    if (c < csv->first_safe_char || (c >= 0x7f && c <= 0xa0)  ||
 		       (csv->quote_char  && c == csv->quote_char) ||
 		       (csv->sep_char    && c == csv->sep_char)   ||
 		       (csv->escape_char && c == csv->escape_char)) {
@@ -1462,7 +1475,7 @@
     CSV_XS_SELF;
     xs_cache_set (hv, idx, val);
     XSRETURN (1);
-    /* XS _cache_diag */
+    /* XS _cache_set */
 
 void
 _cache_diag (self)

Modified: trunk/libtext-csv-xs-perl/ChangeLog
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libtext-csv-xs-perl/ChangeLog?rev=48466&op=diff
==============================================================================
--- trunk/libtext-csv-xs-perl/ChangeLog (original)
+++ trunk/libtext-csv-xs-perl/ChangeLog Tue Dec  8 22:36:19 2009
@@ -1,3 +1,8 @@
+2009-12-02 0.70 - H.Merijn Brand   <h.m.brand at xs4all.nl>
+
+    * Add quote_space attribute
+    * Forbid \r and \n in sep_char, quote_char, and escape_char
+
 2009-10-10 0.69 - H.Merijn Brand   <h.m.brand at xs4all.nl>
 
     * Missing end quotes in error code docs

Modified: trunk/libtext-csv-xs-perl/META.yml
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libtext-csv-xs-perl/META.yml?rev=48466&op=diff
==============================================================================
--- trunk/libtext-csv-xs-perl/META.yml (original)
+++ trunk/libtext-csv-xs-perl/META.yml Tue Dec  8 22:36:19 2009
@@ -1,6 +1,6 @@
 --- #YAML:1.1
 name:                    Text-CSV_XS
-version:                 0.69
+version:                 0.70
 abstract:                Comma-Separated Values manipulation routines
 license:                 perl
 author:              
@@ -10,7 +10,7 @@
 provides:
     Text::CSV_XS:
         file:            CSV_XS.pm
-        version:         0.69
+        version:         0.70
 requires:     
     perl:                5.005
     DynaLoader:          0

Modified: trunk/libtext-csv-xs-perl/debian/changelog
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libtext-csv-xs-perl/debian/changelog?rev=48466&op=diff
==============================================================================
--- trunk/libtext-csv-xs-perl/debian/changelog (original)
+++ trunk/libtext-csv-xs-perl/debian/changelog Tue Dec  8 22:36:19 2009
@@ -1,3 +1,9 @@
+libtext-csv-xs-perl (0.70-1) UNRELEASED; urgency=low
+
+  * New upstream release.
+
+ -- gregor herrmann <gregoa at debian.org>  Tue, 08 Dec 2009 23:35:39 +0100
+
 libtext-csv-xs-perl (0.69-1) unstable; urgency=low
 
   * New upstream release

Modified: trunk/libtext-csv-xs-perl/t/12_acc.t
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libtext-csv-xs-perl/t/12_acc.t?rev=48466&op=diff
==============================================================================
--- trunk/libtext-csv-xs-perl/t/12_acc.t (original)
+++ trunk/libtext-csv-xs-perl/t/12_acc.t Tue Dec  8 22:36:19 2009
@@ -3,7 +3,7 @@
 use strict;
 $^W = 1;	# use warnings core since 5.6
 
-use Test::More tests => 86;
+use Test::More tests => 107;
 
 BEGIN {
     use_ok "Text::CSV_XS";
@@ -95,8 +95,21 @@
 like ((Text::CSV_XS::error_diag)[1], qr{^INI - allow_whitespace}, "Wrong combo - error message");
 is   ((Text::CSV_XS::error_diag)[0], 1002, "Wrong combo - numeric error");
 
+# Test 1003 in constructor
+foreach my $x ("\r", "\n", "\r\n", "x\n", "\rx") {
+    foreach my $attr (qw( sep_char quote_char escape_char )) {
+	eval { $csv = Text::CSV_XS->new ({ $attr => $x }) };
+	is ((Text::CSV_XS::error_diag)[0], 1003, "eol in $attr");
+	}
+    }
+# Test 1003 in methods
+foreach my $attr (qw( sep_char quote_char escape_char )) {
+    ok ($csv = Text::CSV_XS->new, "New");
+    eval { ok ($csv->$attr ("\n"), "$attr => \\n") };
+    is (($csv->error_diag)[0], 1003, "not allowed");
+    }
+
 # And test erroneous calls
-
 is (Text::CSV_XS::new (0),		   undef,	"new () as function");
 is (Text::CSV_XS::error_diag (), "usage: my \$csv = Text::CSV_XS->new ([{ option => value, ... }]);",
 							"Generic usage () message");

Modified: trunk/libtext-csv-xs-perl/t/15_flags.t
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libtext-csv-xs-perl/t/15_flags.t?rev=48466&op=diff
==============================================================================
--- trunk/libtext-csv-xs-perl/t/15_flags.t (original)
+++ trunk/libtext-csv-xs-perl/t/15_flags.t Tue Dec  8 22:36:19 2009
@@ -3,7 +3,7 @@
 use strict;
 $^W = 1;	# use warnings core since 5.6
 
-use Test::More tests => 185;
+use Test::More tests => 197;
 
 BEGIN {
     use_ok "Text::CSV_XS";
@@ -210,11 +210,11 @@
     ok (!$csv->parse (qq{"+\r\n"}),	"Quo ESC CR NL");
     }
 
+ok (1, "Testing always_quote");
 {   my $csv = Text::CSV_XS->new ({ always_quote => 0 });
     ok ($csv->combine (1..3),		"Combine");
     is ($csv->string, q{1,2,3},		"String");
     is ($csv->always_quote, 0,		"Attr 0");
-    ok ($csv->combine (1..3),		"Combine");
     ok ($csv->always_quote (1),		"Attr 1");
     ok ($csv->combine (1..3),		"Combine");
     is ($csv->string, q{"1","2","3"},	"String");
@@ -224,3 +224,18 @@
     is ($csv->string, q{1,2,3},		"String");
     is ($csv->always_quote, 0,		"Attr 0");
     }
+
+ok (1, "Testing quote_space");
+{   my $csv = Text::CSV_XS->new ({ quote_space => 1 });
+    ok ($csv->combine (1, " ", 3),	"Combine");
+    is ($csv->string, q{1," ",3},	"String");
+    is ($csv->quote_space, 1,		"Attr 1");
+    is ($csv->quote_space (0), 0,	"Attr 0");
+    ok ($csv->combine (1, " ", 3),	"Combine");
+    is ($csv->string, q{1, ,3},		"String");
+    is ($csv->quote_space, 0,		"Attr 0");
+    is ($csv->quote_space (1), 1,	"Attr 1");
+    ok ($csv->combine (1, " ", 3),	"Combine");
+    is ($csv->string, q{1," ",3},	"String");
+    is ($csv->quote_space, 1,		"Attr 1");
+    }




More information about the Pkg-perl-cvs-commits mailing list