From a6a49e60a078454064c97bbb28775517a3ff6a26 Mon Sep 17 00:00:00 2001
From: Manuel Grizonnet <manuel.grizonnet@orfeo-toolbox.org>
Date: Fri, 2 Mar 2012 19:24:03 +0100
Subject: [PATCH] ENH:avoid to use boost_regex library to trim multiple spaces
 (use std::unique instead)

---
 CMake/ImportBoost.cmake                  |  2 +-
 Code/IO/CMakeLists.txt                   |  2 +-
 Code/IO/otbSpectralSensitivityReader.cxx |  7 ++-----
 Code/IO/otbSpectralSensitivityReader.h   | 12 ++++++++++++
 4 files changed, 16 insertions(+), 7 deletions(-)

diff --git a/CMake/ImportBoost.cmake b/CMake/ImportBoost.cmake
index 045b08b3fa..612f1913a1 100644
--- a/CMake/ImportBoost.cmake
+++ b/CMake/ImportBoost.cmake
@@ -6,7 +6,7 @@ MARK_AS_ADVANCED(OTB_USE_EXTERNAL_BOOST)
 
 IF(OTB_USE_EXTERNAL_BOOST)
   # Import the package
-  FIND_PACKAGE(Boost REQUIRED COMPONENTS regex)
+  FIND_PACKAGE(Boost)
   MARK_AS_ADVANCED(Boost_DIR)
   IF(Boost_FOUND)
     MESSAGE(STATUS "  Found Boost version ${Boost_VERSION}")
diff --git a/Code/IO/CMakeLists.txt b/Code/IO/CMakeLists.txt
index df8803528a..9b5f0f1e6a 100644
--- a/Code/IO/CMakeLists.txt
+++ b/Code/IO/CMakeLists.txt
@@ -38,7 +38,7 @@ ADD_LIBRARY(OTBIO ${OTBIO_SRCS})
 #    PROPERTIES
 #    LINK_INTERFACE_LIBRARIES ""
 #  )
-TARGET_LINK_LIBRARIES (OTBIO  ${TIFF_LIBRARY} ${GEOTIFF_LIBRARY}  ${GDAL_LIBRARY} ${OGR_LIBRARY} ${JPEG_LIBRARY} ${OPENTHREADS_LIBRARY} ${Boost_REGEX_LIBRARY} OTBCommon OTBBasicFilters OTBCurlAdapters)
+TARGET_LINK_LIBRARIES (OTBIO  ${TIFF_LIBRARY} ${GEOTIFF_LIBRARY}  ${GDAL_LIBRARY} ${OGR_LIBRARY} ${JPEG_LIBRARY} ${OPENTHREADS_LIBRARY} OTBCommon OTBBasicFilters OTBCurlAdapters)
 TARGET_LINK_LIBRARIES (OTBIO ITKIO ITKCommon otbkml tinyXML)
 
 IF (OTB_USE_LIBLAS)
diff --git a/Code/IO/otbSpectralSensitivityReader.cxx b/Code/IO/otbSpectralSensitivityReader.cxx
index 81c09d1927..1a90150ce9 100644
--- a/Code/IO/otbSpectralSensitivityReader.cxx
+++ b/Code/IO/otbSpectralSensitivityReader.cxx
@@ -22,7 +22,6 @@
 #include <algorithm>
 #include <cctype>
 #include <boost/algorithm/string.hpp>
-#include <boost/regex.hpp> 
 #include "itksys/SystemTools.hxx"
 
 #include "otbSpotImageMetadataInterface.h"
@@ -138,10 +137,8 @@ SpectralSensitivityReader
   while (std::getline(file, line))
     {
     // Replace multiple spaces by a unique space 
-    boost::regex expr("(\\s)+");
-    std::string fmt(" ");
-    line = boost::regex_replace(line, expr, fmt);
-    
+    std::unique(line.begin(), line.end(), SpectralSensitivityReader::BothAre(' '));
+
     // if the first character is a space, erase it
     boost::trim(line);
     std::vector<std::string> keywordStrings;
diff --git a/Code/IO/otbSpectralSensitivityReader.h b/Code/IO/otbSpectralSensitivityReader.h
index 7d68cbceb4..4be6bf9683 100644
--- a/Code/IO/otbSpectralSensitivityReader.h
+++ b/Code/IO/otbSpectralSensitivityReader.h
@@ -84,6 +84,18 @@ protected:
   /** PrintSelf method */
   void PrintSelf(std::ostream& os, itk::Indent indent) const;
 
+  /** Struct use to remove multiple spaces in file */
+  struct BothAre
+{
+    char c;
+    BothAre(char r) : c(r) {}
+    bool operator()(char l, char r) const
+    {
+            return r == c && l == c;
+    }
+};
+
+
 private:
   SpectralSensitivityReader(const Self &); //purposely not implemented
   void operator =(const Self&); //purposely not implemented
-- 
GitLab