| 1 | # For Emacs: -*- mode:cperl; eval: (folding-mode 1); -*- | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | package Lingua::SWE::Num2Word; | ||||||||||||||||||||||||||||
| 4 | # ABSTRACT: Number to word conversion in Swedish | ||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use 5.16.0; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 1 | ▶ | use utf8; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | # {{{ use block | ||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 1 | ▶ | use Export::Attrs; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | # }}} | ||||||||||||||||||||||||||||
| 15 | # {{{ variables declaration | ||||||||||||||||||||||||||||
| 16 | 1 | our $VERSION = '0.2603260'; | |||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | # }}} | ||||||||||||||||||||||||||||
| 19 | # {{{ num2sv_cardinal convert number to text | ||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | sub num2sv_cardinal :Export { | ||||||||||||||||||||||||||||
| 22 | 8 | ▶ | my $positive = shift // return 'noll'; | ||||||||||||||||||||||||||
|
Subroutine
num2sv_cardinal: called CC=15 SCAR=34.9
Pod
documented
Condition100%2/2
shift() // (return "noll")
MC/DC100%1/1
shift() // (return "noll")
shift()
Truth table100%2/2
A
A= shift()
| |||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | 7 | ▶ | return if ($positive < 0); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | 7 | my $out; | |||||||||||||||||||||||||||
| 27 | 7 | my @tokens1 = qw(noll ett två tre fyra fem sex sju åtta nio tio elva | |||||||||||||||||||||||||||
| 28 | tolv tretton fjorton femton sexton sjutton arton nitton); # 0-19 Cardinals | ||||||||||||||||||||||||||||
| 29 | 7 | my @tokens2 = qw(tjugo trettio fyrtio femtio sextio sjutio åttio nittio); # 20-90 Cardinals (end with zero) | |||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | 7 | ▶ | return $tokens1[$positive] if($positive < 20); # interval 0 - 19 | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | 5 | ▶ | if($positive < 100) { # interval 20 - 99 | ||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||
| 34 | 0 | my @num = split '',$positive; | |||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | 0 | $out = $tokens2[$num[0]-2]; | |||||||||||||||||||||||||||
| 37 | 0 | ▶ | $out .= $tokens1[$num[1]] if ($num[1]); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 38 | } elsif($positive < 1000) { # interval 100 - 999 | ||||||||||||||||||||||||||||
| 39 | 3 | my @num = split '',$positive; | |||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | 3 | $out = $tokens1[$num[0]].'hundra'; | |||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | 3 | ▶ | if ((int $num[1].$num[2]) < 20 && (int $num[1].$num[2])>0 ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
int $num[1] . $num[2] < 20 and int $num[1] . $num[2] > 0
MC/DC0%0/2
int $num[1] . $num[2] < 20 and int $num[1] . $num[2] > 0
int $num[1] . $num[2] < 20
int $num[1] . $num[2] > 0
Truth table33%1/3
A and B
A= int $num[1] . $num[2] < 20B= int $num[1] . $num[2] > 0
| |||||||||||||||||||||||||||||
| 44 | 0 | $out .= &num2sv_cardinal(int $num[1].$num[2]); | |||||||||||||||||||||||||||
| 45 | } else { | ||||||||||||||||||||||||||||
| 46 | 3 | ▶ | $out .= $tokens2[$num[1]-2] if($num[1]); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 47 | 3 | ▶ | $out .= $tokens1[$num[2]] if($num[2]); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||
| 49 | } elsif($positive < 1000_000) { # interval 1000 - 999_999 | ||||||||||||||||||||||||||||
| 50 | 2 | my @num = split '',$positive; | |||||||||||||||||||||||||||
| 51 | 2 | my @sub = splice @num,-3; | |||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | 2 | $out = &num2sv_cardinal(int join '',@num); | |||||||||||||||||||||||||||
| 54 | 2 | $out .= 'tusen'; | |||||||||||||||||||||||||||
| 55 | 2 | ▶ | $out .= &num2sv_cardinal(int join '',@sub) if (int(join "",@sub) >0); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 56 | } elsif($positive < 1_000_000_000) { # interval 1_000_000 - 999_999_999 | ||||||||||||||||||||||||||||
| 57 | 0 | my @num = split '',$positive; | |||||||||||||||||||||||||||
| 58 | 0 | my @sub = splice @num,-6; | |||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | 0 | $out = &num2sv_cardinal(int join '',@num); | |||||||||||||||||||||||||||
| 61 | 0 | $out .= ' miljoner '; | |||||||||||||||||||||||||||
| 62 | 0 | ▶ | $out .= &num2sv_cardinal(int join '',@sub) if (int(join "",@sub) >0); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | 5 | return $out; | |||||||||||||||||||||||||||
| 66 | 1 | ▶ | } | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | # }}} | ||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | 1 | 1; | |||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | __END__ | ||||||||||||||||||||||||||||