line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package String::SimpleEscape; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY |
4
|
|
|
|
|
|
|
our $DATE = '2020-05-28'; # DATE |
5
|
|
|
|
|
|
|
our $DIST = 'String-SimpleEscape'; # DIST |
6
|
|
|
|
|
|
|
our $VERSION = '0.001'; # VERSION |
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
69105
|
use strict; |
|
1
|
|
|
|
|
10
|
|
|
1
|
|
|
|
|
32
|
|
9
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
32
|
|
10
|
|
|
|
|
|
|
|
11
|
1
|
|
|
1
|
|
6
|
use Exporter 'import'; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
288
|
|
12
|
|
|
|
|
|
|
our @EXPORT_OK = qw(simple_escape_string simple_unescape_string); |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
my %escape = ( |
15
|
|
|
|
|
|
|
"\012" => "\\n", |
16
|
|
|
|
|
|
|
"\t" => "\\t", |
17
|
|
|
|
|
|
|
"\\" => "\\\\", |
18
|
|
|
|
|
|
|
"\"" => "\\\"", |
19
|
|
|
|
|
|
|
); |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
my %unescape = ( |
22
|
|
|
|
|
|
|
"\\n" => "\012", |
23
|
|
|
|
|
|
|
"\\t" => "\t", |
24
|
|
|
|
|
|
|
"\\\\" => "\\", |
25
|
|
|
|
|
|
|
"\\\"" => "\"", |
26
|
|
|
|
|
|
|
); |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub simple_escape_string { |
29
|
3
|
|
|
3
|
1
|
1218
|
my $str = shift; |
30
|
3
|
|
|
|
|
20
|
$str =~ s/([\012\011\\"])/$escape{$1}/g; |
31
|
3
|
|
|
|
|
15
|
$str; |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
sub simple_unescape_string { |
34
|
4
|
|
|
4
|
1
|
2689
|
my $str = shift; |
35
|
4
|
|
|
|
|
23
|
$str =~ s/(\\n|\\t|\\\\|\\")/$unescape{$1}/g; |
36
|
4
|
|
|
|
|
17
|
$str; |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
1; |
40
|
|
|
|
|
|
|
# ABSTRACT: Simple string escaping & unescaping |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
__END__ |