From 9070ff055aa8337e75ca05a909bcfaf17b666d09 Mon Sep 17 00:00:00 2001 From: =?utf8?q?St=C3=A9phane=20Jacob?= Date: Sun, 12 Dec 2010 15:44:49 +0100 Subject: [PATCH] The first word of the street line should be truncated to 4 letters. MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Stéphane Jacob --- classes/address.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/classes/address.php b/classes/address.php index 067a505..a17c370 100644 --- a/classes/address.php +++ b/classes/address.php @@ -378,12 +378,18 @@ class Address * success, modifies the length accordingly and returns either the matching * substitution or the needle. */ - private function substitute($needle, $haystack, &$length, &$success) + private function substitute($needle, $haystack, &$length, &$success, $trim = false) { if (array_key_exists($needle, $haystack)) { $success = true; $length -= (strlen($needle) - strlen($haystack[$needle])); return $haystack[$needle]; + } elseif ($trim) { + $success = true; + if (strlen($needle) > 4) { + $length -= (strlen($needle) - 4); + $needle = $needle{4}; + } } return $needle; } @@ -500,7 +506,7 @@ class Address for ($i = 0; $i < $count && $length > $limit; ++$i) { $success = false; if ($isStreetLine) { - $sub = $this->substitute($words[$i], Address::$streetAbbreviations, $length, $success); + $sub = $this->substitute($words[$i], Address::$streetAbbreviations, $length, $success, ($i == 0)); } // Entreprises' substitution are only suitable for the first two lines. if ($lineNumber <= 2 && !$success) { -- 2.1.4