|
Revision 11293, 0.9 kB
(checked in by Darren_Duncan, 3 years ago)
|
|
replaced all 'use v6;' lines with 'use v6-alpha;' in 330 files (examples/, ext/, t/, t_disabled/) ... more remain to do
|
-
Property svn:mime-type set to
text/plain; charset=UTF-8
-
Property svn:eol-style set to
native
|
| Line | |
|---|
| 1 | # Please remember to update examples/output/vmethods/escape if you change this |
|---|
| 2 | # file so its output will change. |
|---|
| 3 | |
|---|
| 4 | use v6-alpha; |
|---|
| 5 | |
|---|
| 6 | multi sub escape (Str $source is copy, Str $lang) { |
|---|
| 7 | given $lang { |
|---|
| 8 | when "html" { |
|---|
| 9 | $source ~~ s:Perl5:g/([&<>"'-])/{ #"#--vim |
|---|
| 10 | $0 eq "&" ?? "&" !! |
|---|
| 11 | $0 eq "<" ?? "<" !! |
|---|
| 12 | $0 eq ">" ?? ">" !! |
|---|
| 13 | $0 eq '"' ?? """ !! |
|---|
| 14 | $0 eq "'" ?? "'" !! |
|---|
| 15 | $0 eq "-" ?? "-" !! die |
|---|
| 16 | }/; |
|---|
| 17 | } |
|---|
| 18 | |
|---|
| 19 | when "doublequote" { |
|---|
| 20 | $source ~~ s:Perl5:g/([\\"])/{ |
|---|
| 21 | $0 eq "\\" ?? "\\\\" !! |
|---|
| 22 | $0 eq "\"" ?? "\\\"" !! die |
|---|
| 23 | }/; |
|---|
| 24 | } |
|---|
| 25 | |
|---|
| 26 | default { |
|---|
| 27 | die '"lang" parameter must be "html"|"doublequote"' unless |
|---|
| 28 | $lang eq any <html doublequote>; |
|---|
| 29 | } |
|---|
| 30 | } |
|---|
| 31 | |
|---|
| 32 | return $source; |
|---|
| 33 | } |
|---|
| 34 | |
|---|
| 35 | say 'This string should be quoted: "\\<>&-"'.escape(:lang<html>); |
|---|
| 36 | say 'This string should be quoted: "\\<>&-"'.escape(:lang<doublequote>); |
|---|