File indexing completed on 2025-01-18 09:28:29
0001 #ifndef BOOST_ARCHIVE_ITERATORS_REMOVE_WHITESPACE_HPP
0002 #define BOOST_ARCHIVE_ITERATORS_REMOVE_WHITESPACE_HPP
0003
0004
0005 #if defined(_MSC_VER)
0006 # pragma once
0007 #endif
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019 #include <boost/assert.hpp>
0020
0021 #include <boost/iterator/iterator_adaptor.hpp>
0022 #include <boost/iterator/filter_iterator.hpp>
0023 #include <boost/iterator/iterator_traits.hpp>
0024
0025
0026
0027
0028
0029
0030
0031 #ifndef BOOST_NO_CWCTYPE
0032 #include <cwctype> // iswspace
0033 #if defined(BOOST_NO_STDC_NAMESPACE)
0034 namespace std{ using ::iswspace; }
0035 #endif
0036 #endif
0037
0038 #include <cctype> // isspace
0039 #if defined(BOOST_NO_STDC_NAMESPACE)
0040 namespace std{ using ::isspace; }
0041 #endif
0042
0043 #if defined(__STD_RWCOMPILER_H__) || defined(_RWSTD_VER)
0044
0045 #undef isspace
0046 #undef iswspace
0047 #endif
0048
0049 namespace {
0050
0051 template<class CharType>
0052 struct remove_whitespace_predicate;
0053
0054 template<>
0055 struct remove_whitespace_predicate<char>
0056 {
0057 bool operator()(unsigned char t){
0058 return ! std::isspace(t);
0059 }
0060 };
0061
0062 #ifndef BOOST_NO_CWCHAR
0063 template<>
0064 struct remove_whitespace_predicate<wchar_t>
0065 {
0066 bool operator()(wchar_t t){
0067 return ! std::iswspace(t);
0068 }
0069 };
0070 #endif
0071
0072 }
0073
0074
0075
0076
0077 namespace boost {
0078 namespace archive {
0079 namespace iterators {
0080
0081
0082
0083
0084 template<class Predicate, class Base>
0085 class filter_iterator
0086 : public boost::iterator_adaptor<
0087 filter_iterator<Predicate, Base>,
0088 Base,
0089 use_default,
0090 single_pass_traversal_tag
0091 >
0092 {
0093 friend class boost::iterator_core_access;
0094 typedef typename boost::iterator_adaptor<
0095 filter_iterator<Predicate, Base>,
0096 Base,
0097 use_default,
0098 single_pass_traversal_tag
0099 > super_t;
0100 typedef filter_iterator<Predicate, Base> this_t;
0101 typedef typename super_t::reference reference_type;
0102
0103 reference_type dereference_impl(){
0104 if(! m_full){
0105 while(! m_predicate(* this->base_reference()))
0106 ++(this->base_reference());
0107 m_full = true;
0108 }
0109 return * this->base_reference();
0110 }
0111
0112 reference_type dereference() const {
0113 return const_cast<this_t *>(this)->dereference_impl();
0114 }
0115
0116 Predicate m_predicate;
0117 bool m_full;
0118 public:
0119
0120
0121 void increment(){
0122 m_full = false;
0123 ++(this->base_reference());
0124 }
0125 filter_iterator(Base start) :
0126 super_t(start),
0127 m_full(false)
0128 {}
0129 filter_iterator(){}
0130 };
0131
0132 template<class Base>
0133 class remove_whitespace :
0134 public filter_iterator<
0135 remove_whitespace_predicate<
0136 typename boost::iterator_value<Base>::type
0137
0138 >,
0139 Base
0140 >
0141 {
0142 friend class boost::iterator_core_access;
0143 typedef filter_iterator<
0144 remove_whitespace_predicate<
0145 typename boost::iterator_value<Base>::type
0146
0147 >,
0148 Base
0149 > super_t;
0150 public:
0151
0152
0153 template<class T>
0154 remove_whitespace(T start) :
0155 super_t(Base(static_cast< T >(start)))
0156 {}
0157
0158 remove_whitespace(const remove_whitespace & rhs) :
0159 super_t(rhs.base_reference())
0160 {}
0161 };
0162
0163 }
0164 }
0165 }
0166
0167 #endif