line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Parse::Number::EN; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
our $DATE = '2015-09-03'; # DATE |
4
|
|
|
|
|
|
|
our $VERSION = '0.06'; # VERSION |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
# TODO: make it OO and customize thousand sep & decimal point |
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
596
|
use 5.010001; |
|
1
|
|
|
|
|
3
|
|
9
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
18
|
|
10
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
20
|
|
11
|
|
|
|
|
|
|
|
12
|
1
|
|
|
1
|
|
747
|
use Exporter::Lite; |
|
1
|
|
|
|
|
753
|
|
|
1
|
|
|
|
|
6
|
|
13
|
|
|
|
|
|
|
our @EXPORT_OK = qw($Pat parse_number_en); |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
our %SPEC; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
#our $Pat = qr/(?: |
18
|
|
|
|
|
|
|
# [+-]? |
19
|
|
|
|
|
|
|
# (?: |
20
|
|
|
|
|
|
|
# (?:\d{1,3}(?:[,]\d{3})+ | \d+) (?:[.]\d*)? | # english |
21
|
|
|
|
|
|
|
# [.]\d+ |
22
|
|
|
|
|
|
|
# ) |
23
|
|
|
|
|
|
|
# (?:[Ee][+-]?\d+)? |
24
|
|
|
|
|
|
|
# )/x; |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
# non /x version |
27
|
|
|
|
|
|
|
our $Pat = '(?:[+-]?(?:(?:\d{1,3}(?:[,]\d{3})+|\d+)(?:[.]\d*)?|[.]\d+)(?:[Ee][+-]?\d+)?)'; |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
$SPEC{parse_number_en} = { |
30
|
|
|
|
|
|
|
v => 1.1, |
31
|
|
|
|
|
|
|
summary => 'Parse number from English text', |
32
|
|
|
|
|
|
|
description => <<'_', |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
This function can parse number with thousand separators (e.g. 10,000). |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
In the future percentage (e.g. 10.2%) and fractions (e.g. 1/3, 2 1/2) might also |
37
|
|
|
|
|
|
|
be supported. |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
_ |
40
|
|
|
|
|
|
|
args => { |
41
|
|
|
|
|
|
|
text => { |
42
|
|
|
|
|
|
|
summary => 'The input text that contains number', |
43
|
|
|
|
|
|
|
schema => 'str*', |
44
|
|
|
|
|
|
|
req => 1, |
45
|
|
|
|
|
|
|
pos => 0, |
46
|
|
|
|
|
|
|
}, |
47
|
|
|
|
|
|
|
}, |
48
|
|
|
|
|
|
|
result_naked => 1, |
49
|
|
|
|
|
|
|
}; |
50
|
|
|
|
|
|
|
sub parse_number_en { |
51
|
30
|
|
|
30
|
1
|
69872
|
my %args = @_; |
52
|
30
|
|
|
|
|
49
|
my $text = $args{text}; |
53
|
|
|
|
|
|
|
|
54
|
30
|
100
|
|
|
|
300
|
return undef unless $text =~ s/^\s*($Pat)//s; |
55
|
24
|
|
|
|
|
53
|
my $n = $1; |
56
|
24
|
|
|
|
|
41
|
$n =~ s/,//g; |
57
|
24
|
|
|
|
|
98
|
$n+0; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
1; |
61
|
|
|
|
|
|
|
# ABSTRACT: Parse number from English text |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
__END__ |