| 1 | package Localizer::BuiltinFunctions; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | 5 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 3 | 5 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 5 | ▶ | use utf8; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | 5 | ▶ | use 5.010_001; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||
| 7 | 1 | ▶ | sub sprintf { sprintf(shift, @_) } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
sprintf: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||
| 9 | # imported by Locale::Maketext | ||||||||||||||||||||||||||||||||||||||||||
| 10 | 6 | ▶ | sub numf { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
numf: called CC=5 SCAR=18.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | 6 | my($num) = @_[0,1]; | |||||||||||||||||||||||||||||||||||||||||
| 12 | 6 | ▶ | if($num < 10_000_000_000 and $num > -10_000_000_000 and $num == int($num)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
$num < '10000000000' and $num > '-10000000000' and $num == int $num
$num < '10000000000' and $num > '-10000000000'
MC/DC0%0/3
$num < '10000000000' and $num > '-10000000000' and $num == int $num
$num < '10000000000'
$num > '-10000000000'
$num == int $num
Truth table25%1/4
A and B and C
A= $num < '10000000000'B= $num > '-10000000000'C= $num == int $num
| |||||||||||||||||||||||||||||||||||||||||||
| 13 | 6 | $num += 0; # Just use normal integer stringification. | |||||||||||||||||||||||||||||||||||||||||
| 14 | # Specifically, don't let %G turn ten million into 1E+007 | ||||||||||||||||||||||||||||||||||||||||||
| 15 | } | ||||||||||||||||||||||||||||||||||||||||||
| 16 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 17 | 0 | $num = CORE::sprintf('%G', $num); | |||||||||||||||||||||||||||||||||||||||||
| 18 | # "CORE::" is there to avoid confusion with the above sub sprintf. | ||||||||||||||||||||||||||||||||||||||||||
| 19 | } | ||||||||||||||||||||||||||||||||||||||||||
| 20 | 6 | ▶ | while( $num =~ s/^([-+]?\d+)(\d{3})/$1,$2/s ) {1} # right from perlfaq5 | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 21 | # The initial \d+ gobbles as many digits as it can, and then we | ||||||||||||||||||||||||||||||||||||||||||
| 22 | # backtrack so it un-eats the rightmost three, and then we | ||||||||||||||||||||||||||||||||||||||||||
| 23 | # insert the comma there. | ||||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||
| 25 | 6 | return $num; | |||||||||||||||||||||||||||||||||||||||||
| 26 | } | ||||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||
| 28 | # imported by Locale::Maketext | ||||||||||||||||||||||||||||||||||||||||||
| 29 | 4 | ▶ | sub numerate { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
numerate: called CC=5 SCAR=18.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 30 | # return this lexical item in a form appropriate to this number | ||||||||||||||||||||||||||||||||||||||||||
| 31 | 4 | my($num, @forms) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 32 | 4 | my $s = ($num == 1); | |||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||
| 34 | 4 | ▶ | return '' unless @forms; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 35 | 4 | ▶ | if(@forms == 1) { # only the headword form specified | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 36 | 0 | ▶ | return $s ? $forms[0] : ($forms[0] . 's'); # very cheap hack. | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||||||||||||||||
| 38 | else { # sing and plural were specified | ||||||||||||||||||||||||||||||||||||||||||
| 39 | 4 | ▶ | return $s ? $forms[0] : $forms[1]; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||||||
| 43 | # imported by Locale::Maketext | ||||||||||||||||||||||||||||||||||||||||||
| 44 | 4 | ▶ | sub quant { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
quant: called CC=4 SCAR=15.6
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 45 | 4 | my($num, @forms) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||
| 47 | 4 | ▶ | return $num if @forms == 0; # what should this mean? | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 48 | 4 | ▶ | return $forms[2] if @forms > 2 and $num == 0; # special zeroth case | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
@forms > 2 and $num == 0
MC/DC0%0/2
@forms > 2 and $num == 0
@forms > 2
$num == 0
Truth table33%1/3
A and B
A= @forms > 2B= $num == 0
| |||||||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||||||
| 50 | # Normal case: | ||||||||||||||||||||||||||||||||||||||||||
| 51 | # Note that the formatting of $num is preserved. | ||||||||||||||||||||||||||||||||||||||||||
| 52 | 4 | return( numf($num) . ' ' . numerate($num, @forms) ); | |||||||||||||||||||||||||||||||||||||||||
| 53 | # Most human languages put the number phrase before the qualified phrase. | ||||||||||||||||||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||||||
| 56 | 5 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||||||||
| 58 | =head1 LICENSE | ||||||||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||||||||
| 60 | Copyright (C) Tokuhiro Matsuno. | ||||||||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||||||
| 62 | This library is free software; you can redistribute it and/or modify | ||||||||||||||||||||||||||||||||||||||||||
| 63 | it under the same terms as Perl itself. | ||||||||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||||||