/usr/share/php/Horde/Support/Numerizer/Locale/Pt.php is in php-horde-support 2.2.0-1ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 | <?php
/**
* Copyright 2010-2017 Horde LLC (http://www.horde.org/)
*
* @license http://www.horde.org/licenses/bsd BSD
* @category Horde
* @package Support
*/
/**
* @license http://www.horde.org/licenses/bsd BSD
* @category Horde
* @package Support
*/
class Horde_Support_Numerizer_Locale_Pt extends Horde_Support_Numerizer_Locale_Base
{
public $DIRECT_NUMS = array(
'treze' => '13',
'catorze' => '14',
'quatorze' => '14',
'quinze' => '15',
'dezasseis' => '16',
'dezassete' => '17',
'dezoito' => '18',
'dezanove' => '19',
'um(\W|$)' => '1$1',
'uma(\W|$)' => '1$1',
'dois' => '2',
'duas' => '2',
'tres' => '3',
'quatro' => '4',
'cinco' => '5',
'seis' => '6',
'sete' => '7',
'oito' => '8',
'nove' => '9',
'dez' => '10',
'onze' => '11',
'doze' => '12',
);
public $TEN_PREFIXES = array(
'vinte' => '20',
'trinta' => '30',
'quarenta' => '40',
'cinquenta' => '50',
'sessenta' => '60',
'setenta' => '70',
'oitenta' => '80',
'noventa' => '90',
);
public $BIG_PREFIXES = array(
'cem' => '100',
'mil' => '1000',
'milhao *' => '1000000',
'milhar de *' => '1000000000',
'biliao *' => '1000000000000',
);
public function numerize($string)
{
// preprocess
$string = $this->_splitHyphenateWords($string);
$string = $this->_replaceTenPrefixes($string);
$string = $this->_directReplacements($string);
$string = $this->_replaceBigPrefixes($string);
// $string = $this->_fractionalAddition($string);
return $string;
}
/**
* will mutilate hyphenated-words but shouldn't matter for date extraction
*/
protected function _splitHyphenateWords($string)
{
return preg_replace('/ +|([^\d]) e? ([^d])/', '$1 $2', $string);
}
/**
* easy/direct replacements
*/
protected function _directReplacements($string)
{
foreach ($this->DIRECT_NUMS as $dn => $dn_replacement) {
$string = preg_replace("/$dn/i", $dn_replacement, $string);
}
return $string;
}
/**
* ten, twenty, etc.
*/
protected function _replaceTenPrefixes($string)
{
foreach ($this->TEN_PREFIXES as $tp => $tp_replacement) {
$string = preg_replace_callback(
"/(?:$tp)( *\d(?=[^\d]|\$))*/i",
function ($m) use ($tp_replacement) {
return $tp_replacement + (isset($m[1]) ? (int)$m[1] : 0);
},
$string
);
}
return $string;
}
/**
* hundreds, thousands, millions, etc.
*/
protected function _replaceBigPrefixes($string)
{
foreach ($this->BIG_PREFIXES as $bp => $bp_replacement) {
$string = preg_replace_callback(
'/(\d*) *' . $bp . '(\d?)/i',
function ($m) use ($bp_replacement) {
$factor = (int)$m[1];
if (!$factor) {
$factor = 1;
}
return ($bp_replacement * $factor)
. ($bp_replacement == 100 ? ($m[2] ? 'e' : '') : 'e')
. $m[2];
},
$string);
$string = $this->_andition($string);
}
return $string;
}
protected function _andition($string)
{
while (preg_match('/(\d+)((?: *e *)+)(\d*)(?=\w|$)/i', $string, $sc, PREG_OFFSET_CAPTURE)) {
$string = substr($string, 0, $sc[1][1]) . ((int)$sc[1][0] + (int)$sc[3][0]) . substr($string, $sc[3][1] + strlen($sc[3][0]));
}
return $string;
}
protected function _fractionalAddition($string)
{
return preg_replace_callback(
'/(\d+)(?: | e |-)*/i',
function ($m) {
return (string)((float)$m[1] + 0.5);
},
$string
);
}
}
|