From 02c8ebd54fb13add186bed33a0f7f99275569687 Mon Sep 17 00:00:00 2001
From: Patrick Barroca <pbarroca@afi-sa.fr>
Date: Thu, 11 Jan 2018 17:56:40 +0100
Subject: [PATCH] hotline #69245 : provide old alphaMaj format

---
 Linse.php                  | 11 +++++++++--
 Linse/Converter.php        | 14 ++++++++------
 Linse/Iso5426Converter.php |  4 ++--
 Linse/Utf8Converter.php    |  4 ++--
 4 files changed, 21 insertions(+), 12 deletions(-)

diff --git a/Linse.php b/Linse.php
index 0d3fc00..6137655 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 26ae5a5..170d531 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 c49e8f6..61336d6 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 2f21cfb..c35be06 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
-- 
GitLab