| 1 | # For Emacs: -*- mode:cperl; eval: (folding-mode 1); coding:utf-8 -*- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | package Lingua::RON::Num2Word; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | # ABSTRACT: Number to word conversion in Romanian | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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 Carp; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | 1 | ▶ | use Export::Attrs; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 1 | ▶ | use Readonly; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | # }}} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | # {{{ variable declarations | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 1 | my Readonly::Scalar $COPY = 'Copyright (c) PetaMem, s.r.o. 2002-present'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 1 | our $VERSION = '0.2603270'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | # }}} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | # {{{ num2ron_cardinal convert number to text | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | sub num2ron_cardinal :Export { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 2 | ▶ | my $positive = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
num2ron_cardinal: called CC=33 SCAR=66.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 2 | ▶ | croak 'You should specify a number from interval [0, 999_999_999]' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%3/9
not defined $positive && $positive =~ /\A\d+\z/msux or $positive < 0 or $positive > 999999999
not defined $positive && $positive =~ /\A\d+\z/msux or $positive < 0
defined $positive && $positive =~ /\A\d+\z/msux
MC/DC0%0/4
not defined $positive && $positive =~ /\A\d+\z/msux or $positive < 0 or $positive > 999999999
defined $positive
$positive =~ /\A\d+\z/msux
$positive < 0
$positive > 999999999
Truth table20%1/5
not(A && B) or C or D
A= defined $positiveB= $positive =~ /\A\d+\z/msuxC= $positive < 0D= $positive > 999999999
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | if !defined $positive | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | || $positive !~ m{\A\d+\z}xms | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | || $positive < 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | || $positive > 999_999_999; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 2 | my @units = ('zero', 'unu', 'doi', 'trei', 'patru', 'cinci', | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 'șase', 'șapte', 'opt', 'nouă'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 2 | my @teens = ('zece', 'unsprezece', 'doisprezece', 'treisprezece', | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 'paisprezece', 'cincisprezece', 'șaisprezece', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 'șaptesprezece', 'optsprezece', 'nouăsprezece'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 2 | my @tens = ('', '', 'douăzeci', 'treizeci', 'patruzeci', 'cincizeci', | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 'șaizeci', 'șaptezeci', 'optzeci', 'nouăzeci'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 2 | ▶ | return $units[$positive] if ($positive >= 0 && $positive < 10); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$positive >= 0 and $positive < 10
MC/DC0%0/2
$positive >= 0 and $positive < 10
$positive >= 0
$positive < 10
Truth table33%1/3
A and B
A= $positive >= 0B= $positive < 10
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 0 | ▶ | return $teens[$positive - 10] if ($positive >= 10 && $positive < 20); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$positive >= 10 and $positive < 20
MC/DC0%0/2
$positive >= 10 and $positive < 20
$positive >= 10
$positive < 20
Truth table0%0/3
A and B
A= $positive >= 10B= $positive < 20
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 0 | my $out; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | my $remain; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 0 | ▶ | if ($positive > 19 && $positive < 100) { # 20 .. 99 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 8 branches
Condition0%0/3
$positive > 19 and $positive < 100
MC/DC0%0/2
$positive > 19 and $positive < 100
$positive > 19
$positive < 100
Truth table0%0/3
A and B
A= $positive > 19B= $positive < 100
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 0 | my $ten_idx = int($positive / 10); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 0 | $remain = $positive % 10; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 0 | $out = $tens[$ten_idx]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 0 | ▶ | $out .= ' și ' . $units[$remain] if ($remain); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | elsif ($positive == 100) { # 100 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 0 | $out = 'o sută'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | ▶ | elsif ($positive > 100 && $positive < 200) { # 101 .. 199 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$positive > 100 and $positive < 200
MC/DC0%0/2
$positive > 100 and $positive < 200
$positive > 100
$positive < 200
Truth table0%0/3
A and B
A= $positive > 100B= $positive < 200
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 0 | $remain = $positive % 100; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 0 | $out = 'o sută ' . num2ron_cardinal($remain); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | ▶ | elsif ($positive >= 200 && $positive < 1000) { # 200 .. 999 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$positive >= 200 and $positive < 1000
MC/DC0%0/2
$positive >= 200 and $positive < 1000
$positive >= 200
$positive < 1000
Truth table0%0/3
A and B
A= $positive >= 200B= $positive < 1000
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 0 | my $hun_idx = int($positive / 100); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 0 | $remain = $positive % 100; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 0 | ▶ | $out = $hun_idx == 2 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | ? 'două sute' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | : num2ron_cardinal($hun_idx) . ' sute'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 0 | ▶ | $out .= ' ' . num2ron_cardinal($remain) if ($remain); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | ▶ | elsif ($positive >= 1000 && $positive < 2000) { # 1000 .. 1999 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$positive >= 1000 and $positive < 2000
MC/DC0%0/2
$positive >= 1000 and $positive < 2000
$positive >= 1000
$positive < 2000
Truth table0%0/3
A and B
A= $positive >= 1000B= $positive < 2000
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 0 | $remain = $positive % 1000; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 0 | $out = 'o mie'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 0 | ▶ | $out .= ' ' . num2ron_cardinal($remain) if ($remain); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | ▶ | elsif ($positive >= 2000 && $positive < 1_000_000) { # 2000 .. 999_999 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$positive >= 2000 and $positive < 1000000
MC/DC0%0/2
$positive >= 2000 and $positive < 1000000
$positive >= 2000
$positive < 1000000
Truth table0%0/3
A and B
A= $positive >= 2000B= $positive < 1000000
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 0 | my $tho_idx = int($positive / 1000); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 0 | $remain = $positive % 1000; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 0 | ▶ | $out = $tho_idx == 2 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | ? 'două mii' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | : num2ron_cardinal($tho_idx) . ' mii'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 0 | ▶ | $out .= ' ' . num2ron_cardinal($remain) if ($remain); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | ▶ | elsif ($positive >= 1_000_000 && $positive < 2_000_000) { # 1_000_000 .. 1_999_999 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$positive >= 1000000 and $positive < 2000000
MC/DC0%0/2
$positive >= 1000000 and $positive < 2000000
$positive >= 1000000
$positive < 2000000
Truth table0%0/3
A and B
A= $positive >= 1000000B= $positive < 2000000
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 0 | $remain = $positive % 1_000_000; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 0 | $out = 'un milion'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 0 | ▶ | $out .= ' ' . num2ron_cardinal($remain) if ($remain); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | ▶ | elsif ($positive >= 2_000_000 && $positive < 1_000_000_000) { # 2_000_000 .. 999_999_999 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$positive >= 2000000 and $positive < 1000000000
MC/DC0%0/2
$positive >= 2000000 and $positive < 1000000000
$positive >= 2000000
$positive < 1000000000
Truth table0%0/3
A and B
A= $positive >= 2000000B= $positive < 1000000000
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 0 | my $mil_idx = int($positive / 1_000_000); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 0 | $remain = $positive % 1_000_000; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | 0 | ▶ | $out = $mil_idx == 2 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | ? 'două milioane' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | : num2ron_cardinal($mil_idx) . ' milioane'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 0 | ▶ | $out .= ' ' . num2ron_cardinal($remain) if ($remain); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 0 | return $out; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 1 | ▶ | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | # }}} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | # {{{ capabilities declare supported features | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | sub capabilities { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | return { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | 0 | ▶ | cardinal => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
capabilities: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | ordinal => 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | # }}} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | 1 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||