@@ -990,9 +990,81 @@ char_traits<char32_t>::assign(char_type* __s, size_t __n, char_type __a)
990
990
991
991
// helper fns for basic_string
992
992
993
+ // __find
993
994
template <class _CharT , class _SizeT , class _Traits , _SizeT __npos>
994
- _SizeT _LIBCPP_INLINE_VISIBILITY __find_first_of (const _CharT *__p, _SizeT __sz,
995
- const _CharT* __s, _SizeT __pos, _SizeT __n) _NOEXCEPT
995
+ _SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
996
+ __find (const _CharT *__p, _SizeT __sz,
997
+ _CharT __c, _SizeT __pos) _NOEXCEPT
998
+ {
999
+ if (__pos >= __sz)
1000
+ return __npos;
1001
+ const _CharT* __r = _Traits::find (__p + __pos, __sz - __pos, __c);
1002
+ if (__r == 0 )
1003
+ return __npos;
1004
+ return static_cast <_SizeT>(__r - __p);
1005
+ }
1006
+
1007
+ template <class _CharT , class _SizeT , class _Traits , _SizeT __npos>
1008
+ _SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
1009
+ __find (const _CharT *__p, _SizeT __sz,
1010
+ const _CharT* __s, _SizeT __pos, _SizeT __n) _NOEXCEPT
1011
+ {
1012
+ if (__pos > __sz || __sz - __pos < __n)
1013
+ return __npos;
1014
+ if (__n == 0 )
1015
+ return __pos;
1016
+ // if (__n == 1)
1017
+ // return _VSTD::__find<_CharT, _SizeT, _Traits, __npos>(__p, __sz, *__s, __pos);
1018
+ const _CharT* __r =
1019
+ _VSTD::search (__p + __pos, __p + __sz, __s, __s + __n, _Traits::eq);
1020
+ if (__r == __p + __sz)
1021
+ return __npos;
1022
+ return static_cast <_SizeT>(__r - __p);
1023
+ }
1024
+
1025
+
1026
+ // __rfind
1027
+
1028
+ template <class _CharT , class _SizeT , class _Traits , _SizeT __npos>
1029
+ _SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
1030
+ __rfind (const _CharT *__p, _SizeT __sz,
1031
+ _CharT __c, _SizeT __pos) _NOEXCEPT
1032
+ {
1033
+ if (__sz < 1 )
1034
+ return __npos;
1035
+ if (__pos < __sz)
1036
+ ++__pos;
1037
+ else
1038
+ __pos = __sz;
1039
+ for (const _CharT* __ps = __p + __pos; __ps != __p;)
1040
+ {
1041
+ if (_Traits::eq (*--__ps, __c))
1042
+ return static_cast <_SizeT>(__ps - __p);
1043
+ }
1044
+ return __npos;
1045
+ }
1046
+
1047
+ template <class _CharT , class _SizeT , class _Traits , _SizeT __npos>
1048
+ _SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
1049
+ __rfind (const _CharT *__p, _SizeT __sz,
1050
+ const _CharT* __s, _SizeT __pos, _SizeT __n) _NOEXCEPT
1051
+ {
1052
+ __pos = _VSTD::min (__pos, __sz);
1053
+ if (__n < __sz - __pos)
1054
+ __pos += __n;
1055
+ else
1056
+ __pos = __sz;
1057
+ const _CharT* __r = _VSTD::find_end (__p, __p + __pos, __s, __s + __n, _Traits::eq);
1058
+ if (__n > 0 && __r == __p + __pos)
1059
+ return __npos;
1060
+ return static_cast <_SizeT>(__r - __p);
1061
+ }
1062
+
1063
+ // __find_first_of
1064
+ template <class _CharT , class _SizeT , class _Traits , _SizeT __npos>
1065
+ _SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
1066
+ __find_first_of (const _CharT *__p, _SizeT __sz,
1067
+ const _CharT* __s, _SizeT __pos, _SizeT __n) _NOEXCEPT
996
1068
{
997
1069
if (__pos >= __sz || __n == 0 )
998
1070
return __npos;
@@ -1003,9 +1075,12 @@ _SizeT _LIBCPP_INLINE_VISIBILITY __find_first_of(const _CharT *__p, _SizeT __sz,
1003
1075
return static_cast <_SizeT>(__r - __p);
1004
1076
}
1005
1077
1078
+
1079
+ // __find_last_of
1006
1080
template <class _CharT , class _SizeT , class _Traits , _SizeT __npos>
1007
- _SizeT _LIBCPP_INLINE_VISIBILITY __find_last_of (const _CharT *__p, _SizeT __sz,
1008
- const _CharT* __s, _SizeT __pos, _SizeT __n) _NOEXCEPT
1081
+ _SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
1082
+ __find_last_of (const _CharT *__p, _SizeT __sz,
1083
+ const _CharT* __s, _SizeT __pos, _SizeT __n) _NOEXCEPT
1009
1084
{
1010
1085
if (__n != 0 )
1011
1086
{
@@ -1024,9 +1099,11 @@ _SizeT _LIBCPP_INLINE_VISIBILITY __find_last_of(const _CharT *__p, _SizeT __sz,
1024
1099
}
1025
1100
1026
1101
1102
+ // __find_first_not_of
1027
1103
template <class _CharT , class _SizeT , class _Traits , _SizeT __npos>
1028
- _SizeT _LIBCPP_INLINE_VISIBILITY __find_first_not_of (const _CharT *__p, _SizeT __sz,
1029
- const _CharT* __s, _SizeT __pos, _SizeT __n) _NOEXCEPT
1104
+ _SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
1105
+ __find_first_not_of (const _CharT *__p, _SizeT __sz,
1106
+ const _CharT* __s, _SizeT __pos, _SizeT __n) _NOEXCEPT
1030
1107
{
1031
1108
if (__pos < __sz)
1032
1109
{
@@ -1040,8 +1117,9 @@ _SizeT _LIBCPP_INLINE_VISIBILITY __find_first_not_of(const _CharT *__p, _SizeT _
1040
1117
1041
1118
1042
1119
template <class _CharT , class _SizeT , class _Traits , _SizeT __npos>
1043
- _SizeT _LIBCPP_INLINE_VISIBILITY __find_first_not_of (const _CharT *__p, _SizeT __sz,
1044
- _CharT __c, _SizeT __pos) _NOEXCEPT
1120
+ _SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
1121
+ __find_first_not_of (const _CharT *__p, _SizeT __sz,
1122
+ _CharT __c, _SizeT __pos) _NOEXCEPT
1045
1123
{
1046
1124
if (__pos < __sz)
1047
1125
{
@@ -1054,9 +1132,11 @@ _SizeT _LIBCPP_INLINE_VISIBILITY __find_first_not_of(const _CharT *__p, _SizeT _
1054
1132
}
1055
1133
1056
1134
1135
+ // __find_last_not_of
1057
1136
template <class _CharT , class _SizeT , class _Traits , _SizeT __npos>
1058
- _SizeT _LIBCPP_INLINE_VISIBILITY __find_last_not_of (const _CharT *__p, _SizeT __sz,
1059
- const _CharT* __s, _SizeT __pos, _SizeT __n) _NOEXCEPT
1137
+ _SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
1138
+ __find_last_not_of (const _CharT *__p, _SizeT __sz,
1139
+ const _CharT* __s, _SizeT __pos, _SizeT __n) _NOEXCEPT
1060
1140
{
1061
1141
if (__pos < __sz)
1062
1142
++__pos;
@@ -1070,8 +1150,9 @@ _SizeT _LIBCPP_INLINE_VISIBILITY __find_last_not_of(const _CharT *__p, _SizeT __
1070
1150
1071
1151
1072
1152
template <class _CharT , class _SizeT , class _Traits , _SizeT __npos>
1073
- _SizeT _LIBCPP_INLINE_VISIBILITY __find_last_not_of (const _CharT *__p, _SizeT __sz,
1074
- _CharT __c, _SizeT __pos) _NOEXCEPT
1153
+ _SizeT _LIBCPP_CONSTEXPR_AFTER_CXX11 _LIBCPP_INLINE_VISIBILITY
1154
+ __find_last_not_of (const _CharT *__p, _SizeT __sz,
1155
+ _CharT __c, _SizeT __pos) _NOEXCEPT
1075
1156
{
1076
1157
if (__pos < __sz)
1077
1158
++__pos;
@@ -3346,17 +3427,8 @@ basic_string<_CharT, _Traits, _Allocator>::find(const value_type* __s,
3346
3427
size_type __n) const _NOEXCEPT
3347
3428
{
3348
3429
_LIBCPP_ASSERT (__n == 0 || __s != nullptr , " string::find(): received nullptr" );
3349
- size_type __sz = size ();
3350
- if (__pos > __sz || __sz - __pos < __n)
3351
- return npos;
3352
- if (__n == 0 )
3353
- return __pos;
3354
- const value_type* __p = data ();
3355
- const value_type* __r = _VSTD::search (__p + __pos, __p + __sz, __s, __s + __n,
3356
- __traits_eq<traits_type>());
3357
- if (__r == __p + __sz)
3358
- return npos;
3359
- return static_cast <size_type>(__r - __p);
3430
+ return _VSTD::__find<value_type, size_type, traits_type, npos>
3431
+ (data (), size (), __s, __pos, __n);
3360
3432
}
3361
3433
3362
3434
template <class _CharT , class _Traits , class _Allocator >
@@ -3365,7 +3437,8 @@ typename basic_string<_CharT, _Traits, _Allocator>::size_type
3365
3437
basic_string<_CharT, _Traits, _Allocator>::find (const basic_string& __str,
3366
3438
size_type __pos) const _NOEXCEPT
3367
3439
{
3368
- return find (__str.data (), __pos, __str.size ());
3440
+ return _VSTD::__find<value_type, size_type, traits_type, npos>
3441
+ (data (), size (), __str.data (), __pos, __str.size ());
3369
3442
}
3370
3443
3371
3444
template <class _CharT , class _Traits , class _Allocator >
@@ -3375,22 +3448,17 @@ basic_string<_CharT, _Traits, _Allocator>::find(const value_type* __s,
3375
3448
size_type __pos) const _NOEXCEPT
3376
3449
{
3377
3450
_LIBCPP_ASSERT (__s != nullptr , " string::find(): received nullptr" );
3378
- return find (__s, __pos, traits_type::length (__s));
3451
+ return _VSTD::__find<value_type, size_type, traits_type, npos>
3452
+ (data (), size (), __s, __pos, traits_type::length (__s));
3379
3453
}
3380
3454
3381
3455
template <class _CharT , class _Traits , class _Allocator >
3382
3456
typename basic_string<_CharT, _Traits, _Allocator>::size_type
3383
3457
basic_string<_CharT, _Traits, _Allocator>::find (value_type __c,
3384
3458
size_type __pos) const _NOEXCEPT
3385
3459
{
3386
- size_type __sz = size ();
3387
- if (__pos >= __sz)
3388
- return npos;
3389
- const value_type* __p = data ();
3390
- const value_type* __r = traits_type::find (__p + __pos, __sz - __pos, __c);
3391
- if (__r == 0 )
3392
- return npos;
3393
- return static_cast <size_type>(__r - __p);
3460
+ return _VSTD::__find<value_type, size_type, traits_type, npos>
3461
+ (data (), size (), __c, __pos);
3394
3462
}
3395
3463
3396
3464
// rfind
@@ -3402,18 +3470,8 @@ basic_string<_CharT, _Traits, _Allocator>::rfind(const value_type* __s,
3402
3470
size_type __n) const _NOEXCEPT
3403
3471
{
3404
3472
_LIBCPP_ASSERT (__n == 0 || __s != nullptr , " string::rfind(): received nullptr" );
3405
- size_type __sz = size ();
3406
- __pos = _VSTD::min (__pos, __sz);
3407
- if (__n < __sz - __pos)
3408
- __pos += __n;
3409
- else
3410
- __pos = __sz;
3411
- const value_type* __p = data ();
3412
- const value_type* __r = _VSTD::find_end (__p, __p + __pos, __s, __s + __n,
3413
- __traits_eq<traits_type>());
3414
- if (__n > 0 && __r == __p + __pos)
3415
- return npos;
3416
- return static_cast <size_type>(__r - __p);
3473
+ return _VSTD::__rfind<value_type, size_type, traits_type, npos>
3474
+ (data (), size (), __s, __pos, __n);
3417
3475
}
3418
3476
3419
3477
template <class _CharT , class _Traits , class _Allocator >
@@ -3422,7 +3480,8 @@ typename basic_string<_CharT, _Traits, _Allocator>::size_type
3422
3480
basic_string<_CharT, _Traits, _Allocator>::rfind (const basic_string& __str,
3423
3481
size_type __pos) const _NOEXCEPT
3424
3482
{
3425
- return rfind (__str.data (), __pos, __str.size ());
3483
+ return _VSTD::__rfind<value_type, size_type, traits_type, npos>
3484
+ (data (), size (), __str.data (), __pos, __str.size ());
3426
3485
}
3427
3486
3428
3487
template <class _CharT , class _Traits , class _Allocator >
@@ -3432,29 +3491,17 @@ basic_string<_CharT, _Traits, _Allocator>::rfind(const value_type* __s,
3432
3491
size_type __pos) const _NOEXCEPT
3433
3492
{
3434
3493
_LIBCPP_ASSERT (__s != nullptr , " string::rfind(): received nullptr" );
3435
- return rfind (__s, __pos, traits_type::length (__s));
3494
+ return _VSTD::__rfind<value_type, size_type, traits_type, npos>
3495
+ (data (), size (), __s, __pos, traits_type::length (__s));
3436
3496
}
3437
3497
3438
3498
template <class _CharT , class _Traits , class _Allocator >
3439
3499
typename basic_string<_CharT, _Traits, _Allocator>::size_type
3440
3500
basic_string<_CharT, _Traits, _Allocator>::rfind (value_type __c,
3441
3501
size_type __pos) const _NOEXCEPT
3442
3502
{
3443
- size_type __sz = size ();
3444
- if (__sz)
3445
- {
3446
- if (__pos < __sz)
3447
- ++__pos;
3448
- else
3449
- __pos = __sz;
3450
- const value_type* __p = data ();
3451
- for (const value_type* __ps = __p + __pos; __ps != __p;)
3452
- {
3453
- if (traits_type::eq (*--__ps, __c))
3454
- return static_cast <size_type>(__ps - __p);
3455
- }
3456
- }
3457
- return npos;
3503
+ return _VSTD::__rfind<value_type, size_type, traits_type, npos>
3504
+ (data (), size (), __c, __pos);
3458
3505
}
3459
3506
3460
3507
// find_first_of
0 commit comments