- Timestamp:
- Aug 20, 2009, 1:29:54 AM (15 years ago)
- Branches:
- master, release-1.10, release-1.4, release-1.5, release-1.6, release-1.7, release-1.8, release-1.9
- Children:
- 0b5168d
- Parents:
- 4cbb1b4
- git-author:
- Anders Kaseorg <andersk@mit.edu> (08/20/09 01:21:30)
- git-committer:
- Anders Kaseorg <andersk@mit.edu> (08/20/09 01:29:54)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
perl/lib/BarnOwl.pm
rcff58b4 rfc92e6e2 290 290 } 291 291 292 =head2 quote STRING 293 294 Return a version of STRING fully quoted to survive processing by 295 BarnOwl's command parser. 292 =head2 quote LIST 293 294 Quotes each of the strings in LIST and returns a string that will be 295 correctly decoded to LIST by the BarnOwl command parser. For example: 296 297 quote('zwrite', 'andersk', '-m', 'Hello, world!') 298 # returns "zwrite andersk -m 'Hello, world!'" 296 299 297 300 =cut 298 301 299 302 sub quote { 300 my $str = shift; 301 return "''" if $str eq ''; 302 if ($str !~ /['" ]/) { 303 return "$str"; 303 my @quoted; 304 for my $str (@_) { 305 if ($str eq '') { 306 push @quoted, "''"; 307 } elsif ($str !~ /['" ]/) { 308 push @quoted, "$str"; 309 } elsif ($str !~ /'/) { 310 push @quoted, "'$str'"; 311 } else { 312 (my $qstr = $str) =~ s/"/"'"'"/g; 313 push @quoted, '"' . $qstr . '"'; 314 } 304 315 } 305 if ($str !~ /'/) { 306 return "'$str'"; 307 } 308 $str =~ s/"/"'"'"/g; 309 return '"' . $str . '"'; 316 return join(' ', @quoted); 310 317 } 311 318
Note: See TracChangeset
for help on using the changeset viewer.