line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package CSS::DOM::Util; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
$VERSION = '0.17'; |
4
|
|
|
|
|
|
|
|
5
|
27
|
|
|
27
|
|
51260
|
use strict; use warnings; no warnings qw 'utf8 parenthesis'; |
|
27
|
|
|
27
|
|
64
|
|
|
27
|
|
|
27
|
|
558
|
|
|
27
|
|
|
|
|
98
|
|
|
27
|
|
|
|
|
47
|
|
|
27
|
|
|
|
|
542
|
|
|
27
|
|
|
|
|
113
|
|
|
27
|
|
|
|
|
38
|
|
|
27
|
|
|
|
|
831
|
|
6
|
|
|
|
|
|
|
|
7
|
27
|
|
|
27
|
|
135
|
use Exporter 5.57 'import'; |
|
27
|
|
|
|
|
344
|
|
|
27
|
|
|
|
|
13809
|
|
8
|
|
|
|
|
|
|
our @EXPORT_OK = qw ' |
9
|
|
|
|
|
|
|
unescape escape |
10
|
|
|
|
|
|
|
escape_ident |
11
|
|
|
|
|
|
|
unescape_url |
12
|
|
|
|
|
|
|
unescape_str escape_str'; |
13
|
|
|
|
|
|
|
our %EXPORT_TAGS = (all=>\@EXPORT_OK); |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub escape($$) { |
17
|
117
|
|
|
117
|
1
|
900
|
my $str = shift; |
18
|
117
|
|
|
|
|
1005
|
my $hex_or_space = qr/[0-9a-fA-F]|(?!$_[0])[ \t]/; |
19
|
117
|
|
|
|
|
885
|
$str =~ s/([\n\r\f]|$_[0])/ |
20
|
86
|
|
|
|
|
136
|
my $c = $1; |
21
|
86
|
100
|
100
|
|
|
611
|
$c =~ m'[ -\/:-@[-`{-~]' |
22
|
|
|
|
|
|
|
? "\\$c" |
23
|
|
|
|
|
|
|
: sprintf '\%x' . ' ' x ( |
24
|
|
|
|
|
|
|
ord $c < 0x100000 && |
25
|
|
|
|
|
|
|
(substr $str, $+[0], 1,||'a') =~ $hex_or_space |
26
|
|
|
|
|
|
|
), ord $c |
27
|
|
|
|
|
|
|
/ge; |
28
|
117
|
|
|
|
|
768
|
$str; |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub unescape($) { |
32
|
3069
|
|
|
3069
|
1
|
4053
|
my $val = shift; |
33
|
3069
|
|
|
|
|
5320
|
$val =~ s/\\(?: |
34
|
|
|
|
|
|
|
([a-fA-F0-9]{1,6})(?:\r\n|[ \n\r\t\f])? |
35
|
|
|
|
|
|
|
| |
36
|
|
|
|
|
|
|
([^\n\r\f0-9a-f]) |
37
|
|
|
|
|
|
|
| |
38
|
|
|
|
|
|
|
(\r\n?|[\n\f]) |
39
|
|
|
|
|
|
|
)/ |
40
|
4203
|
100
|
|
|
|
15782
|
defined $1 ? chr hex $1 : |
|
|
100
|
|
|
|
|
|
41
|
|
|
|
|
|
|
defined $2 ? $2 : |
42
|
|
|
|
|
|
|
'' |
43
|
|
|
|
|
|
|
/gex; |
44
|
3069
|
|
|
|
|
10689
|
$val; |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
sub escape_ident($) { |
48
|
101
|
|
|
101
|
1
|
142
|
my $str = shift; |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
# An identifier can’t have [0-9] for the first character, or for |
51
|
|
|
|
|
|
|
# the second if |
52
|
|
|
|
|
|
|
# the first is [-]. |
53
|
101
|
|
|
|
|
312
|
return escape $str, |
54
|
|
|
|
|
|
|
qr/([\0-,.\/:-\@[-^`{-\177]|^[0-9]|(?<=^-)[0-9])/; |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
sub unescape_url($) { |
58
|
43
|
|
|
43
|
1
|
75
|
my $token = shift; |
59
|
43
|
|
|
|
|
183
|
$token =~ s/^url\([ \t\r\n\f]*//; |
60
|
43
|
|
|
|
|
146
|
$token =~ s/[ \t\r\n\f]*\)\z//; |
61
|
43
|
100
|
|
|
|
115
|
$token =~ s/^['"]// and chop $token; |
62
|
43
|
|
|
|
|
78
|
return unescape $token |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
sub escape_str($) { |
66
|
3
|
|
|
3
|
1
|
16
|
"'" . escape($_[0],qr/'/) . "'" |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
sub unescape_str($) { |
70
|
57
|
|
|
57
|
1
|
160
|
unescape substr $_[0], 1, -1; |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
**__END__** |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
=head1 NAME |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
CSS::DOM::Util - Utility functions for dealing with CSS tokens |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
=head1 VERSION |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
Version 0.17 |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
=head1 SYNOPSIS |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
use CSS::DOM::Util ':all'; |
86
|
|
|
|
|
|
|
# or: |
87
|
|
|
|
|
|
|
use CSS::DOM::Util qw[ |
88
|
|
|
|
|
|
|
escape unescape |
89
|
|
|
|
|
|
|
escape_ident unescape_url |
90
|
|
|
|
|
|
|
escape_str unescape_str |
91
|
|
|
|
|
|
|
]; |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=head1 DESCRIPTION |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
This module provides utility functions for dealing with CSS tokens. |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=head1 FUNCTIONS |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
All functions below that take one argument have a C<($)> prototype, so they |
100
|
|
|
|
|
|
|
have the same precedence as C |
101
|
|
|
|
|
|
|
and C. |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=over |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
=item escape $string, $chars_to_escape |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
This escapes any characters in C<$string> that occur in |
108
|
|
|
|
|
|
|
C<$chars_to_escape>, which is interpreted as a regular expression. The |
109
|
|
|
|
|
|
|
regexp must consume just one character; otherwise you'll find chars |
110
|
|
|
|
|
|
|
missing from the output. ASCII vertical whitespace (except the vertical |
111
|
|
|
|
|
|
|
tab) is always escaped. |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
Printable non-alphanumeric ASCII characters and the space character are |
114
|
|
|
|
|
|
|
escaped with a single |
115
|
|
|
|
|
|
|
backslash. Other characters are encoded in hexadecimal. |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
C also considers that you might want to include the escaped string |
118
|
|
|
|
|
|
|
in a larger string, so it appends a space if the escaped string ends with a |
119
|
|
|
|
|
|
|
hexadecimal escape with fewer than six digits. |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
=item unescape $string |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
This turns something like \"H\65llo\" into "Hello" (including quotes). |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
=item escape_ident $string |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
=item escape_ident $string, $more_chars_to_escape |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
This escapes C<$string> as a CSS identifier, escaping also any characters |
130
|
|
|
|
|
|
|
matched by C<$more_chars_to_escape>. |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
=item unescape_url $url_token |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
Returns the URL that the token represents. |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
=item escape_str $string |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
Returns a CSS string token containing C<$string> (within quotes; characters |
139
|
|
|
|
|
|
|
possibly escaped). |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
=item unescape_str $string_token |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
Returns the value that a CSS string token represents. |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
=back |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
=head1 SEE ALSO |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
L |