diff --git a/Linse.php b/Linse.php index 0d3fc006e9fa80a55e819e3565a3117b48e04195..61376554ede48d01ab902afa64f381660de63ede 100644 --- a/Linse.php +++ b/Linse.php @@ -155,8 +155,15 @@ class Linse { } - public function alphaMaj($chaine) { - return $this->getConverter()->toIndexable($chaine); + /** + * return provided string uppercased and converted to ascii + * + * @param $string string to transform + * @param $compact bool compact whitespaces + * @return string + */ + public function alphaMaj($string, $compact=true) { + return $this->getConverter()->toIndexable($string, $compact); } diff --git a/Linse/Converter.php b/Linse/Converter.php index 26ae5a5a82a8895a7ded2fe95b081eb6ab6128e3..170d531e4328ff3d90497da0f1580ddb1c2429b1 100644 --- a/Linse/Converter.php +++ b/Linse/Converter.php @@ -38,11 +38,13 @@ class Linse_Converter { } - public function toIndexable($data) { - return preg_replace('/\s+/', - ' ', - trim(str_replace($this->_ascii_map, - $this->_ascii_to_uppercase, - $data))); + public function toIndexable($data, $compact=true) { + $ascii = trim(str_replace($this->_ascii_map, + $this->_ascii_to_uppercase, + $data)); + + return $compact + ? preg_replace('/\s+/', ' ', $ascii) + : $ascii; } } \ No newline at end of file diff --git a/Linse/Iso5426Converter.php b/Linse/Iso5426Converter.php index c49e8f6fa649926ab2d1bb54c056a3447235e41b..61336d6594eeaa9b5a08dce60fb84491998db719 100644 --- a/Linse/Iso5426Converter.php +++ b/Linse/Iso5426Converter.php @@ -21,7 +21,7 @@ class Linse_Iso5426Converter extends Linse_Converter { - public function toIndexable($data) { + public function toIndexable($data, $compact=true) { $data = preg_replace('/\210.+\211/', '', $data); // Les delimiteurs d'article bnf NSB NSE $result = ''; @@ -37,7 +37,7 @@ class Linse_Iso5426Converter extends Linse_Converter { } $result = preg_replace('/[' . chr(123) . '-' . chr(255) .']/', '', $result); - return parent::toIndexable($result); + return parent::toIndexable($result, $compact); } diff --git a/Linse/Utf8Converter.php b/Linse/Utf8Converter.php index 2f21cfbd38f65e4b70c88ac3ee7768d8163126f5..c35be06e151372a56d4112ff294c416cc446bbb5 100644 --- a/Linse/Utf8Converter.php +++ b/Linse/Utf8Converter.php @@ -60,13 +60,13 @@ class Linse_Utf8Converter extends Linse_Converter { ]; - public function toIndexable($data) { + public function toIndexable($data, $compact=true) { $data = mb_strtoupper($data); $data = str_replace(array_keys($this->tableMajUtf8), array_values($this->tableMajUtf8), $data); $data = utf8_decode($data); - return parent::toIndexable($data); + return parent::toIndexable($data, $compact); } } \ No newline at end of file