File indexing completed on 2025-01-18 09:51:26
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021 #ifndef BOOST_REGEX_SPLIT_HPP
0022 #define BOOST_REGEX_SPLIT_HPP
0023
0024 namespace boost{
0025
0026 #ifdef BOOST_MSVC
0027 #pragma warning(push)
0028 #pragma warning(disable: 4103)
0029 #endif
0030 #ifdef BOOST_HAS_ABI_HEADERS
0031 # include BOOST_ABI_PREFIX
0032 #endif
0033 #ifdef BOOST_MSVC
0034 #pragma warning(pop)
0035 #endif
0036
0037 #ifdef BOOST_MSVC
0038 # pragma warning(push)
0039 #if BOOST_MSVC < 1910
0040 #pragma warning(disable:4800)
0041 #endif
0042 #endif
0043
0044 namespace BOOST_REGEX_DETAIL_NS{
0045
0046 template <class charT>
0047 const basic_regex<charT>& get_default_expression(charT)
0048 {
0049 static const charT expression_text[4] = { '\\', 's', '+', '\00', };
0050 static const basic_regex<charT> e(expression_text);
0051 return e;
0052 }
0053
0054 template <class OutputIterator, class charT, class Traits1, class Alloc1>
0055 class split_pred
0056 {
0057 typedef std::basic_string<charT, Traits1, Alloc1> string_type;
0058 typedef typename string_type::const_iterator iterator_type;
0059 iterator_type* p_last;
0060 OutputIterator* p_out;
0061 std::size_t* p_max;
0062 std::size_t initial_max;
0063 public:
0064 split_pred(iterator_type* a, OutputIterator* b, std::size_t* c)
0065 : p_last(a), p_out(b), p_max(c), initial_max(*c) {}
0066
0067 bool operator()(const match_results<iterator_type>& what);
0068 };
0069
0070 template <class OutputIterator, class charT, class Traits1, class Alloc1>
0071 bool split_pred<OutputIterator, charT, Traits1, Alloc1>::operator()
0072 (const match_results<iterator_type>& what)
0073 {
0074 *p_last = what[0].second;
0075 if(what.size() > 1)
0076 {
0077
0078 for(unsigned i = 1; i < what.size(); ++i)
0079 {
0080 *(*p_out) = what.str(i);
0081 ++(*p_out);
0082 if(0 == --*p_max) return false;
0083 }
0084 return *p_max != 0;
0085 }
0086 else
0087 {
0088
0089 const sub_match<iterator_type>& sub = what[-1];
0090 if((sub.first != sub.second) || (*p_max != initial_max))
0091 {
0092 *(*p_out) = sub.str();
0093 ++(*p_out);
0094 return --*p_max;
0095 }
0096 }
0097
0098
0099 return true;
0100 }
0101
0102 }
0103
0104 template <class OutputIterator, class charT, class Traits1, class Alloc1, class Traits2>
0105 std::size_t regex_split(OutputIterator out,
0106 std::basic_string<charT, Traits1, Alloc1>& s,
0107 const basic_regex<charT, Traits2>& e,
0108 match_flag_type flags,
0109 std::size_t max_split)
0110 {
0111 typedef typename std::basic_string<charT, Traits1, Alloc1>::const_iterator ci_t;
0112
0113 ci_t last = s.begin();
0114 std::size_t init_size = max_split;
0115 BOOST_REGEX_DETAIL_NS::split_pred<OutputIterator, charT, Traits1, Alloc1> pred(&last, &out, &max_split);
0116 ci_t i, j;
0117 i = s.begin();
0118 j = s.end();
0119 regex_grep(pred, i, j, e, flags);
0120
0121
0122
0123
0124 if(max_split && (last != s.end()) && (e.mark_count() == 0))
0125 {
0126 *out = std::basic_string<charT, Traits1, Alloc1>((ci_t)last, (ci_t)s.end());
0127 ++out;
0128 last = s.end();
0129 --max_split;
0130 }
0131
0132
0133 s.erase(0, last - s.begin());
0134
0135
0136 return init_size - max_split;
0137 }
0138
0139 template <class OutputIterator, class charT, class Traits1, class Alloc1, class Traits2>
0140 inline std::size_t regex_split(OutputIterator out,
0141 std::basic_string<charT, Traits1, Alloc1>& s,
0142 const basic_regex<charT, Traits2>& e,
0143 match_flag_type flags = match_default)
0144 {
0145 return regex_split(out, s, e, flags, UINT_MAX);
0146 }
0147
0148 template <class OutputIterator, class charT, class Traits1, class Alloc1>
0149 inline std::size_t regex_split(OutputIterator out,
0150 std::basic_string<charT, Traits1, Alloc1>& s)
0151 {
0152 return regex_split(out, s, BOOST_REGEX_DETAIL_NS::get_default_expression(charT(0)), match_default, UINT_MAX);
0153 }
0154
0155 #ifdef BOOST_MSVC
0156 # pragma warning(pop)
0157 #endif
0158
0159 #ifdef BOOST_MSVC
0160 #pragma warning(push)
0161 #pragma warning(disable: 4103)
0162 #endif
0163 #ifdef BOOST_HAS_ABI_HEADERS
0164 # include BOOST_ABI_SUFFIX
0165 #endif
0166 #ifdef BOOST_MSVC
0167 #pragma warning(pop)
0168 #endif
0169
0170 }
0171
0172 #endif
0173
0174