my $out;
for ($in) {
pos = 0;
for (;;) {
if (/\G ([^\\]+) /xsgc) { $out .= $1; }
if (/\G \\u([0-9a-fA-F]{4}) /xsgc) { $out .= chr(hex($1)); next; }
if (/\G \\([tnfr]) /xsgc) { $out .= $CONTROL_CODE{$1}; next; }
if (/\G \\(.) /xsgc) { $out .= $1; next; }
if (/\G \z /xsgc) { last; }
die; # Ends with unescaped "\".
}
}
printf("U+%04x\n", ord($_)) for $out =~ /(.)/sg;
Update: Fixed arrangement of conditions.
Update: Changed /\Z/ to /\z/.
In reply to Re: Regex Parsing Style
by ikegami
in thread Regex Parsing Style
by Jim
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |