10
10
#define _LIBCPP___STRING_CHAR_TRAITS_H
11
11
12
12
#include < __algorithm/fill_n.h>
13
+ #include < __algorithm/find.h>
13
14
#include < __algorithm/find_end.h>
14
15
#include < __algorithm/find_first_of.h>
15
16
#include < __algorithm/min.h>
16
17
#include < __assert>
17
18
#include < __compare/ordering.h>
18
19
#include < __config>
19
20
#include < __functional/hash.h>
21
+ #include < __functional/identity.h>
20
22
#include < __iterator/iterator_traits.h>
21
23
#include < __string/constexpr_c_functions.h>
22
24
#include < __type_traits/is_constant_evaluated.h>
@@ -272,10 +274,14 @@ struct _LIBCPP_TEMPLATE_VIS char_traits<char8_t> {
272
274
return std::__constexpr_memcmp (__s1, __s2, __element_count (__n));
273
275
}
274
276
275
- static _LIBCPP_HIDE_FROM_ABI constexpr size_t length (const char_type* __s) _NOEXCEPT;
277
+ static _LIBCPP_HIDE_FROM_ABI constexpr size_t length (const char_type* __str) _NOEXCEPT {
278
+ return std::__constexpr_strlen (__str);
279
+ }
276
280
277
281
_LIBCPP_HIDE_FROM_ABI static constexpr const char_type*
278
- find (const char_type* __s, size_t __n, const char_type& __a) _NOEXCEPT;
282
+ find (const char_type* __s, size_t __n, const char_type& __a) _NOEXCEPT {
283
+ return std::__constexpr_memchr (__s, __a, __n);
284
+ }
279
285
280
286
static _LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 char_type*
281
287
move (char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT {
@@ -307,25 +313,6 @@ struct _LIBCPP_TEMPLATE_VIS char_traits<char8_t> {
307
313
static inline _LIBCPP_HIDE_FROM_ABI constexpr int_type eof () noexcept { return int_type (EOF); }
308
314
};
309
315
310
- // TODO use '__builtin_strlen' if it ever supports char8_t ??
311
- inline constexpr size_t char_traits<char8_t >::length(const char_type* __s) _NOEXCEPT {
312
- size_t __len = 0 ;
313
- for (; !eq (*__s, char_type (0 )); ++__s)
314
- ++__len;
315
- return __len;
316
- }
317
-
318
- // TODO use '__builtin_char_memchr' if it ever supports char8_t ??
319
- inline constexpr const char8_t *
320
- char_traits<char8_t >::find(const char_type* __s, size_t __n, const char_type& __a) _NOEXCEPT {
321
- for (; __n; --__n) {
322
- if (eq (*__s, __a))
323
- return __s;
324
- ++__s;
325
- }
326
- return nullptr ;
327
- }
328
-
329
316
#endif // _LIBCPP_HAS_NO_CHAR8_T
330
317
331
318
template <>
@@ -353,9 +340,15 @@ struct _LIBCPP_TEMPLATE_VIS char_traits<char16_t> {
353
340
_LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR_SINCE_CXX17 int
354
341
compare (const char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT;
355
342
_LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR_SINCE_CXX17 size_t length (const char_type* __s) _NOEXCEPT;
356
- _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR_SINCE_CXX17 const char_type*
357
- find (const char_type* __s, size_t __n, const char_type& __a) _NOEXCEPT;
358
343
344
+ _LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR_SINCE_CXX17 const char_type*
345
+ find (const char_type* __s, size_t __n, const char_type& __a) _NOEXCEPT {
346
+ __identity __proj;
347
+ const char_type* __match = std::__find_impl (__s, __s + __n, __a, __proj);
348
+ if (__match == __s + __n)
349
+ return nullptr ;
350
+ return __match;
351
+ }
359
352
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 static char_type*
360
353
move (char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT {
361
354
return std::__constexpr_memmove (__s1, __s2, __element_count (__n));
@@ -408,16 +401,6 @@ inline _LIBCPP_CONSTEXPR_SINCE_CXX17 size_t char_traits<char16_t>::length(const
408
401
return __len;
409
402
}
410
403
411
- inline _LIBCPP_CONSTEXPR_SINCE_CXX17 const char16_t *
412
- char_traits<char16_t >::find(const char_type* __s, size_t __n, const char_type& __a) _NOEXCEPT {
413
- for (; __n; --__n) {
414
- if (eq (*__s, __a))
415
- return __s;
416
- ++__s;
417
- }
418
- return nullptr ;
419
- }
420
-
421
404
template <>
422
405
struct _LIBCPP_TEMPLATE_VIS char_traits<char32_t > {
423
406
using char_type = char32_t ;
@@ -443,8 +426,15 @@ struct _LIBCPP_TEMPLATE_VIS char_traits<char32_t> {
443
426
_LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR_SINCE_CXX17 int
444
427
compare (const char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT;
445
428
_LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR_SINCE_CXX17 size_t length (const char_type* __s) _NOEXCEPT;
429
+
446
430
_LIBCPP_HIDE_FROM_ABI static _LIBCPP_CONSTEXPR_SINCE_CXX17 const char_type*
447
- find (const char_type* __s, size_t __n, const char_type& __a) _NOEXCEPT;
431
+ find (const char_type* __s, size_t __n, const char_type& __a) _NOEXCEPT {
432
+ __identity __proj;
433
+ const char_type* __match = std::__find_impl (__s, __s + __n, __a, __proj);
434
+ if (__match == __s + __n)
435
+ return nullptr ;
436
+ return __match;
437
+ }
448
438
449
439
_LIBCPP_HIDE_FROM_ABI _LIBCPP_CONSTEXPR_SINCE_CXX20 static char_type*
450
440
move (char_type* __s1, const char_type* __s2, size_t __n) _NOEXCEPT {
@@ -496,16 +486,6 @@ inline _LIBCPP_CONSTEXPR_SINCE_CXX17 size_t char_traits<char32_t>::length(const
496
486
return __len;
497
487
}
498
488
499
- inline _LIBCPP_CONSTEXPR_SINCE_CXX17 const char32_t *
500
- char_traits<char32_t >::find(const char_type* __s, size_t __n, const char_type& __a) _NOEXCEPT {
501
- for (; __n; --__n) {
502
- if (eq (*__s, __a))
503
- return __s;
504
- ++__s;
505
- }
506
- return nullptr ;
507
- }
508
-
509
489
// helper fns for basic_string and string_view
510
490
511
491
// __str_find
0 commit comments