| 1 | # For Emacs: -*- mode:cperl; mode:folding; coding:utf-8; -*- | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | package Lingua::MKD::Num2Word; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | # ABSTRACT: Number to word conversion in Macedonian | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 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 | # {{{ var block | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 1 | our $VERSION = '0.2603270'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 1 | my %token1 = qw( 0 нула 1 еден 2 два | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 3 три 4 четири 5 пет | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 6 шест 7 седум 8 осум | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 9 девет 10 десет 11 единаесет | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 12 дванаесет 13 тринаесет 14 четиринаесет | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 15 петнаесет 16 шестнаесет 17 седумнаесет | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 18 осумнаесет 19 деветнаесет | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 1 | my %token2 = qw( 20 дваесет 30 триесет 40 четириесет | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 50 педесет 60 шеесет 70 седумдесет | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 80 осумдесет 90 деведесет | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 1 | my %token3 = ( 100, 'сто', 200, 'двесте', 300, 'триста', | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 400, 'четиристотини', 500, 'петстотини', 600, 'шестстотини', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 700, 'седумстотини', 800, 'осумстотини', 900, 'деветстотини' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | # }}} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | # {{{ _num_to_words internal: convert 1-999 to words | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | sub _num_to_words { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 34 | ▶ | my ($number) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_num_to_words: called CC=7 SCAR=19.5
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 34 | ▶ | return $token1{$number} if exists $token1{$number}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 21 | ▶ | if ($number < 100) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 6 | my $rem = $number % 10; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 6 | ▶ | if ($rem == 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 4 | return $token2{$number}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 2 | return $token2{$number - $rem} . ' и ' . $token1{$rem}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 15 | my $hund_rem = $number % 100; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 15 | my $hund_val = $number - $hund_rem; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 15 | ▶ | if ($hund_rem == 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 6 | return $token3{$hund_val}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | # hundreds + remainder: "и" goes before the last component | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | # 101 = сто и еден, 120 = сто и дваесет, 123 = сто дваесет и три | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 9 | my $tens_rem = $hund_rem % 10; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 9 | ▶ | if ($hund_rem < 20 || $tens_rem == 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$hund_rem < 20 or $tens_rem == 0
MC/DC100%2/2
$hund_rem < 20 or $tens_rem == 0
$hund_rem < 20
$tens_rem == 0
Truth table100%3/3
A or B
A= $hund_rem < 20B= $tens_rem == 0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | # single component remainder: hundred "и" remainder | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 2 | return $token3{$hund_val} . ' и ' . _num_to_words($hund_rem); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | # two-component remainder (e.g. 23): hundred tens "и" unit | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 7 | return $token3{$hund_val} . ' ' . $token2{$hund_rem - $tens_rem} . ' и ' . $token1{$tens_rem}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | # }}} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | # {{{ num2mkd_cardinal number to string conversion | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | sub num2mkd_cardinal :Export { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 36 | ▶ | my $number = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
num2mkd_cardinal: called CC=16 SCAR=27.7
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 36 | ▶ | croak 'You should specify a number from interval [0, 999_999_999]' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition88%8/9
not defined $number && $number =~ /\A\d+\z/msux or $number < 0 or $number > 999999999
not defined $number && $number =~ /\A\d+\z/msux or $number < 0
defined $number && $number =~ /\A\d+\z/msux
MC/DC75%3/4
not defined $number && $number =~ /\A\d+\z/msux or $number < 0 or $number > 999999999
defined $number
$number =~ /\A\d+\z/msux
$number < 0
$number > 999999999
Truth table80%4/5
not(A && B) or C or D
A= defined $numberB= $number =~ /\A\d+\z/msuxC= $number < 0D= $number > 999999999
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | if !defined $number | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | || $number !~ m{\A\d+\z}xms | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | || $number < 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | || $number > 999_999_999; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 33 | ▶ | return $token1{0} if $number == 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 32 | my $result = ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | # {{{ millions | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 32 | ▶ | if ($number >= 1_000_000) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 5 | my $millions = int($number / 1_000_000); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 5 | $number %= 1_000_000; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 5 | ▶ | if ($millions == 1) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 2 | $result = 'еден милион'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 3 | $result = _num_to_words($millions) . ' милиони'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | # }}} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | # {{{ thousands | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 32 | ▶ | if ($number >= 1_000) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 10 | my $thousands = int($number / 1_000); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 10 | $number %= 1_000; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | 10 | ▶ | $result .= ' ' if $result ne ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 10 | ▶ | if ($thousands == 1) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 6 | $result .= 'илјада'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | elsif ($thousands == 2) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 1 | $result .= 'две илјади'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 3 | $result .= _num_to_words($thousands) . ' илјади'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | # }}} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | # {{{ remainder (0-999) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 32 | ▶ | if ($number > 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | 26 | ▶ | if ($result ne '') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | # "и" before remainder when there is no compound hundreds group: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | # i.e. remainder < 100 (no hundreds at all) or round hundreds (100,200,...,900) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 7 | ▶ | if ($number < 100 || $number % 100 == 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$number < 100 or $number % 100 == 0
MC/DC100%2/2
$number < 100 or $number % 100 == 0
$number < 100
$number % 100 == 0
Truth table100%3/3
A or B
A= $number < 100B= $number % 100 == 0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | 4 | $result .= ' и ' . _num_to_words($number); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | 3 | $result .= ' ' . _num_to_words($number); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | 19 | $result = _num_to_words($number); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | # }}} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | 32 | return $result; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | 1 | ▶ | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | # }}} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | # {{{ capabilities declare supported features | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | sub capabilities { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | return { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | 0 | ▶ | cardinal => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
capabilities: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | ordinal => 0, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | # }}} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | 1 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||