line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Complete::Number; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
our $DATE = '2015-09-09'; # DATE |
4
|
|
|
|
|
|
|
our $VERSION = '0.03'; # VERSION |
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
650
|
use 5.010001; |
|
1
|
|
|
|
|
2
|
|
7
|
1
|
|
|
1
|
|
4
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
17
|
|
8
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
20
|
|
9
|
|
|
|
|
|
|
#use experimental 'smartmatch'; |
10
|
|
|
|
|
|
|
#use Log::Any::IfLOG '$log'; |
11
|
|
|
|
|
|
|
|
12
|
1
|
|
|
1
|
|
727
|
use Complete::Setting; |
|
1
|
|
|
|
|
195
|
|
|
1
|
|
|
|
|
989
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
require Exporter; |
15
|
|
|
|
|
|
|
our @ISA = qw(Exporter); |
16
|
|
|
|
|
|
|
our @EXPORT_OK = qw( |
17
|
|
|
|
|
|
|
complete_int |
18
|
|
|
|
|
|
|
complete_float |
19
|
|
|
|
|
|
|
); |
20
|
|
|
|
|
|
|
our %SPEC; |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
$SPEC{':package'} = { |
23
|
|
|
|
|
|
|
v => 1.1, |
24
|
|
|
|
|
|
|
summary => 'Complete numbers', |
25
|
|
|
|
|
|
|
}; |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
my %common_args = ( |
28
|
|
|
|
|
|
|
word => { schema=>[str=>{default=>''}], pos=>0, req=>1 }, |
29
|
|
|
|
|
|
|
ci => { schema=>['bool'] }, |
30
|
|
|
|
|
|
|
); |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
$SPEC{complete_int} = { |
33
|
|
|
|
|
|
|
v => 1.1, |
34
|
|
|
|
|
|
|
summary => 'Complete integer number', |
35
|
|
|
|
|
|
|
args => { |
36
|
|
|
|
|
|
|
%common_args, |
37
|
|
|
|
|
|
|
max => { schema=>['int'] }, |
38
|
|
|
|
|
|
|
min => { schema=>['int'] }, |
39
|
|
|
|
|
|
|
xmax => { schema=>['int'] }, |
40
|
|
|
|
|
|
|
xmin => { schema=>['int'] }, |
41
|
|
|
|
|
|
|
}, |
42
|
|
|
|
|
|
|
result_naked => 1, |
43
|
|
|
|
|
|
|
result => { |
44
|
|
|
|
|
|
|
schema => 'array', |
45
|
|
|
|
|
|
|
}, |
46
|
|
|
|
|
|
|
}; |
47
|
|
|
|
|
|
|
sub complete_int { |
48
|
4
|
|
|
4
|
1
|
3822
|
require Complete::Util; |
49
|
|
|
|
|
|
|
|
50
|
4
|
|
|
|
|
3239
|
my %args = @_; |
51
|
4
|
|
100
|
|
|
19
|
my $word = $args{word} // ""; |
52
|
4
|
|
33
|
|
|
12
|
my $ci = $args{ci} // $Complete::Setting::OPT_CI; |
53
|
|
|
|
|
|
|
|
54
|
4
|
|
|
|
|
4
|
my @words; |
55
|
|
|
|
|
|
|
|
56
|
4
|
|
|
|
|
5
|
my $limit = 100; |
57
|
4
|
100
|
66
|
|
|
66
|
if(defined($args{min}) && defined($args{max}) && |
|
|
50
|
66
|
|
|
|
|
|
|
50
|
33
|
|
|
|
|
|
|
100
|
33
|
|
|
|
|
|
|
50
|
66
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
|
66
|
|
|
|
|
58
|
|
|
|
|
|
|
$args{max}-$args{min} <= $limit) { |
59
|
1
|
|
|
|
|
5
|
push @words, $args{min} .. $args{max}; |
60
|
|
|
|
|
|
|
} elsif (defined($args{min}) && defined($args{xmax}) && |
61
|
|
|
|
|
|
|
$args{xmax}-$args{min} <= $limit) { |
62
|
0
|
|
|
|
|
0
|
push @words, $args{min} .. $args{xmax}-1; |
63
|
|
|
|
|
|
|
} elsif (defined($args{xmin}) && defined($args{max}) && |
64
|
|
|
|
|
|
|
$args{max}-$args{xmin} <= $limit) { |
65
|
0
|
|
|
|
|
0
|
push @words, $args{xmin}+1 .. $args{max}; |
66
|
|
|
|
|
|
|
} elsif (defined($args{xmin}) && defined($args{xmax}) && |
67
|
|
|
|
|
|
|
$args{xmax}-$args{xmin} <= $limit) { |
68
|
1
|
|
|
|
|
4
|
push @words, $args{xmin}+1 .. $args{xmax}-1; |
69
|
|
|
|
|
|
|
} elsif (length($word) && $word !~ /\A-?\d*\z/) { |
70
|
|
|
|
|
|
|
# warn: not an int |
71
|
|
|
|
|
|
|
} else { |
72
|
|
|
|
|
|
|
# do a digit by digit completion |
73
|
2
|
|
|
|
|
5
|
my @signs = (""); |
74
|
2
|
100
|
|
|
|
10
|
push @signs, "-" if $word =~ /\A-|\A\z/; |
75
|
2
|
|
|
|
|
5
|
for my $sign (@signs) { |
76
|
3
|
|
|
|
|
9
|
for ("", 0..9) { |
77
|
33
|
|
|
|
|
50
|
my $i = $sign . $word . $_; |
78
|
33
|
100
|
|
|
|
58
|
next unless length $i; |
79
|
32
|
100
|
|
|
|
91
|
next unless $i =~ /\A-?\d+\z/; |
80
|
31
|
100
|
|
|
|
57
|
next if $i eq '-0'; |
81
|
30
|
50
|
|
|
|
51
|
next if $i =~ /\A-?0\d/; |
82
|
30
|
50
|
33
|
|
|
60
|
next if defined($args{min} ) && $i < $args{min}; |
83
|
30
|
50
|
33
|
|
|
61
|
next if defined($args{xmin}) && $i <= $args{xmin}; |
84
|
30
|
50
|
33
|
|
|
56
|
next if defined($args{max} ) && $i > $args{max}; |
85
|
30
|
50
|
33
|
|
|
52
|
next if defined($args{xmin}) && $i >= $args{xmax}; |
86
|
30
|
|
|
|
|
57
|
push @words, $i; |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
4
|
|
|
|
|
14
|
Complete::Util::complete_array_elem(array=>\@words, word=>$word, ci=>$ci); |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
$SPEC{complete_float} = { |
95
|
|
|
|
|
|
|
v => 1.1, |
96
|
|
|
|
|
|
|
summary => 'Complete floating number', |
97
|
|
|
|
|
|
|
args => { |
98
|
|
|
|
|
|
|
%common_args, |
99
|
|
|
|
|
|
|
max => { schema=>['float'] }, |
100
|
|
|
|
|
|
|
min => { schema=>['float'] }, |
101
|
|
|
|
|
|
|
xmax => { schema=>['float'] }, |
102
|
|
|
|
|
|
|
xmin => { schema=>['float'] }, |
103
|
|
|
|
|
|
|
}, |
104
|
|
|
|
|
|
|
result_naked => 1, |
105
|
|
|
|
|
|
|
result => { |
106
|
|
|
|
|
|
|
schema => 'array', |
107
|
|
|
|
|
|
|
}, |
108
|
|
|
|
|
|
|
}; |
109
|
|
|
|
|
|
|
sub complete_float { |
110
|
1
|
|
|
1
|
1
|
1934
|
require Complete::Util; |
111
|
|
|
|
|
|
|
|
112
|
1
|
|
|
|
|
2
|
my %args = @_; |
113
|
1
|
|
50
|
|
|
7
|
my $word = $args{word} // ""; |
114
|
1
|
|
33
|
|
|
5
|
my $ci = $args{ci} // $Complete::Setting::OPT_CI; |
115
|
|
|
|
|
|
|
|
116
|
1
|
|
|
|
|
2
|
my @words; |
117
|
|
|
|
|
|
|
|
118
|
1
|
|
|
|
|
3
|
my $limit = 100; |
119
|
|
|
|
|
|
|
|
120
|
1
|
50
|
33
|
|
|
5
|
if (length($word) && $word !~ /\A-?\d*(\.\d*)?\z/) { |
121
|
|
|
|
|
|
|
# warn: not a float |
122
|
|
|
|
|
|
|
} else { |
123
|
1
|
|
|
|
|
3
|
my @signs = (""); |
124
|
1
|
50
|
|
|
|
6
|
push @signs, "-" if $word =~ /\A-|\A\z/; |
125
|
1
|
|
|
|
|
3
|
for my $sign (@signs) { |
126
|
2
|
|
|
|
|
6
|
for ("", 0..9, |
127
|
|
|
|
|
|
|
".0",".1",".2",".3",".4",".5",".6",".7",".8",".9") { |
128
|
42
|
|
|
|
|
125
|
my $f = $sign . $word . $_; |
129
|
42
|
100
|
|
|
|
62
|
next unless length $f; |
130
|
41
|
100
|
|
|
|
119
|
next unless $f =~ /\A-?\d+(\.\d+)?\z/; |
131
|
20
|
100
|
|
|
|
38
|
next if $f eq '-0'; |
132
|
19
|
50
|
|
|
|
32
|
next if $f =~ /\A-?0\d\z/; |
133
|
19
|
50
|
33
|
|
|
39
|
next if defined($args{min} ) && $f < $args{min}; |
134
|
19
|
50
|
33
|
|
|
38
|
next if defined($args{xmin}) && $f <= $args{xmin}; |
135
|
19
|
50
|
33
|
|
|
37
|
next if defined($args{max} ) && $f > $args{max}; |
136
|
19
|
50
|
33
|
|
|
38
|
next if defined($args{xmin}) && $f >= $args{xmax}; |
137
|
19
|
|
|
|
|
32
|
push @words, $f; |
138
|
|
|
|
|
|
|
} |
139
|
|
|
|
|
|
|
} |
140
|
|
|
|
|
|
|
} |
141
|
|
|
|
|
|
|
|
142
|
1
|
|
|
|
|
5
|
Complete::Util::complete_array_elem(array=>\@words, word=>$word, ci=>$ci); |
143
|
|
|
|
|
|
|
} |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
1; |
147
|
|
|
|
|
|
|
# ABSTRACT: Complete numbers |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
__END__ |