1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10:
11:
12: 13: 14: 15: 16: 17: 18:
19: class Horde_Support_Numerizer_Locale_De extends Horde_Support_Numerizer_Locale_Base
20: {
21: public $DIRECT_NUMS = array(
22: 'dreizehn' => 13,
23: 'vierzehn' => 14,
24: 'fünfzehn' => 15,
25: 'sechzehn' => 16,
26: 'siebzehn' => 17,
27: 'achtzehn' => 18,
28: 'neunzehn' => 19,
29: 'ein[se]?' => 1,
30: 'zwei' => 2,
31: 'zwo' => 2,
32: 'drei' => 3,
33: 'vier' => 4,
34: 'fünf' => 5,
35: 'sechs' => 6,
36: 'sieben' => 7,
37: 'acht' => 8,
38: 'neun' => 9,
39: 'zehn' => 10,
40: 'elf' => 11,
41: 'zwölf' => 12,
42: );
43:
44: public $TEN_PREFIXES = array(
45: 'zwanzig' => 20,
46: 'dreißig' => 30,
47: 'vierzig' => 40,
48: 'fünfzig' => 50,
49: 'sechzig' => 60,
50: 'siebzig' => 70,
51: 'achtzig' => 80,
52: 'neunzig' => 90,
53: );
54:
55: public $BIG_PREFIXES = array(
56: 'hundert' => 100,
57: 'tausend' => 1000,
58: 'million *' => 1000000,
59: 'milliarde *' => 1000000000,
60: 'billion *' => 1000000000000,
61: );
62:
63: 64: 65: 66: 67: 68: 69: 70:
71: public function numerize($string)
72: {
73: $string = $this->_replaceTenPrefixes($string);
74: $string = $this->_directReplacements($string);
75: $string = $this->_replaceBigPrefixes($string);
76: $string = $this->_fractionalAddition($string);
77:
78: return $string;
79: }
80:
81: 82: 83:
84: protected function _replaceTenPrefixes($string)
85: {
86: foreach ($this->TEN_PREFIXES as $tp => $tp_replacement) {
87: $string = preg_replace_callback(
88: "/(?:$tp)( *\d(?=[^\d]|\$))*/i",
89: create_function(
90: '$m',
91: 'return ' . $tp_replacement . ' + (isset($m[1]) ? (int)$m[1] : 0);'
92: ),
93: $string);
94: }
95: return $string;
96: }
97:
98: 99: 100:
101: protected function _replaceBigPrefixes($string)
102: {
103: foreach ($this->BIG_PREFIXES as $bp => $bp_replacement) {
104: $string = preg_replace_callback(
105: '/(\d*) *' . $bp . '(\d?)/i',
106: create_function(
107: '$m',
108: '$factor = (int)$m[1]; if (!$factor) $factor = 1; return (' . $bp_replacement . ' * $factor)' . ($bp_replacement == 100 ? ' . ($m[2] ? "und" : "")' : ' . "und"') . ' . $m[2];'
109: ),
110: $string);
111: $string = $this->_andition($string);
112: }
113: return $string;
114: }
115:
116: protected function _andition($string)
117: {
118: while (preg_match('/(\d+)((?: *und *)+)(\d*)(?=\w|$)/i', $string, $sc, PREG_OFFSET_CAPTURE)) {
119: $string = substr($string, 0, $sc[1][1]) . ((int)$sc[1][0] + (int)$sc[3][0]) . substr($string, $sc[3][1] + strlen($sc[3][0]));
120: }
121: return $string;
122: }
123:
124: }
125: