Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:50:17

0001 // ----------------------------------------------------------------------------
0002 // Copyright (C) 2002-2006 Marcin Kalicinski
0003 //
0004 // Distributed under the Boost Software License, Version 1.0. 
0005 // (See accompanying file LICENSE_1_0.txt or copy at 
0006 // http://www.boost.org/LICENSE_1_0.txt)
0007 //
0008 // For more information, see www.boost.org
0009 // ----------------------------------------------------------------------------
0010 #ifndef BOOST_PROPERTY_TREE_DETAIL_PTREE_UTILS_HPP_INCLUDED
0011 #define BOOST_PROPERTY_TREE_DETAIL_PTREE_UTILS_HPP_INCLUDED
0012 
0013 #include <boost/limits.hpp>
0014 #include <boost/type_traits/integral_constant.hpp>
0015 #include <boost/mpl/has_xxx.hpp>
0016 #include <boost/mpl/and.hpp>
0017 #include <string>
0018 #include <algorithm>
0019 #include <locale>
0020 
0021 namespace boost { namespace property_tree { namespace detail
0022 {
0023 
0024     template<class T>
0025     struct less_nocase
0026     {
0027         typedef typename T::value_type Ch;
0028         std::locale m_locale;
0029         inline bool operator()(Ch c1, Ch c2) const
0030         {
0031             return std::toupper(c1, m_locale) < std::toupper(c2, m_locale);
0032         }
0033         inline bool operator()(const T &t1, const T &t2) const
0034         {
0035             return std::lexicographical_compare(t1.begin(), t1.end(),
0036                                                 t2.begin(), t2.end(), *this);
0037         }
0038     };
0039 
0040     template <typename Ch>
0041     struct is_character : public boost::false_type {};
0042     template <>
0043     struct is_character<char> : public boost::true_type {};
0044     template <>
0045     struct is_character<wchar_t> : public boost::true_type {};
0046 
0047 
0048     BOOST_MPL_HAS_XXX_TRAIT_DEF(internal_type)
0049     BOOST_MPL_HAS_XXX_TRAIT_DEF(external_type)
0050     template <typename T>
0051     struct is_translator : public boost::mpl::and_<
0052         has_internal_type<T>, has_external_type<T> > {};
0053 
0054 
0055 
0056     // Naively convert narrow string to another character type
0057     template<typename Str>
0058     Str widen(const char *text)
0059     {
0060         Str result;
0061         while (*text)
0062         {
0063             result += typename Str::value_type(*text);
0064             ++text;
0065         }
0066         return result;
0067     }
0068 
0069     // Naively convert string to narrow character type
0070     template<typename Str, typename char_type>
0071     Str narrow(const char_type *text)
0072     {
0073         Str result;
0074         while (*text)
0075         {
0076             if (*text < 0 || *text > static_cast<char_type>((std::numeric_limits<char>::max)()))
0077                 result += '*';
0078             else
0079                 result += typename Str::value_type(*text);
0080             ++text;
0081         }
0082         return result;
0083     }
0084 
0085     // Remove trailing and leading spaces
0086     template<class Str>
0087     Str trim(const Str &s, const std::locale &loc = std::locale())
0088     {
0089         typename Str::const_iterator first = s.begin();
0090         typename Str::const_iterator end = s.end();
0091         while (first != end && std::isspace(*first, loc))
0092             ++first;
0093         if (first == end)
0094             return Str();
0095         typename Str::const_iterator last = end;
0096         do --last; while (std::isspace(*last, loc));
0097         if (first != s.begin() || last + 1 != end)
0098             return Str(first, last + 1);
0099         else
0100             return s;
0101     }
0102 
0103 } } }
0104 
0105 #endif