| 1 | # For Emacs: -*- mode:cperl; eval: (folding-mode 1); coding:utf-8 -*- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | package Lingua::SRD::Num2Word; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | # ABSTRACT: Number to word conversion in Sardinian (Logudorese) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | # }}} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | # {{{ variable declarations | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 1 | our $VERSION = '0.2603270'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 1 | my @ONES = qw(zeru unu duos tres bàtoro chimbe ses sete oto noe); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 1 | my @TEENS = qw(deghe undighi doighi treighi batordighi bindighi seighi | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | deghesete degheoto deghenoe); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 1 | my @TENS = qw(_ _ binti trinta baranta chinbanta sessanta setanta otanta nonanta); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | # Hundreds multiplier prefixes: 2-9 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 1 | my @HUN_PREFIX = qw(_ _ du tre bator chinbi ses sete oto nobi); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | # }}} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | # {{{ num2srd_cardinal convert number to text | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | sub num2srd_cardinal :Export { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 66 | ▶ | my $positive = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
num2srd_cardinal: called CC=25 SCAR=38.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 66 | ▶ | 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
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | if !defined $positive | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | || $positive !~ m{\A\d+\z}xms | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | || $positive < 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | || $positive > 999_999_999; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | # 0–9 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 66 | ▶ | return $ONES[$positive] if $positive <= 9; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | # 10–19 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 53 | ▶ | return $TEENS[$positive - 10] if $positive >= 10 && $positive <= 19; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$positive >= 10 and $positive <= 19
MC/DC50%1/2
$positive >= 10 and $positive <= 19
$positive >= 10
$positive <= 19
Truth table66%2/3
A and B
A= $positive >= 10B= $positive <= 19
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | # 20–99 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 42 | ▶ | if ($positive >= 20 && $positive <= 99) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$positive >= 20 and $positive <= 99
MC/DC50%1/2
$positive >= 20 and $positive <= 99
$positive >= 20
$positive <= 99
Truth table66%2/3
A and B
A= $positive >= 20B= $positive <= 99
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 25 | my $ten_idx = int($positive / 10); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 25 | my $unit = $positive % 10; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 25 | ▶ | return $TENS[$ten_idx] if $unit == 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 17 | my $ten_word = $TENS[$ten_idx]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | # Apocope: tens drop final vowel before "unu" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 17 | ▶ | if ($unit == 1) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 8 | $ten_word =~ s/[aeiou]$//; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 8 | return $ten_word . $ONES[$unit]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 9 | return $ten_word . $ONES[$unit]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | # 100–999 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 17 | ▶ | if ($positive >= 100 && $positive <= 999) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$positive >= 100 and $positive <= 999
MC/DC50%1/2
$positive >= 100 and $positive <= 999
$positive >= 100
$positive <= 999
Truth table66%2/3
A and B
A= $positive >= 100B= $positive <= 999
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 13 | my $hun_idx = int($positive / 100); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 13 | my $remain = $positive % 100; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 13 | my $out; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 13 | ▶ | if ($hun_idx == 1) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 3 | $out = 'chentu'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 10 | $out = $HUN_PREFIX[$hun_idx] . 'chentos'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 13 | ▶ | $out .= num2srd_cardinal($remain) if $remain; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 13 | return $out; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | # 1_000–999_999 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 4 | ▶ | if ($positive >= 1_000 && $positive <= 999_999) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$positive >= 1000 and $positive <= 999999
MC/DC0%0/2
$positive >= 1000 and $positive <= 999999
$positive >= 1000
$positive <= 999999
Truth table33%1/3
A and B
A= $positive >= 1000B= $positive <= 999999
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 4 | my $tho_idx = int($positive / 1000); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 4 | my $remain = $positive % 1000; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 4 | my $out; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 4 | ▶ | if ($tho_idx == 1) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 2 | $out = 'milli'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | elsif ($tho_idx == 2) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 1 | $out = 'duamiza'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 1 | $out = num2srd_cardinal($tho_idx) . 'miza'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 4 | ▶ | $out .= num2srd_cardinal($remain) if $remain; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | 4 | return $out; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | # 1_000_000–999_999_999 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | 0 | ▶ | if ($positive >= 1_000_000 && $positive <= 999_999_999) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$positive >= 1000000 and $positive <= 999999999
MC/DC0%0/2
$positive >= 1000000 and $positive <= 999999999
$positive >= 1000000
$positive <= 999999999
Truth table0%0/3
A and B
A= $positive >= 1000000B= $positive <= 999999999
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 0 | my $mil_idx = int($positive / 1_000_000); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 0 | my $remain = $positive % 1_000_000; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 0 | my $out; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | 0 | ▶ | if ($mil_idx == 1) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 0 | $out = 'unu milione'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 0 | $out = num2srd_cardinal($mil_idx) . ' miliones'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | 0 | ▶ | $out .= ' ' . num2srd_cardinal($remain) if $remain; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 0 | return $out; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 1 | ▶ | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | # }}} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | # {{{ capabilities declare supported features | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | sub capabilities { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | return { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | 1 | ▶ | cardinal => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
capabilities: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | ordinal => 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | # }}} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | 1 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||