| 1 | # For Emacs: -*- mode:cperl; eval: (folding-mode 1); coding:utf-8 -*- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | package Lingua::CYM::Num2Word; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | # ABSTRACT: Number to word conversion in Welsh (Cymraeg) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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 | # {{{ num2cym_cardinal convert number to text | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | sub num2cym_cardinal :Export { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 23 | ▶ | my $positive = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
num2cym_cardinal: called CC=21 SCAR=31.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 23 | ▶ | croak 'You should specify a number from interval [0, 999_999_999]' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition77%7/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/DC50%2/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 table60%3/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 | # Basic digits 0-10 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 21 | my @ones = qw(dim un dau tri pedwar pump chwech saith wyth naw deg); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | # Tens in the modern decimal system: pum deg, chwe deg, etc. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | # Index 2 => dau ddeg (20), 3 => tri deg (30), ... | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 21 | my @tens = ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | undef, # 0 - unused | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | undef, # 1 - 10 handled separately | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 'dau ddeg', # 20 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 'tri deg', # 30 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 'pedwar deg', # 40 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 'pum deg', # 50 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 'chwe deg', # 60 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 'saith deg', # 70 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 'wyth deg', # 80 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 'naw deg', # 90 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 21 | ▶ | return $ones[$positive] if $positive >= 0 && $positive <= 10; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$positive >= 0 and $positive <= 10
MC/DC50%1/2
$positive >= 0 and $positive <= 10
$positive >= 0
$positive <= 10
Truth table66%2/3
A and B
A= $positive >= 0B= $positive <= 10
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | # 11-19: un deg un, un deg dau, ... | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 15 | ▶ | if ($positive > 10 && $positive < 20) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$positive > 10 and $positive < 20
MC/DC50%1/2
$positive > 10 and $positive < 20
$positive > 10
$positive < 20
Truth table66%2/3
A and B
A= $positive > 10B= $positive < 20
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 2 | my $unit = $ones[$positive - 10]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 2 | return "un deg $unit"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 13 | my $out; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | my $remain; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | # 20-99 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 13 | ▶ | if ($positive >= 20 && $positive < 100) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$positive >= 20 and $positive < 100
MC/DC50%1/2
$positive >= 20 and $positive < 100
$positive >= 20
$positive < 100
Truth table66%2/3
A and B
A= $positive >= 20B= $positive < 100
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 5 | my $ten_idx = int($positive / 10); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 5 | $remain = $positive % 10; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 5 | $out = $tens[$ten_idx]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 5 | ▶ | $out .= ' ' . $ones[$remain] if $remain; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 5 | return $out; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | # 100-999 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 8 | ▶ | if ($positive >= 100 && $positive < 1000) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$positive >= 100 and $positive < 1000
MC/DC50%1/2
$positive >= 100 and $positive < 1000
$positive >= 100
$positive < 1000
Truth table66%2/3
A and B
A= $positive >= 100B= $positive < 1000
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 5 | my $hund_idx = int($positive / 100); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 5 | $remain = $positive % 100; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 5 | $out = _hundreds($hund_idx); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 5 | ▶ | $out .= ' ' . num2cym_cardinal($remain) if $remain; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 5 | return $out; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | # 1000-999_999 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 3 | ▶ | if ($positive >= 1000 && $positive < 1_000_000) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$positive >= 1000 and $positive < 1000000
MC/DC50%1/2
$positive >= 1000 and $positive < 1000000
$positive >= 1000
$positive < 1000000
Truth table66%2/3
A and B
A= $positive >= 1000B= $positive < 1000000
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 2 | my $thou_idx = int($positive / 1000); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 2 | $remain = $positive % 1000; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 2 | $out = _thousands($thou_idx); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 2 | ▶ | $out .= ' ' . num2cym_cardinal($remain) if $remain; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 2 | return $out; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | # 1_000_000-999_999_999 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 1 | ▶ | if ($positive >= 1_000_000 && $positive < 1_000_000_000) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$positive >= 1000000 and $positive < 1000000000
MC/DC0%0/2
$positive >= 1000000 and $positive < 1000000000
$positive >= 1000000
$positive < 1000000000
Truth table33%1/3
A and B
A= $positive >= 1000000B= $positive < 1000000000
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 1 | my $mil_idx = int($positive / 1_000_000); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 1 | $remain = $positive % 1_000_000; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | 1 | $out = num2cym_cardinal($mil_idx) . ' miliwn'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 1 | ▶ | $out .= ' ' . num2cym_cardinal($remain) if $remain; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 1 | return $out; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 1 | ▶ | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | # }}} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | # {{{ _hundreds internal: hundreds word | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | sub _hundreds { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 5 | ▶ | my $n = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_hundreds: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | # Welsh mutations on "cant": | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | # 1 => cant, 2 => dau gant (soft), 3 => tri chant (aspirate), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | # 4 => pedwar cant, 5 => pum cant, 6 => chwe chant (aspirate), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | # 7 => saith cant, 8 => wyth cant, 9 => naw cant | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 5 | my @h = ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | undef, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 'cant', # 1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 'dau gant', # 2 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | 'tri chant', # 3 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | 'pedwar cant', # 4 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 'pum cant', # 5 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | 'chwe chant', # 6 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 'saith cant', # 7 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | 'wyth cant', # 8 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 'naw cant', # 9 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | 5 | return $h[$n]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | # }}} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | # {{{ _thousands internal: thousands word | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | sub _thousands { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | 2 | ▶ | my $n = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_thousands: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | # Simple thousands: mil, dwy fil (2k uses feminine), tri mil, etc. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | # For simplicity using masculine forms and basic citation forms | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | 2 | ▶ | if ($n == 1) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | 1 | return 'mil'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | 1 | return num2cym_cardinal($n) . ' mil'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | # }}} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | # {{{ capabilities declare supported features | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | sub capabilities { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | return { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | 0 | ▶ | cardinal => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
capabilities: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | ordinal => 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | # }}} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | 1 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||