File tree Expand file tree Collapse file tree 1 file changed +6
-16
lines changed Expand file tree Collapse file tree 1 file changed +6
-16
lines changed Original file line number Diff line number Diff line change @@ -32,37 +32,27 @@ ($module,%meta)
32
32
return $ filename ~ " --0" ;
33
33
}
34
34
sub strencode ($ str ) {
35
- return $ str . subst (/(<- alpha - [ _ :] >) /,{ charencode($0 ) },: g);
35
+ return $ str . subst (/(<- alpha - [ : ] >) /,{ charencode($0 ) },: g);
36
36
}
37
37
sub charencode ($ char ) {
38
- my ($ url ,$ hex ) = (' ' ,int2hex( ord $ char ));
38
+ my ($ url ,$ hex ) = (' ' ,$ char . fmt ( " %02x " ));
39
39
40
- $ hex = ' 0' ~ $ hex if ($ hex . chars % 1 );
41
40
while $ hex . chars {
42
- $ url ~ = ' %' ~ $ hex . substr (0 ,2 );
43
- $ hex = $ hex . substr (2 );
41
+ $ url ~ = ' %' ~ $ hex . substr (0 ,2 );
42
+ $ hex = $ hex . substr (2 );
44
43
}
45
44
return $ url ;
46
45
}
47
- sub int2hex ($ val is rw ) {
48
- my $ hex = ' ' ;
49
- while $ val {
50
- my $ tmp = $ val % 16 ;
51
- $ val = int ($ val / 16 );
52
- $ hex = ($ tmp < 10 ?? $ tmp !! chr (97 - 10 + $ tmp )) ~ $ hex ;
53
- }
54
- return $ hex ;
55
- }
56
46
sub fletcher16 ($ str ) {
57
47
my ($ A ,$ B ) = (0 ,0 );
58
48
for map { . ord }, $ str . comb -> $ val {
59
49
if $ val > 255 {
60
- $ A = ($ A + int ( $ val / 255 ) ) % 255 ;
50
+ $ A = ($ A + $ val div 255 ) % 255 ;
61
51
$ B = ($ B + $ A ) % 255 ;
62
52
}
63
53
$ A = ($ A + $ val % 255 ) % 255 ;
64
54
$ B = ($ B + $ A ) % 255 ;
65
55
}
66
- return sprintf " %04s " , int2hex ($ A * 256 + $ B );
56
+ return ($ A * 256 + $ B ) . fmt ( " %04x " );
67
57
}
68
58
You can’t perform that action at this time.
0 commit comments