Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:52:41

0001 //  (C) Copyright Gennadiy Rozental 2001.
0002 //  Distributed under the Boost Software License, Version 1.0.
0003 //  (See accompanying file LICENSE_1_0.txt or copy at
0004 //  http://www.boost.org/LICENSE_1_0.txt)
0005 
0006 //  See http://www.boost.org/libs/test for the library home page.
0007 //
0008 //  File        : $RCSfile$
0009 //
0010 //  Version     : $Revision$
0011 //
0012 //  Description : generic char traits class; wraps std::char_traits
0013 // ***************************************************************************
0014 
0015 #ifndef BOOST_TEST_UTILS_BCS_CHAR_TRAITS_HPP
0016 #define BOOST_TEST_UTILS_BCS_CHAR_TRAITS_HPP
0017 
0018 // Boost
0019 #include <boost/config.hpp>
0020 #include <boost/detail/workaround.hpp>
0021 #include <boost/test/detail/config.hpp>
0022 #include <boost/type_traits/add_const.hpp>
0023 
0024 // STL
0025 #include <string>                       // std::char_traits
0026 #include <cstddef>                      // std::size_t
0027 
0028 #include <boost/test/detail/suppress_warnings.hpp>
0029 
0030 //____________________________________________________________________________//
0031 
0032 namespace boost {
0033 
0034 namespace unit_test {
0035 
0036 namespace ut_detail {
0037 
0038 template<typename CharT> struct bcs_base_char           { typedef CharT type; };
0039 
0040 template<> struct bcs_base_char<char const>             { typedef char type; };
0041 template<> struct bcs_base_char<unsigned char>          { typedef char type; };
0042 #if !BOOST_WORKAROUND(BOOST_BORLANDC, BOOST_TESTED_AT(0x551))
0043 template<> struct bcs_base_char<unsigned char const>    { typedef char type; };
0044 #endif
0045 
0046 template<> struct bcs_base_char<wchar_t const>          { typedef wchar_t type; };
0047 
0048 // ************************************************************************** //
0049 // **************               bcs_char_traits                ************** //
0050 // ************************************************************************** //
0051 
0052 template<typename CharT>
0053 struct bcs_char_traits_impl
0054 {
0055 #if BOOST_WORKAROUND(BOOST_BORLANDC, BOOST_TESTED_AT(0x564))
0056     typedef CharT const const_char;
0057 #else
0058     typedef typename boost::add_const<CharT>::type const_char;
0059 #endif
0060     static bool eq( CharT c1, CharT c2 )
0061     {
0062         return c1 == c2;
0063     }
0064     static bool lt( CharT c1, CharT c2 )
0065     {
0066         return c1 < c2;
0067     }
0068 
0069     static int compare( const_char* cstr1, const_char* cstr2, std::size_t n )
0070     {
0071         while( n > 0 ) {
0072             if( !eq( *cstr1, *cstr2 ) )
0073                 return lt( *cstr1, *cstr2 ) ? -1 : 1;
0074             ++cstr1;
0075             ++cstr2;
0076             --n;
0077         }
0078 
0079         return 0;
0080     }
0081 
0082     static std::size_t length( const_char* cstr )
0083     {
0084         const_char null_char = CharT();
0085 
0086         const_char* ptr = cstr;
0087         while( !eq( *ptr, null_char ) )
0088             ++ptr;
0089 
0090         return ptr - cstr;
0091     }
0092 
0093     static const_char* find( const_char* s, std::size_t n, CharT c )
0094     {
0095         while( n > 0 ) {
0096             if( eq( *s, c ) )
0097                 return s;
0098 
0099             ++s;
0100             --n;
0101         }
0102         return 0;
0103     }
0104 };
0105 
0106 #ifdef BOOST_CLASSIC_IOSTREAMS
0107 template<typename CharT>
0108 struct char_traits_with_find : std::string_char_traits<CharT> {
0109     static CharT const* find( CharT const* s, std::size_t n, CharT c )
0110     {
0111         while( n > 0 ) {
0112             if( eq( *s, c ) )
0113                 return s;
0114 
0115             ++s;
0116             --n;
0117         }
0118         return 0;
0119     }
0120 };
0121 
0122 template<> struct bcs_char_traits_impl<char> : public char_traits_with_find<char> {};
0123 template<> struct bcs_char_traits_impl<wchar_t> : public char_traits_with_find<wchar_t> {};
0124 #else
0125 template<> struct bcs_char_traits_impl<char> : public std::char_traits<char> {};
0126 template<> struct bcs_char_traits_impl<wchar_t> : public std::char_traits<wchar_t> {};
0127 #endif
0128 
0129 template<typename CharT>
0130 class bcs_char_traits : public bcs_char_traits_impl<CharT> {
0131     typedef typename ut_detail::bcs_base_char<CharT>::type                              the_base_char;
0132 public:
0133 #ifdef BOOST_CLASSIC_IOSTREAMS
0134     typedef std::basic_string<the_base_char, std::string_char_traits<the_base_char> >   std_string;
0135 #else
0136     typedef std::basic_string<the_base_char, std::char_traits<the_base_char> >          std_string;
0137 #endif
0138 };
0139 
0140 } // namespace ut_detail
0141 
0142 } // namespace unit_test
0143 
0144 } // namespace boost
0145 
0146 //____________________________________________________________________________//
0147 
0148 #include <boost/test/detail/enable_warnings.hpp>
0149 
0150 #endif // BOOST_TEST_UTILS_BCS_CHAR_TRAITS_HPP