21 #ifndef otbStringUtils_h
22 #define otbStringUtils_h
30 #if defined(__GNUC__) || defined(__clang__)
31 #pragma GCC diagnostic push
32 #pragma GCC diagnostic ignored "-Wshadow"
33 #pragma GCC diagnostic ignored "-Wunused-parameter"
34 #pragma GCC diagnostic ignored "-Wunused-local-typedefs"
35 #include <boost/lexical_cast.hpp>
36 #include <boost/algorithm/string.hpp>
37 #include <boost/algorithm/string/predicate.hpp>
38 #include <boost/utility/enable_if.hpp>
39 #pragma GCC diagnostic pop
41 #include <boost/lexical_cast.hpp>
42 #include <boost/algorithm/string.hpp>
43 #include <boost/algorithm/string/predicate.hpp>
44 #include <boost/utility/enable_if.hpp>
51 template <
typename Res,
typename In>
56 return boost::lexical_cast<Res>(in);
58 catch (boost::bad_lexical_cast&)
60 std::ostringstream oss;
61 oss <<
"Cannot decode '" << in <<
"' as this is not a valid value for '" << kind <<
"'";
62 throw std::runtime_error(oss.str());
85 typedef std::vector<boost::iterator_range<std::string::const_iterator>> ListType;
89 boost::split(split, str, boost::is_any_of(delims));
91 for (
size_t i = 0; i < split.size(); i++)
93 typename T::value_type value = LexicalCast<typename T::value_type>(split[i], errmsg);
116 template <
typename T>
118 const std::string delims =
"=")
121 typedef boost::iterator_range<std::string::const_iterator> BoostRangeIteratorType;
122 typedef std::list<BoostRangeIteratorType> ListType;
126 boost::split(split, str, boost::is_any_of(delims), boost::token_compress_on);
128 typename ListType::iterator it = split.begin();
129 BoostRangeIteratorType kIt = boost::trim_copy((*it));
130 key.assign(kIt.begin(), kIt.end());
133 if (it != split.end())
135 value = LexicalCast<T>(boost::trim_copy(*it), errmsg);
146 #endif // otbStringUtils_h