@@ -747,12 +747,12 @@ enum syntax_option_type
747
747
nosubs = 1 << 1 ,
748
748
optimize = 1 << 2 ,
749
749
collate = 1 << 3 ,
750
- ECMAScript = 1 << 4 ,
751
- basic = 1 << 5 ,
752
- extended = 1 << 6 ,
753
- awk = 1 << 7 ,
754
- grep = 1 << 8 ,
755
- egrep = 1 << 9
750
+ ECMAScript = 0 ,
751
+ basic = 1 << 4 ,
752
+ extended = 1 << 5 ,
753
+ awk = 1 << 6 ,
754
+ grep = 1 << 7 ,
755
+ egrep = 1 << 8
756
756
};
757
757
758
758
inline
@@ -907,7 +907,9 @@ enum error_type
907
907
error_badrepeat,
908
908
error_complexity,
909
909
error_stack,
910
- error_temp
910
+ __re_err_grammar,
911
+ __re_err_empty,
912
+ __re_err_unknown
911
913
};
912
914
913
915
} // regex_constants
@@ -1538,8 +1540,17 @@ __loop<_CharT>::__exec(__state& __s) const
1538
1540
}
1539
1541
else
1540
1542
{
1541
- if (__max_ > 0 )
1543
+ __s.__loop_data_ [__loop_id_].first = 0 ;
1544
+ bool __do_repeat = 0 < __max_;
1545
+ bool __do_alt = 0 >= __min_;
1546
+ if (__do_repeat && __do_alt)
1542
1547
__s.__do_ = __state::__split;
1548
+ else if (__do_repeat)
1549
+ {
1550
+ __s.__do_ = __state::__accept_but_not_consume;
1551
+ __s.__node_ = this ->first ();
1552
+ __init_repeat (__s);
1553
+ }
1543
1554
else
1544
1555
{
1545
1556
__s.__do_ = __state::__accept_but_not_consume;
@@ -2727,7 +2738,6 @@ private:
2727
2738
bool
2728
2739
__match_at_start (const _CharT* __first, const _CharT* __last,
2729
2740
match_results<const _CharT*, _Allocator>& __m,
2730
- vector<size_t >& __lc,
2731
2741
regex_constants::match_flag_type __flags) const ;
2732
2742
template <class _Allocator >
2733
2743
bool
@@ -2738,13 +2748,11 @@ private:
2738
2748
bool
2739
2749
__match_at_start_posix_nosubs (const _CharT* __first, const _CharT* __last,
2740
2750
match_results<const _CharT*, _Allocator>& __m,
2741
- vector<size_t >& __lc,
2742
2751
regex_constants::match_flag_type __flags) const ;
2743
2752
template <class _Allocator >
2744
2753
bool
2745
2754
__match_at_start_posix_subs (const _CharT* __first, const _CharT* __last,
2746
2755
match_results<const _CharT*, _Allocator>& __m,
2747
- vector<size_t >& __lc,
2748
2756
regex_constants::match_flag_type __flags) const ;
2749
2757
2750
2758
template <class _B , class _A , class _C , class _T >
@@ -2810,7 +2818,7 @@ basic_regex<_CharT, _Traits>::__parse(_ForwardIterator __first,
2810
2818
__h.release ();
2811
2819
__end_ = __start_.get ();
2812
2820
}
2813
- switch (__flags_ & 0x3F0 )
2821
+ switch (__flags_ & 0x1F0 )
2814
2822
{
2815
2823
case ECMAScript:
2816
2824
__parse_ecma_exp (__first, __last);
@@ -2828,7 +2836,7 @@ basic_regex<_CharT, _Traits>::__parse(_ForwardIterator __first,
2828
2836
case egrep:
2829
2837
break ;
2830
2838
default :
2831
- throw regex_error (regex_constants::error_temp );
2839
+ throw regex_error (regex_constants::__re_err_grammar );
2832
2840
}
2833
2841
}
2834
2842
@@ -2859,7 +2867,7 @@ basic_regex<_CharT, _Traits>::__parse_basic_reg_exp(_ForwardIterator __first,
2859
2867
}
2860
2868
}
2861
2869
if (__first != __last)
2862
- throw regex_error (regex_constants::error_temp );
2870
+ throw regex_error (regex_constants::__re_err_empty );
2863
2871
}
2864
2872
return __first;
2865
2873
}
@@ -2873,14 +2881,14 @@ basic_regex<_CharT, _Traits>::__parse_extended_reg_exp(_ForwardIterator __first,
2873
2881
__owns_one_state<_CharT>* __sa = __end_;
2874
2882
_ForwardIterator __temp = __parse_ERE_branch (__first, __last);
2875
2883
if (__temp == __first)
2876
- throw regex_error (regex_constants::error_temp );
2884
+ throw regex_error (regex_constants::__re_err_empty );
2877
2885
__first = __temp;
2878
2886
while (__first != __last && *__first == ' |' )
2879
2887
{
2880
2888
__owns_one_state<_CharT>* __sb = __end_;
2881
2889
__temp = __parse_ERE_branch (++__first, __last);
2882
2890
if (__temp == __first)
2883
- throw regex_error (regex_constants::error_temp );
2891
+ throw regex_error (regex_constants::__re_err_empty );
2884
2892
__push_alternation (__sa, __sb);
2885
2893
__first = __temp;
2886
2894
}
@@ -2895,7 +2903,7 @@ basic_regex<_CharT, _Traits>::__parse_ERE_branch(_ForwardIterator __first,
2895
2903
{
2896
2904
_ForwardIterator __temp = __parse_ERE_expression (__first, __last);
2897
2905
if (__temp == __first)
2898
- throw regex_error (regex_constants::error_temp );
2906
+ throw regex_error (regex_constants::__re_err_empty );
2899
2907
do
2900
2908
{
2901
2909
__first = __temp;
@@ -4879,7 +4887,7 @@ basic_regex<_CharT, _Traits>::__match_at_start_ecma(
4879
4887
__states.pop_back ();
4880
4888
break ;
4881
4889
default :
4882
- throw regex_error (regex_constants::error_temp );
4890
+ throw regex_error (regex_constants::__re_err_unknown );
4883
4891
break ;
4884
4892
}
4885
4893
} while (!__states.empty ());
@@ -4893,7 +4901,6 @@ bool
4893
4901
basic_regex<_CharT, _Traits>::__match_at_start_posix_nosubs(
4894
4902
const _CharT* __first, const _CharT* __last,
4895
4903
match_results<const _CharT*, _Allocator>& __m,
4896
- vector<size_t >& __lc,
4897
4904
regex_constants::match_flag_type __flags) const
4898
4905
{
4899
4906
deque<__state> __states;
@@ -4919,11 +4926,9 @@ basic_regex<_CharT, _Traits>::__match_at_start_posix_nosubs(
4919
4926
switch (__s.__do_ )
4920
4927
{
4921
4928
case __state::__end_state:
4922
- if (__highest_j < __s.__current_ - __s.__first_ )
4923
- {
4929
+ if (!__matched || __highest_j < __s.__current_ - __s.__first_ )
4924
4930
__highest_j = __s.__current_ - __s.__first_ ;
4925
- __matched = true ;
4926
- }
4931
+ __matched = true ;
4927
4932
if (__highest_j == _N)
4928
4933
__states.clear ();
4929
4934
else
@@ -4950,7 +4955,7 @@ basic_regex<_CharT, _Traits>::__match_at_start_posix_nosubs(
4950
4955
__states.pop_back ();
4951
4956
break ;
4952
4957
default :
4953
- throw regex_error (regex_constants::error_temp );
4958
+ throw regex_error (regex_constants::__re_err_unknown );
4954
4959
break ;
4955
4960
}
4956
4961
} while (!__states.empty ());
@@ -4971,7 +4976,6 @@ bool
4971
4976
basic_regex<_CharT, _Traits>::__match_at_start_posix_subs(
4972
4977
const _CharT* __first, const _CharT* __last,
4973
4978
match_results<const _CharT*, _Allocator>& __m,
4974
- vector<size_t >& __lc,
4975
4979
regex_constants::match_flag_type __flags) const
4976
4980
{
4977
4981
vector<__state> __states;
@@ -5001,16 +5005,16 @@ basic_regex<_CharT, _Traits>::__match_at_start_posix_subs(
5001
5005
switch (__s.__do_ )
5002
5006
{
5003
5007
case __state::__end_state:
5004
- if (__j == 0 || __highest_j < __j )
5008
+ if (!__matched || __highest_j < __s. __current_ - __s. __first_ )
5005
5009
{
5006
- __matched = true ;
5007
- __highest_j = __j;
5010
+ __highest_j = __s.__current_ - __s.__first_ ;
5008
5011
__best_state = __s;
5009
- if (__highest_j == _N || __highest_j == 0 )
5010
- __states.clear ();
5011
- else
5012
- __states.pop_back ();
5013
5012
}
5013
+ __matched = true ;
5014
+ if (__highest_j == _N)
5015
+ __states.clear ();
5016
+ else
5017
+ __states.pop_back ();
5014
5018
break ;
5015
5019
case __state::__accept_and_consume:
5016
5020
__j += __s.__current_ - __current;
@@ -5031,7 +5035,7 @@ basic_regex<_CharT, _Traits>::__match_at_start_posix_subs(
5031
5035
__states.pop_back ();
5032
5036
break ;
5033
5037
default :
5034
- throw regex_error (regex_constants::error_temp );
5038
+ throw regex_error (regex_constants::__re_err_unknown );
5035
5039
break ;
5036
5040
}
5037
5041
} while (!__states.empty ());
@@ -5054,14 +5058,13 @@ bool
5054
5058
basic_regex<_CharT, _Traits>::__match_at_start(
5055
5059
const _CharT* __first, const _CharT* __last,
5056
5060
match_results<const _CharT*, _Allocator>& __m,
5057
- vector<size_t >& __lc,
5058
5061
regex_constants::match_flag_type __flags) const
5059
5062
{
5060
- if (__flags_ & ECMAScript)
5063
+ if (( __flags_ & 0x1F0 ) == ECMAScript)
5061
5064
return __match_at_start_ecma (__first, __last, __m, __flags);
5062
5065
if (mark_count () == 0 )
5063
- return __match_at_start_posix_nosubs (__first, __last, __m, __lc, __flags);
5064
- return __match_at_start_posix_subs (__first, __last, __m, __lc, __flags);
5066
+ return __match_at_start_posix_nosubs (__first, __last, __m, __flags);
5067
+ return __match_at_start_posix_subs (__first, __last, __m, __flags);
5065
5068
}
5066
5069
5067
5070
template <class _CharT , class _Traits >
@@ -5075,8 +5078,7 @@ basic_regex<_CharT, _Traits>::__search(
5075
5078
if (__left_anchor_)
5076
5079
__flags |= regex_constants::match_continuous;
5077
5080
__m.__init (1 + mark_count (), __first, __last);
5078
- vector<size_t > __lc (__loop_count ());
5079
- if (__match_at_start (__first, __last, __m, __lc, __flags))
5081
+ if (__match_at_start (__first, __last, __m, __flags))
5080
5082
{
5081
5083
__m.__prefix_ .second = __m[0 ].first ;
5082
5084
__m.__prefix_ .matched = __m.__prefix_ .first != __m.__prefix_ .second ;
@@ -5089,7 +5091,7 @@ basic_regex<_CharT, _Traits>::__search(
5089
5091
__m.__matches_ .assign (__m.size (), __m.__unmatched_ );
5090
5092
for (++__first; __first != __last; ++__first)
5091
5093
{
5092
- if (__match_at_start (__first, __last, __m, __lc, __flags))
5094
+ if (__match_at_start (__first, __last, __m, __flags))
5093
5095
{
5094
5096
__m.__prefix_ .second = __m[0 ].first ;
5095
5097
__m.__prefix_ .matched = __m.__prefix_ .first != __m.__prefix_ .second ;
0 commit comments