| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package String::Dirify; |
|
2
|
|
|
|
|
|
|
|
|
3
|
3
|
|
|
3
|
|
38904
|
use strict; |
|
|
3
|
|
|
|
|
3
|
|
|
|
3
|
|
|
|
|
68
|
|
|
4
|
3
|
|
|
3
|
|
9
|
use warnings; |
|
|
3
|
|
|
|
|
3
|
|
|
|
3
|
|
|
|
|
1801
|
|
|
5
|
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
require Exporter; |
|
7
|
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our @ISA = qw(Exporter); |
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
# Items to export into callers namespace by default. Note: do not export |
|
11
|
|
|
|
|
|
|
# names by default without a very good reason. Use EXPORT_OK instead. |
|
12
|
|
|
|
|
|
|
# Do not simply export all your public functions/methods/constants. |
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
# This allows the declaration use String::Dirify ':all'; |
|
15
|
|
|
|
|
|
|
# If you do not need this, moving things directly into @EXPORT or @EXPORT_OK |
|
16
|
|
|
|
|
|
|
# will save memory. |
|
17
|
|
|
|
|
|
|
our %EXPORT_TAGS = ( 'all' => [ qw( |
|
18
|
|
|
|
|
|
|
dirify |
|
19
|
|
|
|
|
|
|
) ] ); |
|
20
|
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } ); |
|
22
|
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
our @EXPORT = qw( |
|
24
|
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
); |
|
26
|
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
our $VERSION = '1.03'; |
|
28
|
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
# ------------------------------------------------ |
|
30
|
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
my(%high_ASCII_char) = |
|
32
|
|
|
|
|
|
|
( |
|
33
|
|
|
|
|
|
|
"\xc0" => 'A', # A` |
|
34
|
|
|
|
|
|
|
"\xe0" => 'a', # a` |
|
35
|
|
|
|
|
|
|
"\xc1" => 'A', # A' |
|
36
|
|
|
|
|
|
|
"\xe1" => 'a', # a' |
|
37
|
|
|
|
|
|
|
"\xc2" => 'A', # A^ |
|
38
|
|
|
|
|
|
|
"\xe2" => 'a', # a^ |
|
39
|
|
|
|
|
|
|
"\xc4" => 'A', # A: |
|
40
|
|
|
|
|
|
|
"\xe4" => 'a', # a: |
|
41
|
|
|
|
|
|
|
"\xc5" => 'A', # Aring |
|
42
|
|
|
|
|
|
|
"\xe5" => 'a', # aring |
|
43
|
|
|
|
|
|
|
"\xc6" => 'AE', # AE |
|
44
|
|
|
|
|
|
|
"\xe6" => 'ae', # ae |
|
45
|
|
|
|
|
|
|
"\xc3" => 'A', # A~ |
|
46
|
|
|
|
|
|
|
"\xe3" => 'a', # a~ |
|
47
|
|
|
|
|
|
|
"\xc8" => 'E', # E` |
|
48
|
|
|
|
|
|
|
"\xe8" => 'e', # e` |
|
49
|
|
|
|
|
|
|
"\xc9" => 'E', # E' |
|
50
|
|
|
|
|
|
|
"\xe9" => 'e', # e' |
|
51
|
|
|
|
|
|
|
"\xca" => 'E', # E^ |
|
52
|
|
|
|
|
|
|
"\xea" => 'e', # e^ |
|
53
|
|
|
|
|
|
|
"\xcb" => 'E', # E: |
|
54
|
|
|
|
|
|
|
"\xeb" => 'e', # e: |
|
55
|
|
|
|
|
|
|
"\xcc" => 'I', # I` |
|
56
|
|
|
|
|
|
|
"\xec" => 'i', # i` |
|
57
|
|
|
|
|
|
|
"\xcd" => 'I', # I' |
|
58
|
|
|
|
|
|
|
"\xed" => 'i', # i' |
|
59
|
|
|
|
|
|
|
"\xce" => 'I', # I^ |
|
60
|
|
|
|
|
|
|
"\xee" => 'i', # i^ |
|
61
|
|
|
|
|
|
|
"\xcf" => 'I', # I: |
|
62
|
|
|
|
|
|
|
"\xef" => 'i', # i: |
|
63
|
|
|
|
|
|
|
"\xd2" => 'O', # O` |
|
64
|
|
|
|
|
|
|
"\xf2" => 'o', # o` |
|
65
|
|
|
|
|
|
|
"\xd3" => 'O', # O' |
|
66
|
|
|
|
|
|
|
"\xf3" => 'o', # o' |
|
67
|
|
|
|
|
|
|
"\xd4" => 'O', # O^ |
|
68
|
|
|
|
|
|
|
"\xf4" => 'o', # o^ |
|
69
|
|
|
|
|
|
|
"\xd6" => 'O', # O: |
|
70
|
|
|
|
|
|
|
"\xf6" => 'o', # o: |
|
71
|
|
|
|
|
|
|
"\xd5" => 'O', # O~ |
|
72
|
|
|
|
|
|
|
"\xf5" => 'o', # o~ |
|
73
|
|
|
|
|
|
|
"\xd8" => 'O', # O/ |
|
74
|
|
|
|
|
|
|
"\xf8" => 'o', # o/ |
|
75
|
|
|
|
|
|
|
"\xd9" => 'U', # U` |
|
76
|
|
|
|
|
|
|
"\xf9" => 'u', # u` |
|
77
|
|
|
|
|
|
|
"\xda" => 'U', # U' |
|
78
|
|
|
|
|
|
|
"\xfa" => 'u', # u' |
|
79
|
|
|
|
|
|
|
"\xdb" => 'U', # U^ |
|
80
|
|
|
|
|
|
|
"\xfb" => 'u', # u^ |
|
81
|
|
|
|
|
|
|
"\xdc" => 'U', # U: |
|
82
|
|
|
|
|
|
|
"\xfc" => 'u', # u: |
|
83
|
|
|
|
|
|
|
"\xc7" => 'C', # ,C |
|
84
|
|
|
|
|
|
|
"\xe7" => 'c', # ,c |
|
85
|
|
|
|
|
|
|
"\xd1" => 'N', # N~ |
|
86
|
|
|
|
|
|
|
"\xf1" => 'n', # n~ |
|
87
|
|
|
|
|
|
|
"\xdd" => 'Y', # Yacute |
|
88
|
|
|
|
|
|
|
"\xfd" => 'y', # yacute |
|
89
|
|
|
|
|
|
|
"\xdf" => 'ss', # szlig |
|
90
|
|
|
|
|
|
|
"\xff" => 'y' # yuml |
|
91
|
|
|
|
|
|
|
); |
|
92
|
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
my($high_ASCII_re) = join '|', keys %high_ASCII_char; |
|
94
|
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
# ------------------------------------------------ |
|
96
|
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
sub convert_high_ascii |
|
98
|
|
|
|
|
|
|
{ |
|
99
|
|
|
|
|
|
|
# require MT::I18N; |
|
100
|
|
|
|
|
|
|
# MT::I18N::convert_high_ascii(@_); |
|
101
|
|
|
|
|
|
|
|
|
102
|
12
|
|
|
12
|
0
|
12
|
my($self, $s) = @_; |
|
103
|
12
|
|
|
|
|
378
|
$s =~ s/($high_ASCII_re)/$high_ASCII_char{$1}/g; |
|
104
|
|
|
|
|
|
|
|
|
105
|
12
|
|
|
|
|
39
|
return $s; |
|
106
|
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
} # End of convert_high_ascii. |
|
108
|
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
# ------------------------------------------------ |
|
110
|
|
|
|
|
|
|
# Re-use just the parts we need of Movable Type's 'dirify' function. |
|
111
|
|
|
|
|
|
|
# The purpose is to take any string and make it a valid directory name. |
|
112
|
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
sub dirify |
|
114
|
|
|
|
|
|
|
{ |
|
115
|
|
|
|
|
|
|
# ($MT::VERSION && MT->instance->{cfg}->PublishCharset =~ m/utf-?8/i) |
|
116
|
|
|
|
|
|
|
# ? utf8_dirify(@_) : iso_dirify(@_); |
|
117
|
|
|
|
|
|
|
|
|
118
|
12
|
|
|
12
|
0
|
25
|
my($self); |
|
119
|
|
|
|
|
|
|
|
|
120
|
12
|
100
|
|
|
|
27
|
if (ref $_[0]) # Handle calls like $o = String::Dirify -> new(); $d = $o -> dirify($s). |
|
|
|
100
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
{ |
|
122
|
4
|
|
|
|
|
7
|
$self = shift; |
|
123
|
|
|
|
|
|
|
} |
|
124
|
|
|
|
|
|
|
elsif ($_[0] eq __PACKAGE__) # Handle calls like $d = String::Dirify -> dirify($s). |
|
125
|
|
|
|
|
|
|
{ |
|
126
|
1
|
|
|
|
|
2
|
$self = new(shift @_); |
|
127
|
|
|
|
|
|
|
} |
|
128
|
|
|
|
|
|
|
else # Handle calls like $d = dirify($s). |
|
129
|
|
|
|
|
|
|
{ |
|
130
|
7
|
|
|
|
|
13
|
$self = new(__PACKAGE__); |
|
131
|
|
|
|
|
|
|
} |
|
132
|
|
|
|
|
|
|
|
|
133
|
12
|
|
|
|
|
25
|
return $self -> iso_dirify(@_); |
|
134
|
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
} # End of dirify. |
|
136
|
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
# ------------------------------------------------ |
|
138
|
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
sub iso_dirify |
|
140
|
|
|
|
|
|
|
{ |
|
141
|
12
|
|
|
12
|
0
|
12
|
my($self, $s, $sep) = @_; |
|
142
|
|
|
|
|
|
|
|
|
143
|
12
|
50
|
|
|
|
23
|
return '' if (! defined $s); |
|
144
|
|
|
|
|
|
|
|
|
145
|
12
|
100
|
100
|
|
|
35
|
$sep = defined($sep) && ($sep ne '1') ? $sep : '_'; |
|
146
|
12
|
|
|
|
|
19
|
$s = $self -> convert_high_ascii($s); # Convert high-ASCII chars to 7-bit. |
|
147
|
12
|
|
|
|
|
30
|
$s = $self -> remove_html(lc $s); # Lower case, and remove HTML tags. |
|
148
|
12
|
|
|
|
|
16
|
$s =~ s!&[^;\s]+;!!gs; # Remove HTML entities. |
|
149
|
12
|
|
|
|
|
35
|
$s =~ s![^\w\s-]!!gs; # Remove non-word/space chars. |
|
150
|
12
|
|
|
|
|
17
|
$s =~ s!\s+!$sep!gs; # Change runs of spaces to the separator char. |
|
151
|
|
|
|
|
|
|
|
|
152
|
12
|
|
|
|
|
58
|
return $s; |
|
153
|
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
} # End of iso_dirify. |
|
155
|
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
# ------------------------------------------------ |
|
157
|
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
sub new |
|
159
|
|
|
|
|
|
|
{ |
|
160
|
9
|
|
|
9
|
0
|
18
|
my($class) = @_; |
|
161
|
|
|
|
|
|
|
|
|
162
|
9
|
|
|
|
|
19
|
return bless {}, $class; |
|
163
|
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
} # End of new. |
|
165
|
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
# ------------------------------------------------ |
|
167
|
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
sub remove_html |
|
169
|
|
|
|
|
|
|
{ |
|
170
|
12
|
|
|
12
|
0
|
14
|
my($self, $text) = @_; |
|
171
|
|
|
|
|
|
|
|
|
172
|
12
|
50
|
|
|
|
21
|
return $text if (! defined $text); # Suppress warnings. |
|
173
|
12
|
100
|
|
|
|
33
|
return $text if $text =~ m/^<\!\[CDATA\[/i; # We need /i because lc() has been called. |
|
174
|
|
|
|
|
|
|
|
|
175
|
10
|
|
|
|
|
25
|
$text =~ s!<[^>]+>!!gs; # Remove all '<'s which have matching '>'s. |
|
176
|
10
|
|
|
|
|
8
|
$text =~ s!
|
|
177
|
|
|
|
|
|
|
|
|
178
|
10
|
|
|
|
|
11
|
return $text; |
|
179
|
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
} # End of remove_html. |
|
181
|
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
# ------------------------------------------------ |
|
183
|
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
1; |
|
185
|
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
__END__ |