From f66262694545d4ed8c938dea552dc69ef21f7bfd Mon Sep 17 00:00:00 2001 From: Jan Schneider Date: Tue, 16 Dec 2008 12:10:06 +0100 Subject: [PATCH] Overwrite _replaceBigPrefixes() and add _andition(). Still fails because there is an order of precedence in the and/und combinations, not sure how to handle that. And maybe it's still possible to merge the _replaceBigPrefixes() methods. Back to you, Chuck. ;-) --- .../lib/Horde/Support/Numerizer/Locale/De.php | 30 ++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/framework/Horde_Date_Parser/lib/Horde/Support/Numerizer/Locale/De.php b/framework/Horde_Date_Parser/lib/Horde/Support/Numerizer/Locale/De.php index 26689641b..2e13fae30 100644 --- a/framework/Horde_Date_Parser/lib/Horde/Support/Numerizer/Locale/De.php +++ b/framework/Horde_Date_Parser/lib/Horde/Support/Numerizer/Locale/De.php @@ -5,7 +5,7 @@ class Horde_Support_Numerizer_Locale_De extends Horde_Support_Numerizer_Locale_B 'dreizehn' => 13, 'vierzehn' => 14, 'fünfzehn' => 15, - 'sechszehn' => 16, + 'sechzehn' => 16, 'siebzehn' => 17, 'achtzehn' => 18, 'neunzehn' => 19, @@ -56,10 +56,11 @@ class Horde_Support_Numerizer_Locale_De extends Horde_Support_Numerizer_Locale_B { // preprocess? - $string = $this->_directReplacements($string); $string = $this->_replaceTenPrefixes($string); + $string = $this->_directReplacements($string); $string = $this->_replaceBigPrefixes($string); $string = $this->_fractionalAddition($string); + $string = $this->_andition($string); return $string; } @@ -81,4 +82,29 @@ class Horde_Support_Numerizer_Locale_De extends Horde_Support_Numerizer_Locale_B return $string; } + /** + * hundreds, thousands, millions, etc. + */ + protected function _replaceBigPrefixes($string) + { + foreach ($this->BIG_PREFIXES as $bp => $bp_replacement) { + $string = preg_replace_callback( + '/(\d*) *' . $bp . '/i', + create_function( + '$m', + '$factor = (int)$m[1]; if (!$factor) $factor = 1; return (' . $bp_replacement . ' * $factor) . "und";' + ), + $string); + } + return $string; + } + + protected function _andition($string) + { + while (preg_match('/(\d+)((?:und)+)(\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; + } + } -- 2.11.0