line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Unicode::Block::Item; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# Pragmas. |
4
|
14
|
|
|
14
|
|
251907
|
use strict; |
|
14
|
|
|
|
|
33
|
|
|
14
|
|
|
|
|
446
|
|
5
|
14
|
|
|
14
|
|
76
|
use warnings; |
|
14
|
|
|
|
|
25
|
|
|
14
|
|
|
|
|
496
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
# Modules. |
8
|
14
|
|
|
14
|
|
12109
|
use Class::Utils qw(set_params); |
|
14
|
|
|
|
|
159436
|
|
|
14
|
|
|
|
|
380
|
|
9
|
14
|
|
|
14
|
|
817
|
use Error::Pure qw(err); |
|
14
|
|
|
|
|
30
|
|
|
14
|
|
|
|
|
530
|
|
10
|
14
|
|
|
14
|
|
78
|
use Readonly; |
|
14
|
|
|
|
|
22
|
|
|
14
|
|
|
|
|
537
|
|
11
|
14
|
|
|
14
|
|
21254
|
use Text::CharWidth qw(mbwidth); |
|
14
|
|
|
|
|
10789
|
|
|
14
|
|
|
|
|
888
|
|
12
|
14
|
|
|
14
|
|
15312
|
use Unicode::Char; |
|
14
|
|
|
|
|
17590
|
|
|
14
|
|
|
|
|
4275
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
# Constants. |
15
|
|
|
|
|
|
|
Readonly::Scalar our $SPACE => q{ }; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
# Version. |
18
|
|
|
|
|
|
|
our $VERSION = 0.03; |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
# Constructor. |
21
|
|
|
|
|
|
|
sub new { |
22
|
23
|
|
|
23
|
1
|
16803
|
my ($class, @params) = @_; |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
# Create object. |
25
|
23
|
|
|
|
|
77
|
my $self = bless {}, $class; |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
# Hexadecimal number. |
28
|
23
|
|
|
|
|
434
|
$self->{'hex'} = undef; |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
# Length of hex number. |
31
|
23
|
|
|
|
|
47
|
$self->{'hex_length'} = 4; |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
# Process parameters. |
34
|
23
|
|
|
|
|
97
|
set_params($self, @params); |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
# Check hex number. |
37
|
21
|
100
|
|
|
|
254
|
if (! defined $self->{'hex'}) { |
38
|
1
|
|
|
|
|
5
|
err "Parameter 'hex' is required."; |
39
|
|
|
|
|
|
|
} |
40
|
20
|
100
|
|
|
|
68
|
if (! $self->_is_hex) { |
41
|
1
|
|
|
|
|
4
|
err "Parameter 'hex' isn't hexadecimal number."; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
# Object. |
45
|
19
|
|
|
|
|
66
|
return $self; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
# Get hex base number. |
49
|
|
|
|
|
|
|
sub base { |
50
|
1
|
|
|
1
|
1
|
5
|
my $self = shift; |
51
|
1
|
|
|
|
|
5
|
my $base = substr $self->hex, 0, -1; |
52
|
1
|
|
|
|
|
5
|
return 'U+'.$base.'x'; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
# Get character. |
56
|
|
|
|
|
|
|
sub char { |
57
|
12
|
|
|
12
|
1
|
1408
|
my $self = shift; |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
# Create object. |
60
|
12
|
100
|
|
|
|
30
|
if (! exists $self->{'u'}) { |
61
|
11
|
|
|
|
|
990
|
$self->{'u'} = Unicode::Char->new; |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
# Get char. |
65
|
12
|
|
|
|
|
101
|
my $char = $self->{'u'}->u($self->{'hex'}); |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
# 'Non-Spacing Mark' and 'Enclosing Mark'. |
68
|
14
|
100
|
100
|
14
|
|
15259
|
if ($char =~ m/\p{Mn}/ms || $char =~ m/\p{Me}/ms) { |
|
14
|
100
|
|
|
|
144
|
|
|
14
|
100
|
|
|
|
190
|
|
|
12
|
|
|
|
|
274
|
|
69
|
4
|
|
|
|
|
6
|
$char = $SPACE.$char; |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
# Control. |
72
|
|
|
|
|
|
|
} elsif ($char =~ m/\p{Cc}/ms) { |
73
|
1
|
|
|
|
|
3
|
$char = $SPACE; |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
# Not Assigned. |
76
|
|
|
|
|
|
|
} elsif ($char =~ m/\p{Cn}/ms) { |
77
|
2
|
|
|
|
|
24
|
$char = $SPACE; |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
12
|
|
|
|
|
81
|
return $char; |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
# Get hex number. |
84
|
|
|
|
|
|
|
sub hex { |
85
|
4
|
|
|
4
|
1
|
25
|
my $self = shift; |
86
|
4
|
|
|
|
|
25
|
return sprintf '%0'.$self->{'hex_length'}.'x', |
87
|
|
|
|
|
|
|
CORE::hex $self->{'hex'}; |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
# Get last hex number. |
91
|
|
|
|
|
|
|
sub last_hex { |
92
|
1
|
|
|
1
|
1
|
7
|
my $self = shift; |
93
|
1
|
|
|
|
|
4
|
return substr $self->{'hex'}, -1; |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
# Get character width. |
97
|
|
|
|
|
|
|
sub width { |
98
|
7
|
|
|
7
|
1
|
523
|
my $self = shift; |
99
|
7
|
100
|
|
|
|
18
|
if (! exists $self->{'_width'}) { |
100
|
6
|
|
|
|
|
17
|
$self->{'_width'} = mbwidth($self->char); |
101
|
6
|
100
|
|
|
|
18
|
if ($self->{'_width'} == -1) { |
102
|
2
|
|
|
|
|
5
|
$self->{'_width'} = 1; |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
} |
105
|
7
|
|
|
|
|
21
|
return $self->{'_width'}; |
106
|
|
|
|
|
|
|
} |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
# Check for hex number. |
109
|
|
|
|
|
|
|
sub _is_hex { |
110
|
20
|
|
|
20
|
|
32
|
my $self = shift; |
111
|
20
|
100
|
|
|
|
145
|
if ($self->{'hex'} !~ m/^[0-9a-fA-F]+$/ims) { |
112
|
1
|
|
|
|
|
7
|
return 0; |
113
|
|
|
|
|
|
|
} |
114
|
19
|
|
|
|
|
56
|
my $int = CORE::hex $self->{'hex'}; |
115
|
19
|
50
|
|
|
|
58
|
if (! defined $int) { |
116
|
0
|
|
|
|
|
0
|
return 0; |
117
|
|
|
|
|
|
|
} |
118
|
19
|
|
|
|
|
81
|
my $hex = sprintf '%x', $int; |
119
|
19
|
|
|
|
|
49
|
my $value = lc $self->{'hex'}; |
120
|
19
|
|
|
|
|
71
|
$value =~ s/^0*//ms; |
121
|
19
|
100
|
|
|
|
58
|
if ($value eq '') { |
122
|
2
|
|
|
|
|
2
|
$value = 0; |
123
|
|
|
|
|
|
|
} |
124
|
19
|
50
|
|
|
|
50
|
if ($hex ne $value) { |
125
|
0
|
|
|
|
|
0
|
return 0; |
126
|
|
|
|
|
|
|
} |
127
|
19
|
|
|
|
|
58
|
return 1; |
128
|
|
|
|
|
|
|
} |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
1; |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
__END__ |