/[suikacvs]/messaging/manakai/lib/Message/Field/CSV.pm
Suika

Diff of /messaging/manakai/lib/Message/Field/CSV.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.2 by wakaba, Sat Mar 23 11:41:36 2002 UTC revision 1.3 by wakaba, Mon Mar 25 10:15:26 2002 UTC
# Line 34  $REG{dot_word} = qr/(?:$REG{atext}|$REG{ Line 34  $REG{dot_word} = qr/(?:$REG{atext}|$REG{
34  $REG{phrase} = qr/(?:$REG{atext}|$REG{quoted_string})(?:$REG{atext}|$REG{quoted_string}|\.|$REG{FWS})*/;  $REG{phrase} = qr/(?:$REG{atext}|$REG{quoted_string})(?:$REG{atext}|$REG{quoted_string}|\.|$REG{FWS})*/;
35  $REG{M_quoted_string} = qr/\x22((?:\x5C[\x00-\xFF]|[\x00-\x0C\x0E-\x21\x23-\x5B\x5D-\xFF])*)\x22/;  $REG{M_quoted_string} = qr/\x22((?:\x5C[\x00-\xFF]|[\x00-\x0C\x0E-\x21\x23-\x5B\x5D-\xFF])*)\x22/;
36  $REG{NON_atom} = qr/[^\x09\x21\x23-\x27\x2A\x2B\x2D\x2F\x30-\x39\x3D\x3F\x41-\x5A\x5E-\x7E\x2E]/;  $REG{NON_atom} = qr/[^\x09\x21\x23-\x27\x2A\x2B\x2D\x2F\x30-\x39\x3D\x3F\x41-\x5A\x5E-\x7E\x2E]/;
37    $REG{S_encoded_word} = qr/=\x3F$REG{atext_dot}\x3F=/;
38    
39  ## Keywords: foo, bar, "and so on"  ## Keywords: foo, bar, "and so on"
40  ## Newsgroups: local.test,local.foo,local.bar  ## Newsgroups: local.test,local.foo,local.bar
 ## Content-Type: text/plain; charset=us-ascii  
 ## Content-Transfer-Encoding: base64  
41  ## Accept: text/html; q=1.0, text/plain; q=0.03; *; q=0.01  ## Accept: text/html; q=1.0, text/plain; q=0.03; *; q=0.01
42    
43  %OPTION = (  %OPTION = (
44    field_name    => 'keywords',    field_name    => 'keywords',
45      encoding_after_encode => '*default',
46      encoding_before_decode        => '*default',
47      hook_encode_string    => #sub {shift; (value => shift, @_)},
48            \&Message::Util::encode_header_string,
49      hook_decode_string    => #sub {shift; (value => shift, @_)},
50            \&Message::Util::decode_header_string,
51    is_quoted_string      => 1,   ## Can itself quoted-string?    is_quoted_string      => 1,   ## Can itself quoted-string?
52    separator     => ', ',    separator     => ', ',
53    max   => -1,    max   => -1,
54    value_type    => ':none:',    value_type    => [':none:'],
55  );  );
56    
57  sub _init_option ($$) {  sub _init_option ($$) {
# Line 67  sub _init_option ($$) { Line 72  sub _init_option ($$) {
72      $self->{option}->{value_type} = ['Message::Field::ValueParams'];      $self->{option}->{value_type} = ['Message::Field::ValueParams'];
73    } elsif ($field_name eq 'accept') {    } elsif ($field_name eq 'accept') {
74      $self->{option}->{is_quoted_string} = -1;      $self->{option}->{is_quoted_string} = -1;
75        $self->{option}->{value_type} = ['Message::Field::ValueParams'];
76    } elsif ($field_name eq 'encrypted') {    } elsif ($field_name eq 'encrypted') {
77      $self->{option}->{max} = 2;      $self->{option}->{max} = 2;
78    }    }
# Line 113  sub _parse_list ($$) { Line 119  sub _parse_list ($$) {
119    $fb =~ s{((?:$REG{quoted_string}|$REG{domain_literal}|[^\x22\x2C\x5B])+)}{    $fb =~ s{((?:$REG{quoted_string}|$REG{domain_literal}|[^\x22\x2C\x5B])+)}{
120      my $s = $1;  $s =~ s/^$REG{WSP}+//;  $s =~ s/$REG{WSP}+$//;      my $s = $1;  $s =~ s/^$REG{WSP}+//;  $s =~ s/$REG{WSP}+$//;
121      if ($self->{option}->{is_quoted_string}>0) {      if ($self->{option}->{is_quoted_string}>0) {
122        push @ids, $self->_value ($self->_unquote_quoted_string ($s));        push @ids, $self->_value ($self->_decode_quoted_string ($s));
123      } else {      } else {
124        push @ids, $self->_value ($s);        push @ids, $self->_value ($s);
125      }      }
# Line 174  sub stringify ($;%) { Line 180  sub stringify ($;%) {
180    $option{max} = $#{$self->{value}} if $option{max}<0;    $option{max} = $#{$self->{value}} if $option{max}<0;
181    $option{max} = $#{$self->{value}} if $#{$self->{value}}<$option{max};    $option{max} = $#{$self->{value}} if $#{$self->{value}}<$option{max};
182    join $option{separator},    join $option{separator},
183      map {$option{is_quoted_string}>0?$self->_quote_unsafe_string ($_):$_}      map {
184      @{$self->{value}}[0..$option{max}];        if ($option{is_quoted_string}>0) {
185            my %s = &{$self->{option}->{hook_encode_string}} ($self,
186              $_, type => 'phrase');
187            $self->_quote_unsafe_string ($s{value});
188          } else {
189            $_;
190          }
191        } @{$self->{value}}[0..$option{max}];
192  }  }
193    
194  sub _delete_empty ($) {  sub _delete_empty ($) {
# Line 189  sub _quote_unsafe_string ($$) { Line 202  sub _quote_unsafe_string ($$) {
202    my $self = shift;    my $self = shift;
203    my $string = shift;    my $string = shift;
204    if ($string =~ /$REG{NON_atom}/ || $string =~ /$REG{WSP}$REG{WSP}+/) {    if ($string =~ /$REG{NON_atom}/ || $string =~ /$REG{WSP}$REG{WSP}+/) {
205      $string =~ s/([\x22\x5C])/\x5C$1/g;      $string =~ s/([\x22\x5C])([\x20-\xFF])?/"\x5C$1".($2?"\x5C$2":'')/ge;
206      $string = '"'.$string.'"';      $string = '"'.$string.'"';
207    }    }
208    $string;    $string;
# Line 214  sub _unquote_quoted_string ($$) { Line 227  sub _unquote_quoted_string ($$) {
227    }goex;    }goex;
228    $quoted_string;    $quoted_string;
229  }  }
230    
231    sub _decode_quoted_string ($$) {
232      my $self = shift;
233      my $quoted_string = shift;
234      $quoted_string =~ s{$REG{M_quoted_string}|([^\x22]+)}{
235        my ($qtext,$t) = ($1, $2);
236        if ($t) {
237          my %s = &{$self->{option}->{hook_decode_string}} ($self, $t,
238                    type => 'phrase');
239          $s{value};
240        } else {
241          $qtext =~ s/\x5C([\x00-\xFF])/$1/g;
242          my %s = &{$self->{option}->{hook_decode_string}} ($self, $qtext,
243                    type => 'phrase/quoted');
244          $s{value};
245        }
246      }goex;
247      $quoted_string;
248    }
249    
250  =head2 $self->_delete_comment ($field_body)  =head2 $self->_delete_comment ($field_body)
251    

Legend:
Removed from v.1.2  
changed lines
  Added in v.1.3

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24