Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes14kdownloads
__string991 linesDownload Raw Back to include
1// -*- C++ -*-2//===-------------------------- __string ----------------------------------===//3//4// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.5// See https://llvm.org/LICENSE.txt for license information.6// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception7//8//===----------------------------------------------------------------------===//9 10#ifndef _LIBCUDACXX___STRING11#define _LIBCUDACXX___STRING12 13/*14    string synopsis15 16namespace std17{18 19template <class charT>20struct char_traits21{22    typedef charT     char_type;23    typedef ...       int_type;24    typedef streamoff off_type;25    typedef streampos pos_type;26    typedef mbstate_t state_type;27 28    static constexpr void assign(char_type& c1, const char_type& c2) noexcept;29    static constexpr bool eq(char_type c1, char_type c2) noexcept;30    static constexpr bool lt(char_type c1, char_type c2) noexcept;31 32    static constexpr int    compare(const char_type* s1, const char_type* s2, size_t n);33    static constexpr size_t length(const char_type* s);34    static constexpr const char_type*35                            find(const char_type* s, size_t n, const char_type& a);36    static char_type*       move(char_type* s1, const char_type* s2, size_t n);37    static char_type*       copy(char_type* s1, const char_type* s2, size_t n);38    static char_type*       assign(char_type* s, size_t n, char_type a);39 40    static constexpr int_type  not_eof(int_type c) noexcept;41    static constexpr char_type to_char_type(int_type c) noexcept;42    static constexpr int_type  to_int_type(char_type c) noexcept;43    static constexpr bool      eq_int_type(int_type c1, int_type c2) noexcept;44    static constexpr int_type  eof() noexcept;45};46 47template <> struct char_traits<char>;48template <> struct char_traits<wchar_t>;49template <> struct char_traits<char8_t>;  // c++2050 51}  // std52 53*/54 55#include <__config>56#include <algorithm>  // for search and min57#include <cstdio>     // For EOF.58#include <memory>     // for __murmur2_or_cityhash59 60#include "__assert" // all public C++ headers provide the assertion handler61#include <__debug>62 63#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)64#  pragma GCC system_header65#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)66#  pragma clang system_header67#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)68#  pragma system_header69#endif // no system header70 71_LIBCUDACXX_PUSH_MACROS72#include <__undef_macros>73 74#include "__fwd/string.h"75 76_LIBCUDACXX_BEGIN_NAMESPACE_STD77 78// char_traits79 80template <class _CharT>81struct _LIBCUDACXX_TEMPLATE_VIS char_traits82{83    typedef _CharT    char_type;84    typedef int       int_type;85    typedef streamoff off_type;86    typedef streampos pos_type;87    typedef mbstate_t state_type;88 89    static inline void _LIBCUDACXX_CONSTEXPR_AFTER_CXX1490        assign(char_type& __c1, const char_type& __c2) noexcept {__c1 = __c2;}91    static inline constexpr bool eq(char_type __c1, char_type __c2) noexcept92        {return __c1 == __c2;}93    static inline constexpr bool lt(char_type __c1, char_type __c2) noexcept94        {return __c1 < __c2;}95 96    static _LIBCUDACXX_CONSTEXPR_AFTER_CXX1497    int compare(const char_type* __s1, const char_type* __s2, size_t __n);98    _LIBCUDACXX_INLINE_VISIBILITY static _LIBCUDACXX_CONSTEXPR_AFTER_CXX1499    size_t length(const char_type* __s);100    _LIBCUDACXX_INLINE_VISIBILITY static _LIBCUDACXX_CONSTEXPR_AFTER_CXX14101    const char_type* find(const char_type* __s, size_t __n, const char_type& __a);102    static char_type*       move(char_type* __s1, const char_type* __s2, size_t __n);103    _LIBCUDACXX_INLINE_VISIBILITY104    static char_type*       copy(char_type* __s1, const char_type* __s2, size_t __n);105    _LIBCUDACXX_INLINE_VISIBILITY106    static char_type*       assign(char_type* __s, size_t __n, char_type __a);107 108    static inline constexpr int_type  not_eof(int_type __c) noexcept109        {return eq_int_type(__c, eof()) ? ~eof() : __c;}110    static inline constexpr char_type to_char_type(int_type __c) noexcept111        {return char_type(__c);}112    static inline constexpr int_type  to_int_type(char_type __c) noexcept113        {return int_type(__c);}114    static inline constexpr bool      eq_int_type(int_type __c1, int_type __c2) noexcept115        {return __c1 == __c2;}116    static inline constexpr int_type  eof() noexcept117        {return int_type(EOF);}118};119 120template <class _CharT>121_LIBCUDACXX_CONSTEXPR_AFTER_CXX14 int122char_traits<_CharT>::compare(const char_type* __s1, const char_type* __s2, size_t __n)123{124    for (; __n; --__n, ++__s1, ++__s2)125    {126        if (lt(*__s1, *__s2))127            return -1;128        if (lt(*__s2, *__s1))129            return 1;130    }131    return 0;132}133 134template <class _CharT>135inline136_LIBCUDACXX_CONSTEXPR_AFTER_CXX14 size_t137char_traits<_CharT>::length(const char_type* __s)138{139    size_t __len = 0;140    for (; !eq(*__s, char_type(0)); ++__s)141        ++__len;142    return __len;143}144 145template <class _CharT>146inline147_LIBCUDACXX_CONSTEXPR_AFTER_CXX14 const _CharT*148char_traits<_CharT>::find(const char_type* __s, size_t __n, const char_type& __a)149{150    for (; __n; --__n)151    {152        if (eq(*__s, __a))153            return __s;154        ++__s;155    }156    return 0;157}158 159template <class _CharT>160_CharT*161char_traits<_CharT>::move(char_type* __s1, const char_type* __s2, size_t __n)162{163    char_type* __r = __s1;164    if (__s1 < __s2)165    {166        for (; __n; --__n, ++__s1, ++__s2)167            assign(*__s1, *__s2);168    }169    else if (__s2 < __s1)170    {171        __s1 += __n;172        __s2 += __n;173        for (; __n; --__n)174            assign(*--__s1, *--__s2);175    }176    return __r;177}178 179template <class _CharT>180inline181_CharT*182char_traits<_CharT>::copy(char_type* __s1, const char_type* __s2, size_t __n)183{184    _LIBCUDACXX_ASSERT(__s2 < __s1 || __s2 >= __s1+__n, "char_traits::copy overlapped range");185    char_type* __r = __s1;186    for (; __n; --__n, ++__s1, ++__s2)187        assign(*__s1, *__s2);188    return __r;189}190 191template <class _CharT>192inline193_CharT*194char_traits<_CharT>::assign(char_type* __s, size_t __n, char_type __a)195{196    char_type* __r = __s;197    for (; __n; --__n, ++__s)198        assign(*__s, __a);199    return __r;200}201 202// char_traits<char>203 204template <>205struct _LIBCUDACXX_TEMPLATE_VIS char_traits<char>206{207    typedef char      char_type;208    typedef int       int_type;209    typedef streamoff off_type;210    typedef streampos pos_type;211    typedef mbstate_t state_type;212 213    static inline _LIBCUDACXX_CONSTEXPR_AFTER_CXX14214    void assign(char_type& __c1, const char_type& __c2) noexcept {__c1 = __c2;}215    static inline constexpr bool eq(char_type __c1, char_type __c2) noexcept216            {return __c1 == __c2;}217    static inline constexpr bool lt(char_type __c1, char_type __c2) noexcept218        {return (unsigned char)__c1 < (unsigned char)__c2;}219 220    static _LIBCUDACXX_CONSTEXPR_AFTER_CXX14221    int compare(const char_type* __s1, const char_type* __s2, size_t __n) noexcept;222    static inline size_t _LIBCUDACXX_CONSTEXPR_AFTER_CXX14223    length(const char_type* __s)  noexcept {return __builtin_strlen(__s);}224    static _LIBCUDACXX_CONSTEXPR_AFTER_CXX14225    const char_type* find(const char_type* __s, size_t __n, const char_type& __a) noexcept;226    static inline char_type* move(char_type* __s1, const char_type* __s2, size_t __n) noexcept227        {return __n == 0 ? __s1 : (char_type*) memmove(__s1, __s2, __n);}228    static inline char_type* copy(char_type* __s1, const char_type* __s2, size_t __n) noexcept229        {230            _LIBCUDACXX_ASSERT(__s2 < __s1 || __s2 >= __s1+__n, "char_traits::copy overlapped range");231            return __n == 0 ? __s1 : (char_type*)memcpy(__s1, __s2, __n);232        }233    static inline char_type* assign(char_type* __s, size_t __n, char_type __a) noexcept234        {return __n == 0 ? __s : (char_type*)memset(__s, to_int_type(__a), __n);}235 236    static inline constexpr int_type  not_eof(int_type __c) noexcept237        {return eq_int_type(__c, eof()) ? ~eof() : __c;}238    static inline constexpr char_type to_char_type(int_type __c) noexcept239        {return char_type(__c);}240    static inline constexpr int_type to_int_type(char_type __c) noexcept241        {return int_type((unsigned char)__c);}242    static inline constexpr bool eq_int_type(int_type __c1, int_type __c2) noexcept243        {return __c1 == __c2;}244    static inline constexpr int_type  eof() noexcept245        {return int_type(EOF);}246};247 248inline _LIBCUDACXX_CONSTEXPR_AFTER_CXX14249int250char_traits<char>::compare(const char_type* __s1, const char_type* __s2, size_t __n) noexcept251{252    if (__n == 0)253        return 0;254#if __has_feature(cxx_constexpr_string_builtins)255    return __builtin_memcmp(__s1, __s2, __n);256#elif _LIBCUDACXX_STD_VER <= 14257    return memcmp(__s1, __s2, __n);258#else259    for (; __n; --__n, ++__s1, ++__s2)260    {261        if (lt(*__s1, *__s2))262            return -1;263        if (lt(*__s2, *__s1))264            return 1;265    }266    return 0;267#endif268}269 270inline _LIBCUDACXX_CONSTEXPR_AFTER_CXX14271const char*272char_traits<char>::find(const char_type* __s, size_t __n, const char_type& __a) noexcept273{274    if (__n == 0)275        return nullptr;276#if __has_feature(cxx_constexpr_string_builtins)277    return __builtin_char_memchr(__s, to_int_type(__a), __n);278#elif _LIBCUDACXX_STD_VER <= 14279    return (const char_type*) memchr(__s, to_int_type(__a), __n);280#else281    for (; __n; --__n)282    {283        if (eq(*__s, __a))284            return __s;285        ++__s;286    }287    return nullptr;288#endif289}290 291 292// char_traits<wchar_t>293 294template <>295struct _LIBCUDACXX_TEMPLATE_VIS char_traits<wchar_t>296{297    typedef wchar_t   char_type;298    typedef wint_t    int_type;299    typedef streamoff off_type;300    typedef streampos pos_type;301    typedef mbstate_t state_type;302 303    static inline _LIBCUDACXX_CONSTEXPR_AFTER_CXX14304    void assign(char_type& __c1, const char_type& __c2) noexcept {__c1 = __c2;}305    static inline constexpr bool eq(char_type __c1, char_type __c2) noexcept306        {return __c1 == __c2;}307    static inline constexpr bool lt(char_type __c1, char_type __c2) noexcept308        {return __c1 < __c2;}309 310    static _LIBCUDACXX_CONSTEXPR_AFTER_CXX14311    int compare(const char_type* __s1, const char_type* __s2, size_t __n) noexcept;312    static _LIBCUDACXX_CONSTEXPR_AFTER_CXX14313    size_t length(const char_type* __s) noexcept;314    static _LIBCUDACXX_CONSTEXPR_AFTER_CXX14315    const char_type* find(const char_type* __s, size_t __n, const char_type& __a) noexcept;316    static inline char_type* move(char_type* __s1, const char_type* __s2, size_t __n) noexcept317        {return __n == 0 ? __s1 : (char_type*)wmemmove(__s1, __s2, __n);}318    static inline char_type* copy(char_type* __s1, const char_type* __s2, size_t __n) noexcept319        {320            _LIBCUDACXX_ASSERT(__s2 < __s1 || __s2 >= __s1+__n, "char_traits::copy overlapped range");321            return __n == 0 ? __s1 : (char_type*)wmemcpy(__s1, __s2, __n);322        }323    static inline char_type* assign(char_type* __s, size_t __n, char_type __a) noexcept324        {return __n == 0 ? __s : (char_type*)wmemset(__s, __a, __n);}325 326    static inline constexpr int_type  not_eof(int_type __c) noexcept327        {return eq_int_type(__c, eof()) ? ~eof() : __c;}328    static inline constexpr char_type to_char_type(int_type __c) noexcept329        {return char_type(__c);}330    static inline constexpr int_type to_int_type(char_type __c) noexcept331        {return int_type(__c);}332    static inline constexpr bool eq_int_type(int_type __c1, int_type __c2) noexcept333        {return __c1 == __c2;}334    static inline constexpr int_type eof() noexcept335        {return int_type(WEOF);}336};337 338inline _LIBCUDACXX_CONSTEXPR_AFTER_CXX14339int340char_traits<wchar_t>::compare(const char_type* __s1, const char_type* __s2, size_t __n) noexcept341{342    if (__n == 0)343        return 0;344#if __has_feature(cxx_constexpr_string_builtins)345    return __builtin_wmemcmp(__s1, __s2, __n);346#elif _LIBCUDACXX_STD_VER <= 14347    return wmemcmp(__s1, __s2, __n);348#else349    for (; __n; --__n, ++__s1, ++__s2)350    {351        if (lt(*__s1, *__s2))352            return -1;353        if (lt(*__s2, *__s1))354            return 1;355    }356    return 0;357#endif358}359 360 361template <class _Traits>362_LIBCUDACXX_INLINE_VISIBILITY363inline constexpr size_t __char_traits_length_checked(const typename _Traits::char_type* __s) noexcept {364#if _LIBCUDACXX_DEBUG_LEVEL >= 1365  return __s ? _Traits::length(__s) : (_CUDA_VSTD::__libcpp_debug_function(_CUDA_VSTD::__libcpp_debug_info(__FILE__, __LINE__, "p == nullptr", "null pointer pass to non-null argument of char_traits<...>::length")), 0);366#else367  return _Traits::length(__s);368#endif369}370 371inline _LIBCUDACXX_CONSTEXPR_AFTER_CXX14372size_t373char_traits<wchar_t>::length(const char_type* __s) noexcept374{375#if __has_feature(cxx_constexpr_string_builtins)376    return __builtin_wcslen(__s);377#elif _LIBCUDACXX_STD_VER <= 14378    return wcslen(__s);379#else380    size_t __len = 0;381    for (; !eq(*__s, char_type(0)); ++__s)382        ++__len;383    return __len;384#endif385}386 387inline _LIBCUDACXX_CONSTEXPR_AFTER_CXX14388const wchar_t*389char_traits<wchar_t>::find(const char_type* __s, size_t __n, const char_type& __a) noexcept390{391    if (__n == 0)392        return nullptr;393#if __has_feature(cxx_constexpr_string_builtins)394    return __builtin_wmemchr(__s, __a, __n);395#elif _LIBCUDACXX_STD_VER <= 14396    return wmemchr(__s, __a, __n);397#else398    for (; __n; --__n)399    {400        if (eq(*__s, __a))401            return __s;402        ++__s;403    }404    return nullptr;405#endif406}407 408 409#ifndef _LIBCUDACXX_NO_HAS_CHAR8_T410 411template <>412struct _LIBCUDACXX_TEMPLATE_VIS char_traits<char8_t>413{414    typedef char8_t        char_type;415    typedef unsigned int   int_type;416    typedef streamoff      off_type;417    typedef u8streampos    pos_type;418    typedef mbstate_t      state_type;419 420    static inline constexpr void assign(char_type& __c1, const char_type& __c2) noexcept421        {__c1 = __c2;}422    static inline constexpr bool eq(char_type __c1, char_type __c2) noexcept423        {return __c1 == __c2;}424    static inline constexpr bool lt(char_type __c1, char_type __c2) noexcept425        {return __c1 < __c2;}426 427    static constexpr428    int              compare(const char_type* __s1, const char_type* __s2, size_t __n) noexcept;429 430    static constexpr431    size_t           length(const char_type* __s) noexcept;432 433    _LIBCUDACXX_INLINE_VISIBILITY static constexpr434    const char_type* find(const char_type* __s, size_t __n, const char_type& __a) noexcept;435 436    static char_type*       move(char_type* __s1, const char_type* __s2, size_t __n) noexcept437        {return __n == 0 ? __s1 : (char_type*) memmove(__s1, __s2, __n);}438 439    static char_type*       copy(char_type* __s1, const char_type* __s2, size_t __n) noexcept440       {441            _LIBCUDACXX_ASSERT(__s2 < __s1 || __s2 >= __s1+__n, "char_traits::copy overlapped range");442            return __n == 0 ? __s1 : (char_type*)memcpy(__s1, __s2, __n);443       }444 445    static char_type*       assign(char_type* __s, size_t __n, char_type __a) noexcept446        {return __n == 0 ? __s : (char_type*)memset(__s, to_int_type(__a), __n);}447 448    static inline constexpr int_type  not_eof(int_type __c) noexcept449        {return eq_int_type(__c, eof()) ? ~eof() : __c;}450    static inline constexpr char_type to_char_type(int_type __c) noexcept451        {return char_type(__c);}452    static inline constexpr int_type to_int_type(char_type __c) noexcept453        {return int_type(__c);}454    static inline constexpr bool eq_int_type(int_type __c1, int_type __c2) noexcept455        {return __c1 == __c2;}456    static inline constexpr int_type eof() noexcept457        {return int_type(EOF);}458};459 460// TODO use '__builtin_strlen' if it ever supports char8_t ??461inline constexpr462size_t463char_traits<char8_t>::length(const char_type* __s) noexcept464{465    size_t __len = 0;466    for (; !eq(*__s, char_type(0)); ++__s)467        ++__len;468    return __len;469}470 471inline constexpr472int473char_traits<char8_t>::compare(const char_type* __s1, const char_type* __s2, size_t __n) noexcept474{475#if __has_feature(cxx_constexpr_string_builtins)476    return __builtin_memcmp(__s1, __s2, __n);477#else478    for (; __n; --__n, ++__s1, ++__s2)479    {480        if (lt(*__s1, *__s2))481            return -1;482        if (lt(*__s2, *__s1))483            return 1;484    }485    return 0;486#endif487}488 489// TODO use '__builtin_char_memchr' if it ever supports char8_t ??490inline constexpr491const char8_t*492char_traits<char8_t>::find(const char_type* __s, size_t __n, const char_type& __a) noexcept493{494    for (; __n; --__n)495    {496        if (eq(*__s, __a))497            return __s;498        ++__s;499    }500    return 0;501}502 503#endif // #_LIBCUDACXX_NO_HAS_CHAR8_T504 505#ifndef _LIBCUDACXX_HAS_NO_UNICODE_CHARS506 507template <>508struct _LIBCUDACXX_TEMPLATE_VIS char_traits<char16_t>509{510    typedef char16_t       char_type;511    typedef uint_least16_t int_type;512    typedef streamoff      off_type;513    typedef u16streampos   pos_type;514    typedef mbstate_t      state_type;515 516    static inline _LIBCUDACXX_CONSTEXPR_AFTER_CXX14517    void assign(char_type& __c1, const char_type& __c2) noexcept {__c1 = __c2;}518    static inline constexpr bool eq(char_type __c1, char_type __c2) noexcept519        {return __c1 == __c2;}520    static inline constexpr bool lt(char_type __c1, char_type __c2) noexcept521        {return __c1 < __c2;}522 523    _LIBCUDACXX_INLINE_VISIBILITY static _LIBCUDACXX_CONSTEXPR_AFTER_CXX14524    int              compare(const char_type* __s1, const char_type* __s2, size_t __n) noexcept;525    _LIBCUDACXX_INLINE_VISIBILITY static _LIBCUDACXX_CONSTEXPR_AFTER_CXX14526    size_t           length(const char_type* __s) noexcept;527    _LIBCUDACXX_INLINE_VISIBILITY static _LIBCUDACXX_CONSTEXPR_AFTER_CXX14528    const char_type* find(const char_type* __s, size_t __n, const char_type& __a) noexcept;529    _LIBCUDACXX_INLINE_VISIBILITY530    static char_type*       move(char_type* __s1, const char_type* __s2, size_t __n) noexcept;531    _LIBCUDACXX_INLINE_VISIBILITY532    static char_type*       copy(char_type* __s1, const char_type* __s2, size_t __n) noexcept;533    _LIBCUDACXX_INLINE_VISIBILITY534    static char_type*       assign(char_type* __s, size_t __n, char_type __a) noexcept;535 536    static inline constexpr int_type  not_eof(int_type __c) noexcept537        {return eq_int_type(__c, eof()) ? ~eof() : __c;}538    static inline constexpr char_type to_char_type(int_type __c) noexcept539        {return char_type(__c);}540    static inline constexpr int_type to_int_type(char_type __c) noexcept541        {return int_type(__c);}542    static inline constexpr bool eq_int_type(int_type __c1, int_type __c2) noexcept543        {return __c1 == __c2;}544    static inline constexpr int_type eof() noexcept545        {return int_type(0xFFFF);}546};547 548inline _LIBCUDACXX_CONSTEXPR_AFTER_CXX14549int550char_traits<char16_t>::compare(const char_type* __s1, const char_type* __s2, size_t __n) noexcept551{552    for (; __n; --__n, ++__s1, ++__s2)553    {554        if (lt(*__s1, *__s2))555            return -1;556        if (lt(*__s2, *__s1))557            return 1;558    }559    return 0;560}561 562inline _LIBCUDACXX_CONSTEXPR_AFTER_CXX14563size_t564char_traits<char16_t>::length(const char_type* __s) noexcept565{566    size_t __len = 0;567    for (; !eq(*__s, char_type(0)); ++__s)568        ++__len;569    return __len;570}571 572inline _LIBCUDACXX_CONSTEXPR_AFTER_CXX14573const char16_t*574char_traits<char16_t>::find(const char_type* __s, size_t __n, const char_type& __a) noexcept575{576    for (; __n; --__n)577    {578        if (eq(*__s, __a))579            return __s;580        ++__s;581    }582    return 0;583}584 585inline586char16_t*587char_traits<char16_t>::move(char_type* __s1, const char_type* __s2, size_t __n) noexcept588{589    char_type* __r = __s1;590    if (__s1 < __s2)591    {592        for (; __n; --__n, ++__s1, ++__s2)593            assign(*__s1, *__s2);594    }595    else if (__s2 < __s1)596    {597        __s1 += __n;598        __s2 += __n;599        for (; __n; --__n)600            assign(*--__s1, *--__s2);601    }602    return __r;603}604 605inline606char16_t*607char_traits<char16_t>::copy(char_type* __s1, const char_type* __s2, size_t __n) noexcept608{609    _LIBCUDACXX_ASSERT(__s2 < __s1 || __s2 >= __s1+__n, "char_traits::copy overlapped range");610    char_type* __r = __s1;611    for (; __n; --__n, ++__s1, ++__s2)612        assign(*__s1, *__s2);613    return __r;614}615 616inline617char16_t*618char_traits<char16_t>::assign(char_type* __s, size_t __n, char_type __a) noexcept619{620    char_type* __r = __s;621    for (; __n; --__n, ++__s)622        assign(*__s, __a);623    return __r;624}625 626template <>627struct _LIBCUDACXX_TEMPLATE_VIS char_traits<char32_t>628{629    typedef char32_t       char_type;630    typedef uint_least32_t int_type;631    typedef streamoff      off_type;632    typedef u32streampos   pos_type;633    typedef mbstate_t      state_type;634 635    static inline _LIBCUDACXX_CONSTEXPR_AFTER_CXX14636    void assign(char_type& __c1, const char_type& __c2) noexcept {__c1 = __c2;}637    static inline constexpr bool eq(char_type __c1, char_type __c2) noexcept638        {return __c1 == __c2;}639    static inline constexpr bool lt(char_type __c1, char_type __c2) noexcept640        {return __c1 < __c2;}641 642    _LIBCUDACXX_INLINE_VISIBILITY static _LIBCUDACXX_CONSTEXPR_AFTER_CXX14643    int              compare(const char_type* __s1, const char_type* __s2, size_t __n) noexcept;644    _LIBCUDACXX_INLINE_VISIBILITY static _LIBCUDACXX_CONSTEXPR_AFTER_CXX14645    size_t           length(const char_type* __s) noexcept;646    _LIBCUDACXX_INLINE_VISIBILITY static _LIBCUDACXX_CONSTEXPR_AFTER_CXX14647    const char_type* find(const char_type* __s, size_t __n, const char_type& __a) noexcept;648    _LIBCUDACXX_INLINE_VISIBILITY649    static char_type*       move(char_type* __s1, const char_type* __s2, size_t __n) noexcept;650    _LIBCUDACXX_INLINE_VISIBILITY651    static char_type*       copy(char_type* __s1, const char_type* __s2, size_t __n) noexcept;652    _LIBCUDACXX_INLINE_VISIBILITY653    static char_type*       assign(char_type* __s, size_t __n, char_type __a) noexcept;654 655    static inline constexpr int_type  not_eof(int_type __c) noexcept656        {return eq_int_type(__c, eof()) ? ~eof() : __c;}657    static inline constexpr char_type to_char_type(int_type __c) noexcept658        {return char_type(__c);}659    static inline constexpr int_type to_int_type(char_type __c) noexcept660        {return int_type(__c);}661    static inline constexpr bool eq_int_type(int_type __c1, int_type __c2) noexcept662        {return __c1 == __c2;}663    static inline constexpr int_type eof() noexcept664        {return int_type(0xFFFFFFFF);}665};666 667inline _LIBCUDACXX_CONSTEXPR_AFTER_CXX14668int669char_traits<char32_t>::compare(const char_type* __s1, const char_type* __s2, size_t __n) noexcept670{671    for (; __n; --__n, ++__s1, ++__s2)672    {673        if (lt(*__s1, *__s2))674            return -1;675        if (lt(*__s2, *__s1))676            return 1;677    }678    return 0;679}680 681inline _LIBCUDACXX_CONSTEXPR_AFTER_CXX14682size_t683char_traits<char32_t>::length(const char_type* __s) noexcept684{685    size_t __len = 0;686    for (; !eq(*__s, char_type(0)); ++__s)687        ++__len;688    return __len;689}690 691inline _LIBCUDACXX_CONSTEXPR_AFTER_CXX14692const char32_t*693char_traits<char32_t>::find(const char_type* __s, size_t __n, const char_type& __a) noexcept694{695    for (; __n; --__n)696    {697        if (eq(*__s, __a))698            return __s;699        ++__s;700    }701    return 0;702}703 704inline705char32_t*706char_traits<char32_t>::move(char_type* __s1, const char_type* __s2, size_t __n) noexcept707{708    char_type* __r = __s1;709    if (__s1 < __s2)710    {711        for (; __n; --__n, ++__s1, ++__s2)712            assign(*__s1, *__s2);713    }714    else if (__s2 < __s1)715    {716        __s1 += __n;717        __s2 += __n;718        for (; __n; --__n)719            assign(*--__s1, *--__s2);720    }721    return __r;722}723 724inline725char32_t*726char_traits<char32_t>::copy(char_type* __s1, const char_type* __s2, size_t __n) noexcept727{728    _LIBCUDACXX_ASSERT(__s2 < __s1 || __s2 >= __s1+__n, "char_traits::copy overlapped range");729    char_type* __r = __s1;730    for (; __n; --__n, ++__s1, ++__s2)731        assign(*__s1, *__s2);732    return __r;733}734 735inline736char32_t*737char_traits<char32_t>::assign(char_type* __s, size_t __n, char_type __a) noexcept738{739    char_type* __r = __s;740    for (; __n; --__n, ++__s)741        assign(*__s, __a);742    return __r;743}744 745#endif  // _LIBCUDACXX_HAS_NO_UNICODE_CHARS746 747// helper fns for basic_string and string_view748 749// __str_find750template<class _CharT, class _SizeT, class _Traits, _SizeT __npos>751inline _SizeT _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 _LIBCUDACXX_INLINE_VISIBILITY752__str_find(const _CharT *__p, _SizeT __sz,753             _CharT __c, _SizeT __pos) noexcept754{755    if (__pos >= __sz)756        return __npos;757    const _CharT* __r = _Traits::find(__p + __pos, __sz - __pos, __c);758    if (__r == 0)759        return __npos;760    return static_cast<_SizeT>(__r - __p);761}762 763template <class _CharT, class _Traits>764inline _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 const _CharT *765__search_substring(const _CharT *__first1, const _CharT *__last1,766                   const _CharT *__first2, const _CharT *__last2) {767  // Take advantage of knowing source and pattern lengths.768  // Stop short when source is smaller than pattern.769  const ptrdiff_t __len2 = __last2 - __first2;770  if (__len2 == 0)771    return __first1;772 773  ptrdiff_t __len1 = __last1 - __first1;774  if (__len1 < __len2)775    return __last1;776 777  // First element of __first2 is loop invariant.778  _CharT __f2 = *__first2;779  while (true) {780    __len1 = __last1 - __first1;781    // Check whether __first1 still has at least __len2 bytes.782    if (__len1 < __len2)783      return __last1;784 785    // Find __f2 the first byte matching in __first1.786    __first1 = _Traits::find(__first1, __len1 - __len2 + 1, __f2);787    if (__first1 == 0)788      return __last1;789 790    // It is faster to compare from the first byte of __first1 even if we791    // already know that it matches the first byte of __first2: this is because792    // __first2 is most likely aligned, as it is user's "pattern" string, and793    // __first1 + 1 is most likely not aligned, as the match is in the middle of794    // the string.795    if (_Traits::compare(__first1, __first2, __len2) == 0)796      return __first1;797 798    ++__first1;799  }800}801 802template<class _CharT, class _SizeT, class _Traits, _SizeT __npos>803inline _SizeT _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 _LIBCUDACXX_INLINE_VISIBILITY804__str_find(const _CharT *__p, _SizeT __sz,805       const _CharT* __s, _SizeT __pos, _SizeT __n) noexcept806{807    if (__pos > __sz)808        return __npos;809 810    if (__n == 0) // There is nothing to search, just return __pos.811        return __pos;812 813    const _CharT *__r = __search_substring<_CharT, _Traits>(814        __p + __pos, __p + __sz, __s, __s + __n);815 816    if (__r == __p + __sz)817        return __npos;818    return static_cast<_SizeT>(__r - __p);819}820 821 822// __str_rfind823 824template<class _CharT, class _SizeT, class _Traits, _SizeT __npos>825inline _SizeT _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 _LIBCUDACXX_INLINE_VISIBILITY826__str_rfind(const _CharT *__p, _SizeT __sz,827              _CharT __c, _SizeT __pos) noexcept828{829    if (__sz < 1)830        return __npos;831    if (__pos < __sz)832        ++__pos;833    else834        __pos = __sz;835    for (const _CharT* __ps = __p + __pos; __ps != __p;)836    {837        if (_Traits::eq(*--__ps, __c))838            return static_cast<_SizeT>(__ps - __p);839    }840    return __npos;841}842 843template<class _CharT, class _SizeT, class _Traits, _SizeT __npos>844inline _SizeT _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 _LIBCUDACXX_INLINE_VISIBILITY845__str_rfind(const _CharT *__p, _SizeT __sz,846        const _CharT* __s, _SizeT __pos, _SizeT __n) noexcept847{848    __pos = _CUDA_VSTD::min(__pos, __sz);849    if (__n < __sz - __pos)850        __pos += __n;851    else852        __pos = __sz;853    const _CharT* __r = _CUDA_VSTD::__find_end(854                  __p, __p + __pos, __s, __s + __n, _Traits::eq,855                        random_access_iterator_tag(), random_access_iterator_tag());856    if (__n > 0 && __r == __p + __pos)857        return __npos;858    return static_cast<_SizeT>(__r - __p);859}860 861// __str_find_first_of862template<class _CharT, class _SizeT, class _Traits, _SizeT __npos>863inline _SizeT _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 _LIBCUDACXX_INLINE_VISIBILITY864__str_find_first_of(const _CharT *__p, _SizeT __sz,865                const _CharT* __s, _SizeT __pos, _SizeT __n) noexcept866{867    if (__pos >= __sz || __n == 0)868        return __npos;869    const _CharT* __r = _CUDA_VSTD::__find_first_of_ce870        (__p + __pos, __p + __sz, __s, __s + __n, _Traits::eq );871    if (__r == __p + __sz)872        return __npos;873    return static_cast<_SizeT>(__r - __p);874}875 876 877// __str_find_last_of878template<class _CharT, class _SizeT, class _Traits, _SizeT __npos>879inline _SizeT _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 _LIBCUDACXX_INLINE_VISIBILITY880__str_find_last_of(const _CharT *__p, _SizeT __sz,881               const _CharT* __s, _SizeT __pos, _SizeT __n) noexcept882    {883    if (__n != 0)884    {885        if (__pos < __sz)886            ++__pos;887        else888            __pos = __sz;889        for (const _CharT* __ps = __p + __pos; __ps != __p;)890        {891            const _CharT* __r = _Traits::find(__s, __n, *--__ps);892            if (__r)893                return static_cast<_SizeT>(__ps - __p);894        }895    }896    return __npos;897}898 899 900// __str_find_first_not_of901template<class _CharT, class _SizeT, class _Traits, _SizeT __npos>902inline _SizeT _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 _LIBCUDACXX_INLINE_VISIBILITY903__str_find_first_not_of(const _CharT *__p, _SizeT __sz,904                    const _CharT* __s, _SizeT __pos, _SizeT __n) noexcept905{906    if (__pos < __sz)907    {908        const _CharT* __pe = __p + __sz;909        for (const _CharT* __ps = __p + __pos; __ps != __pe; ++__ps)910            if (_Traits::find(__s, __n, *__ps) == 0)911                return static_cast<_SizeT>(__ps - __p);912    }913    return __npos;914}915 916 917template<class _CharT, class _SizeT, class _Traits, _SizeT __npos>918inline _SizeT _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 _LIBCUDACXX_INLINE_VISIBILITY919__str_find_first_not_of(const _CharT *__p, _SizeT __sz,920                          _CharT __c, _SizeT __pos) noexcept921{922    if (__pos < __sz)923    {924        const _CharT* __pe = __p + __sz;925        for (const _CharT* __ps = __p + __pos; __ps != __pe; ++__ps)926            if (!_Traits::eq(*__ps, __c))927                return static_cast<_SizeT>(__ps - __p);928    }929    return __npos;930}931 932 933// __str_find_last_not_of934template<class _CharT, class _SizeT, class _Traits, _SizeT __npos>935inline _SizeT _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 _LIBCUDACXX_INLINE_VISIBILITY936__str_find_last_not_of(const _CharT *__p, _SizeT __sz,937                   const _CharT* __s, _SizeT __pos, _SizeT __n) noexcept938{939    if (__pos < __sz)940        ++__pos;941    else942        __pos = __sz;943    for (const _CharT* __ps = __p + __pos; __ps != __p;)944        if (_Traits::find(__s, __n, *--__ps) == 0)945            return static_cast<_SizeT>(__ps - __p);946    return __npos;947}948 949 950template<class _CharT, class _SizeT, class _Traits, _SizeT __npos>951inline _SizeT _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 _LIBCUDACXX_INLINE_VISIBILITY952__str_find_last_not_of(const _CharT *__p, _SizeT __sz,953                         _CharT __c, _SizeT __pos) noexcept954{955    if (__pos < __sz)956        ++__pos;957    else958        __pos = __sz;959    for (const _CharT* __ps = __p + __pos; __ps != __p;)960        if (!_Traits::eq(*--__ps, __c))961            return static_cast<_SizeT>(__ps - __p);962    return __npos;963}964 965template<class _Ptr>966inline _LIBCUDACXX_INLINE_VISIBILITY967size_t __do_string_hash(_Ptr __p, _Ptr __e)968{969    typedef typename iterator_traits<_Ptr>::value_type value_type;970    return __murmur2_or_cityhash<size_t>()(__p, (__e-__p)*sizeof(value_type));971}972 973template <class _CharT, class _Iter, class _Traits=char_traits<_CharT> >974struct __quoted_output_proxy975{976    _Iter  __first;977    _Iter  __last;978    _CharT  __delim;979    _CharT  __escape;980 981    __quoted_output_proxy(_Iter __f, _Iter __l, _CharT __d, _CharT __e)982    : __first(__f), __last(__l), __delim(__d), __escape(__e) {}983    //  This would be a nice place for a string_ref984};985 986_LIBCUDACXX_END_NAMESPACE_STD987 988_LIBCUDACXX_POP_MACROS989 990#endif  // _LIBCUDACXX___STRING991 
codekingpro/portable-devtools · Team Ai