Filename | /home/s1/perl5/perlbrew/perls/perl-5.22.1/lib/site_perl/5.22.1/Parse/Number/EN.pm |
Statements | Executed 14 statements in 1.59ms |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
1 | 1 | 1 | 1.19ms | 1.21ms | BEGIN@12 | Parse::Number::EN::
1 | 1 | 1 | 35µs | 35µs | BEGIN@8 | Parse::Number::EN::
1 | 1 | 1 | 14µs | 19µs | BEGIN@9 | Parse::Number::EN::
1 | 1 | 1 | 12µs | 19µs | BEGIN@10 | Parse::Number::EN::
0 | 0 | 0 | 0s | 0s | parse_number_en | Parse::Number::EN::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | package Parse::Number::EN; | ||||
2 | |||||
3 | 1 | 700ns | our $DATE = '2016-06-14'; # DATE | ||
4 | 1 | 300ns | our $VERSION = '0.07'; # VERSION | ||
5 | |||||
6 | # TODO: make it OO and customize thousand sep & decimal point | ||||
7 | |||||
8 | 2 | 77µs | 1 | 35µs | # spent 35µs within Parse::Number::EN::BEGIN@8 which was called:
# once (35µs+0s) by DateTime::Format::Alami::EN::BEGIN@14 at line 8 # spent 35µs making 1 call to Parse::Number::EN::BEGIN@8 |
9 | 2 | 40µs | 2 | 24µs | # spent 19µs (14+5) within Parse::Number::EN::BEGIN@9 which was called:
# once (14µs+5µs) by DateTime::Format::Alami::EN::BEGIN@14 at line 9 # spent 19µs making 1 call to Parse::Number::EN::BEGIN@9
# spent 5µs making 1 call to strict::import |
10 | 2 | 42µs | 2 | 27µs | # spent 19µs (12+7) within Parse::Number::EN::BEGIN@10 which was called:
# once (12µs+7µs) by DateTime::Format::Alami::EN::BEGIN@14 at line 10 # spent 19µs making 1 call to Parse::Number::EN::BEGIN@10
# spent 7µs making 1 call to warnings::import |
11 | |||||
12 | 2 | 1.41ms | 2 | 1.23ms | # spent 1.21ms (1.19+21µs) within Parse::Number::EN::BEGIN@12 which was called:
# once (1.19ms+21µs) by DateTime::Format::Alami::EN::BEGIN@14 at line 12 # spent 1.21ms making 1 call to Parse::Number::EN::BEGIN@12
# spent 21µs making 1 call to Exporter::import |
13 | 1 | 2µs | 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 | 1 | 200ns | our $Pat = '(?:[+-]?(?:(?:\d{1,3}(?:[,]\d{3})+|\d+)(?:[.]\d*)?|[.]\d+)(?:[Ee][+-]?\d+)?)'; | ||
28 | |||||
29 | $SPEC{parse_number_en} = { | ||||
30 | 1 | 8µs | 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 | my %args = @_; | ||||
52 | my $text = $args{text}; | ||||
53 | |||||
54 | return undef unless $text =~ s/^\s*($Pat)//s; | ||||
55 | my $n = $1; | ||||
56 | $n =~ s/,//g; | ||||
57 | $n+0; | ||||
58 | } | ||||
59 | |||||
60 | 1 | 9µs | 1; | ||
61 | # ABSTRACT: Parse number from English text | ||||
62 | |||||
63 | __END__ |