in reply to Re^3: Thanks to Ikegami, Chromatic & Corion
in thread Thanks to Ikegami, Chromatic & Corion
"&" is not a meta character in aXML unless followed by "lab;" or one of the other 5, so "&" outputs "&", so "&lab;special&rab;" produces "&lab;special&rab;".
To output "&lab;special&rab;" one needs "<special>lab</special>special<special>rab</special>".
The escape function is:
my %escapes = ( '<' => '&lab;', '>' => '&rab;', '(' => '&lcb;', ')' => '&rcb;', '[' => '&lsb;', ']' => '&rsb;', '&lab;' => '<special>lab</special>', '&lcb;' => '<special>lcb</special>', '&lsb;' => '<special>lsb</special>', '&rab;' => '<special>rab</special>', '&rcb;' => '<special>rcb</special>', '&rsb;' => '<special>rsb</special>', ); #my $escapes_pat = join '', map quotemeta, keys %escapes; #my $escapes_re = qr/$escapes_pat/; my $escapes_re = qr/[<>()\[\]]|&[lr][acs]b;/; # Manually tweaked. sub escape(_) { my ($s) = @_; $s =~ s/($escapes_re)/$escapes{$1}/g; return $s; }
These are probably better choices:
my %escapes = qw( & & < &LAB; > &RAB; ( &LCB; ) &RCB; [ &LSB; ] &R +SB; ); sub escape(_) { my ($s) = @_; $s =~ s(/[&<>()\[\]])/$escapes{$1}/g; return $s; }
Or using v5.14's s///r:
my %escapes = qw( & & < &LAB; > &RAB; ( &LCB; ) &RCB; [ &LSB; ] &R +SB; ); sub escape(_) { $_[0] =~ s(/[&<>()\[\]])/$escapes{$1}/gr }
Why is "parenthesis" abbreviated to "c"? I think reading the "c" as curly, but "{" and "}" are the curly brackets.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^5: Thanks to Ikegami, Chromatic & Corion
by Logicus (Initiate) on Nov 02, 2011 at 02:12 UTC | |
by ikegami (Patriarch) on Nov 02, 2011 at 04:56 UTC | |
by Logicus (Initiate) on Nov 02, 2011 at 13:38 UTC | |
by ikegami (Patriarch) on Nov 02, 2011 at 19:50 UTC | |
by Logicus (Initiate) on Nov 02, 2011 at 20:56 UTC | |
| |
|
Re^5: Thanks to Ikegami, Chromatic & Corion
by Logicus (Initiate) on Nov 02, 2011 at 02:27 UTC | |
by Logicus (Initiate) on Nov 02, 2011 at 02:33 UTC | |
by Anonymous Monk on Nov 02, 2011 at 02:37 UTC | |
| |
by Logicus (Initiate) on Nov 02, 2011 at 02:37 UTC | |
by ikegami (Patriarch) on Nov 02, 2011 at 05:14 UTC | |
|