Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes15kdownloads
string_view846 linesDownload Raw Back to include
1// -*- C++ -*-2//===------------------------ string_view ---------------------------------===//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_STRING_VIEW11#define _LIBCUDACXX_STRING_VIEW12 13/*14string_view synopsis15 16namespace std {17 18    // 7.2, Class template basic_string_view19    template<class charT, class traits = char_traits<charT>>20        class basic_string_view;21 22    // 7.9, basic_string_view non-member comparison functions23    template<class charT, class traits>24    constexpr bool operator==(basic_string_view<charT, traits> x,25                              basic_string_view<charT, traits> y) noexcept;26    template<class charT, class traits>27    constexpr bool operator!=(basic_string_view<charT, traits> x,28                              basic_string_view<charT, traits> y) noexcept;29    template<class charT, class traits>30    constexpr bool operator< (basic_string_view<charT, traits> x,31                                 basic_string_view<charT, traits> y) noexcept;32    template<class charT, class traits>33    constexpr bool operator> (basic_string_view<charT, traits> x,34                              basic_string_view<charT, traits> y) noexcept;35    template<class charT, class traits>36    constexpr bool operator<=(basic_string_view<charT, traits> x,37                                 basic_string_view<charT, traits> y) noexcept;38    template<class charT, class traits>39    constexpr bool operator>=(basic_string_view<charT, traits> x,40                              basic_string_view<charT, traits> y) noexcept;41    // see below, sufficient additional overloads of comparison functions42 43    // 7.10, Inserters and extractors44    template<class charT, class traits>45      basic_ostream<charT, traits>&46        operator<<(basic_ostream<charT, traits>& os,47                   basic_string_view<charT, traits> str);48 49    // basic_string_view typedef names50    typedef basic_string_view<char> string_view;51    typedef basic_string_view<char16_t> u16string_view;52    typedef basic_string_view<char32_t> u32string_view;53    typedef basic_string_view<wchar_t> wstring_view;54 55    template<class charT, class traits = char_traits<charT>>56    class basic_string_view {57      public:58      // types59      typedef traits traits_type;60      typedef charT value_type;61      typedef charT* pointer;62      typedef const charT* const_pointer;63      typedef charT& reference;64      typedef const charT& const_reference;65      typedef implementation-defined const_iterator;66      typedef const_iterator iterator;67      typedef reverse_iterator<const_iterator> const_reverse_iterator;68      typedef const_reverse_iterator reverse_iterator;69      typedef size_t size_type;70      typedef ptrdiff_t difference_type;71      static constexpr size_type npos = size_type(-1);72 73      // 7.3, basic_string_view constructors and assignment operators74      constexpr basic_string_view() noexcept;75      constexpr basic_string_view(const basic_string_view&) noexcept = default;76      basic_string_view& operator=(const basic_string_view&) noexcept = default;77      template<class Allocator>78      constexpr basic_string_view(const charT* str);79      constexpr basic_string_view(const charT* str, size_type len);80 81      // 7.4, basic_string_view iterator support82      constexpr const_iterator begin() const noexcept;83      constexpr const_iterator end() const noexcept;84      constexpr const_iterator cbegin() const noexcept;85      constexpr const_iterator cend() const noexcept;86      const_reverse_iterator rbegin() const noexcept;87      const_reverse_iterator rend() const noexcept;88      const_reverse_iterator crbegin() const noexcept;89      const_reverse_iterator crend() const noexcept;90 91      // 7.5, basic_string_view capacity92      constexpr size_type size() const noexcept;93      constexpr size_type length() const noexcept;94      constexpr size_type max_size() const noexcept;95      constexpr bool empty() const noexcept;96 97      // 7.6, basic_string_view element access98      constexpr const_reference operator[](size_type pos) const;99      constexpr const_reference at(size_type pos) const;100      constexpr const_reference front() const;101      constexpr const_reference back() const;102      constexpr const_pointer data() const noexcept;103 104      // 7.7, basic_string_view modifiers105      constexpr void remove_prefix(size_type n);106      constexpr void remove_suffix(size_type n);107      constexpr void swap(basic_string_view& s) noexcept;108 109      size_type copy(charT* s, size_type n, size_type pos = 0) const;110 111      constexpr basic_string_view substr(size_type pos = 0, size_type n = npos) const;112      constexpr int compare(basic_string_view s) const noexcept;113      constexpr int compare(size_type pos1, size_type n1, basic_string_view s) const;114      constexpr int compare(size_type pos1, size_type n1,115                            basic_string_view s, size_type pos2, size_type n2) const;116      constexpr int compare(const charT* s) const;117      constexpr int compare(size_type pos1, size_type n1, const charT* s) const;118      constexpr int compare(size_type pos1, size_type n1,119                            const charT* s, size_type n2) const;120      constexpr size_type find(basic_string_view s, size_type pos = 0) const noexcept;121      constexpr size_type find(charT c, size_type pos = 0) const noexcept;122      constexpr size_type find(const charT* s, size_type pos, size_type n) const;123      constexpr size_type find(const charT* s, size_type pos = 0) const;124      constexpr size_type rfind(basic_string_view s, size_type pos = npos) const noexcept;125      constexpr size_type rfind(charT c, size_type pos = npos) const noexcept;126      constexpr size_type rfind(const charT* s, size_type pos, size_type n) const;127      constexpr size_type rfind(const charT* s, size_type pos = npos) const;128      constexpr size_type find_first_of(basic_string_view s, size_type pos = 0) const noexcept;129      constexpr size_type find_first_of(charT c, size_type pos = 0) const noexcept;130      constexpr size_type find_first_of(const charT* s, size_type pos, size_type n) const;131      constexpr size_type find_first_of(const charT* s, size_type pos = 0) const;132      constexpr size_type find_last_of(basic_string_view s, size_type pos = npos) const noexcept;133      constexpr size_type find_last_of(charT c, size_type pos = npos) const noexcept;134      constexpr size_type find_last_of(const charT* s, size_type pos, size_type n) const;135      constexpr size_type find_last_of(const charT* s, size_type pos = npos) const;136      constexpr size_type find_first_not_of(basic_string_view s, size_type pos = 0) const noexcept;137      constexpr size_type find_first_not_of(charT c, size_type pos = 0) const noexcept;138      constexpr size_type find_first_not_of(const charT* s, size_type pos, size_type n) const;139      constexpr size_type find_first_not_of(const charT* s, size_type pos = 0) const;140      constexpr size_type find_last_not_of(basic_string_view s, size_type pos = npos) const noexcept;141      constexpr size_type find_last_not_of(charT c, size_type pos = npos) const noexcept;142      constexpr size_type find_last_not_of(const charT* s, size_type pos, size_type n) const;143      constexpr size_type find_last_not_of(const charT* s, size_type pos = npos) const;144 145      constexpr bool starts_with(basic_string_view s) const noexcept; // C++2a146      constexpr bool starts_with(charT c) const noexcept;             // C++2a147      constexpr bool starts_with(const charT* s) const;               // C++2a148      constexpr bool ends_with(basic_string_view s) const noexcept;   // C++2a149      constexpr bool ends_with(charT c) const noexcept;               // C++2a150      constexpr bool ends_with(const charT* s) const;                 // C++2a151 152     private:153      const_pointer data_;  // exposition only154      size_type     size_;  // exposition only155    };156 157  // 7.11, Hash support158  template <class T> struct hash;159  template <> struct hash<string_view>;160  template <> struct hash<u16string_view>;161  template <> struct hash<u32string_view>;162  template <> struct hash<wstring_view>;163 164  constexpr basic_string_view<char>     operator "" sv( const char *str,     size_t len ) noexcept;165  constexpr basic_string_view<wchar_t>  operator "" sv( const wchar_t *str,  size_t len ) noexcept;166  constexpr basic_string_view<char16_t> operator "" sv( const char16_t *str, size_t len ) noexcept;167  constexpr basic_string_view<char32_t> operator "" sv( const char32_t *str, size_t len ) noexcept;168 169}  // namespace std170 171 172*/173 174#include <__config>175#include <__string>176#include <iosfwd>177#include <algorithm>178#include <iterator>179#include <limits>180#include <stdexcept>181#include <version>182#include <__debug>183 184#include "__fwd/string_view.h"185 186#if defined(_CCCL_IMPLICIT_SYSTEM_HEADER_GCC)187#  pragma GCC system_header188#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_CLANG)189#  pragma clang system_header190#elif defined(_CCCL_IMPLICIT_SYSTEM_HEADER_MSVC)191#  pragma system_header192#endif // no system header193 194_LIBCUDACXX_PUSH_MACROS195#include <__undef_macros>196 197_LIBCUDACXX_BEGIN_NAMESPACE_STD198 199template<class _CharT, class _Traits>200class _LIBCUDACXX_TEMPLATE_VIS basic_string_view {201public:202    // types203    typedef _Traits                                    traits_type;204    typedef _CharT                                     value_type;205    typedef _CharT*                                    pointer;206    typedef const _CharT*                              const_pointer;207    typedef _CharT&                                    reference;208    typedef const _CharT&                              const_reference;209    typedef const_pointer                              const_iterator; // See [string.view.iterators]210    typedef const_iterator                             iterator;211    typedef _CUDA_VSTD::reverse_iterator<const_iterator>    const_reverse_iterator;212    typedef const_reverse_iterator                     reverse_iterator;213    typedef size_t                                     size_type;214    typedef ptrdiff_t                                  difference_type;215    static constexpr const size_type npos = -1; // size_type(-1);216 217    static_assert((!is_array<value_type>::value), "Character type of basic_string_view must not be an array");218    static_assert(( is_standard_layout<value_type>::value), "Character type of basic_string_view must be standard-layout");219    static_assert(( is_trivial<value_type>::value), "Character type of basic_string_view must be trivial");220    static_assert((is_same<_CharT, typename traits_type::char_type>::value),221                  "traits_type::char_type must be the same type as CharT");222 223    // [string.view.cons], construct/copy224    constexpr _LIBCUDACXX_INLINE_VISIBILITY225    basic_string_view() noexcept : __data (nullptr), __size(0) {}226 227    constexpr _LIBCUDACXX_INLINE_VISIBILITY228    basic_string_view(const basic_string_view&) noexcept = default;229 230    _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 _LIBCUDACXX_INLINE_VISIBILITY231    basic_string_view& operator=(const basic_string_view&) noexcept = default;232 233    constexpr _LIBCUDACXX_INLINE_VISIBILITY234    basic_string_view(const _CharT* __s, size_type __len) noexcept235        : __data(__s), __size(__len)236    {237#if _LIBCUDACXX_STD_VER > 11238    _LIBCUDACXX_ASSERT(__len == 0 || __s != nullptr, "string_view::string_view(_CharT *, size_t): received nullptr");239#endif240    }241 242    constexpr _LIBCUDACXX_INLINE_VISIBILITY243    basic_string_view(const _CharT* __s)244        : __data(__s), __size(std::__char_traits_length_checked<_Traits>(__s)) {}245 246    // [string.view.iterators], iterators247    constexpr _LIBCUDACXX_INLINE_VISIBILITY248    const_iterator begin()  const noexcept { return cbegin(); }249 250    constexpr _LIBCUDACXX_INLINE_VISIBILITY251    const_iterator end()    const noexcept { return cend(); }252 253    constexpr _LIBCUDACXX_INLINE_VISIBILITY254    const_iterator cbegin() const noexcept { return __data; }255 256    constexpr _LIBCUDACXX_INLINE_VISIBILITY257    const_iterator cend()   const noexcept { return __data + __size; }258 259    _LIBCUDACXX_CONSTEXPR_AFTER_CXX14 _LIBCUDACXX_INLINE_VISIBILITY260    const_reverse_iterator rbegin()   const noexcept { return const_reverse_iterator(cend()); }261 262    _LIBCUDACXX_CONSTEXPR_AFTER_CXX14 _LIBCUDACXX_INLINE_VISIBILITY263    const_reverse_iterator rend()     const noexcept { return const_reverse_iterator(cbegin()); }264 265    _LIBCUDACXX_CONSTEXPR_AFTER_CXX14 _LIBCUDACXX_INLINE_VISIBILITY266    const_reverse_iterator crbegin()  const noexcept { return const_reverse_iterator(cend()); }267 268    _LIBCUDACXX_CONSTEXPR_AFTER_CXX14 _LIBCUDACXX_INLINE_VISIBILITY269    const_reverse_iterator crend()    const noexcept { return const_reverse_iterator(cbegin()); }270 271    // [string.view.capacity], capacity272    constexpr _LIBCUDACXX_INLINE_VISIBILITY273    size_type size()     const noexcept { return __size; }274 275    constexpr _LIBCUDACXX_INLINE_VISIBILITY276    size_type length()   const noexcept { return __size; }277 278    constexpr _LIBCUDACXX_INLINE_VISIBILITY279    size_type max_size() const noexcept { return numeric_limits<size_type>::max(); }280 281    _LIBCUDACXX_NODISCARD_AFTER_CXX17 _LIBCUDACXX_INLINE_VISIBILITY constexpr282    bool empty()         const noexcept { return __size == 0; }283 284    // [string.view.access], element access285    constexpr _LIBCUDACXX_INLINE_VISIBILITY286    const_reference operator[](size_type __pos) const noexcept { return __data[__pos]; }287 288    constexpr _LIBCUDACXX_INLINE_VISIBILITY289    const_reference at(size_type __pos) const290    {291        return __pos >= size()292            ? (__throw_out_of_range("string_view::at"), __data[0])293            : __data[__pos];294    }295 296    constexpr _LIBCUDACXX_INLINE_VISIBILITY297    const_reference front() const noexcept298    {299        return _LIBCUDACXX_ASSERT(!empty(), "string_view::front(): string is empty"), __data[0];300    }301 302    constexpr _LIBCUDACXX_INLINE_VISIBILITY303    const_reference back() const noexcept304    {305        return _LIBCUDACXX_ASSERT(!empty(), "string_view::back(): string is empty"), __data[__size-1];306    }307 308    constexpr _LIBCUDACXX_INLINE_VISIBILITY309    const_pointer data() const noexcept { return __data; }310 311    // [string.view.modifiers], modifiers:312    _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 _LIBCUDACXX_INLINE_VISIBILITY313    void remove_prefix(size_type __n) noexcept314    {315        _LIBCUDACXX_ASSERT(__n <= size(), "remove_prefix() can't remove more than size()");316        __data += __n;317        __size -= __n;318    }319 320    _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 _LIBCUDACXX_INLINE_VISIBILITY321    void remove_suffix(size_type __n) noexcept322    {323        _LIBCUDACXX_ASSERT(__n <= size(), "remove_suffix() can't remove more than size()");324        __size -= __n;325    }326 327    _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 _LIBCUDACXX_INLINE_VISIBILITY328    void swap(basic_string_view& __other) noexcept329    {330        const value_type *__p = __data;331        __data = __other.__data;332        __other.__data = __p;333 334        size_type __sz = __size;335        __size = __other.__size;336        __other.__size = __sz;337    }338 339    _LIBCUDACXX_INLINE_VISIBILITY340    size_type copy(_CharT* __s, size_type __n, size_type __pos = 0) const341    {342        if (__pos > size())343            __throw_out_of_range("string_view::copy");344        size_type __rlen = _CUDA_VSTD::min(__n, size() - __pos);345        _Traits::copy(__s, data() + __pos, __rlen);346        return __rlen;347    }348 349    constexpr _LIBCUDACXX_INLINE_VISIBILITY350    basic_string_view substr(size_type __pos = 0, size_type __n = npos) const351    {352        return __pos > size()353            ? (__throw_out_of_range("string_view::substr"), basic_string_view())354            : basic_string_view(data() + __pos, _CUDA_VSTD::min(__n, size() - __pos));355    }356 357    _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 int compare(basic_string_view __sv) const noexcept358    {359        size_type __rlen = _CUDA_VSTD::min( size(), __sv.size());360        int __retval = _Traits::compare(data(), __sv.data(), __rlen);361        if ( __retval == 0 ) // first __rlen chars matched362            __retval = size() == __sv.size() ? 0 : ( size() < __sv.size() ? -1 : 1 );363        return __retval;364    }365 366    _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 _LIBCUDACXX_INLINE_VISIBILITY367    int compare(size_type __pos1, size_type __n1, basic_string_view __sv) const368    {369        return substr(__pos1, __n1).compare(__sv);370    }371 372    _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 _LIBCUDACXX_INLINE_VISIBILITY373    int compare(                       size_type __pos1, size_type __n1,374                basic_string_view __sv, size_type __pos2, size_type __n2) const375    {376        return substr(__pos1, __n1).compare(__sv.substr(__pos2, __n2));377    }378 379    _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 _LIBCUDACXX_INLINE_VISIBILITY380    int compare(const _CharT* __s) const noexcept381    {382        return compare(basic_string_view(__s));383    }384 385    _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 _LIBCUDACXX_INLINE_VISIBILITY386    int compare(size_type __pos1, size_type __n1, const _CharT* __s) const387    {388        return substr(__pos1, __n1).compare(basic_string_view(__s));389    }390 391    _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 _LIBCUDACXX_INLINE_VISIBILITY392    int compare(size_type __pos1, size_type __n1, const _CharT* __s, size_type __n2) const393    {394        return substr(__pos1, __n1).compare(basic_string_view(__s, __n2));395    }396 397    // find398    _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 _LIBCUDACXX_INLINE_VISIBILITY399    size_type find(basic_string_view __s, size_type __pos = 0) const noexcept400    {401        _LIBCUDACXX_ASSERT(__s.size() == 0 || __s.data() != nullptr, "string_view::find(): received nullptr");402        return __str_find<value_type, size_type, traits_type, npos>403            (data(), size(), __s.data(), __pos, __s.size());404    }405 406    _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 _LIBCUDACXX_INLINE_VISIBILITY407    size_type find(_CharT __c, size_type __pos = 0) const noexcept408    {409        return __str_find<value_type, size_type, traits_type, npos>410            (data(), size(), __c, __pos);411    }412 413    _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 _LIBCUDACXX_INLINE_VISIBILITY414    size_type find(const _CharT* __s, size_type __pos, size_type __n) const415    {416        _LIBCUDACXX_ASSERT(__n == 0 || __s != nullptr, "string_view::find(): received nullptr");417        return __str_find<value_type, size_type, traits_type, npos>418            (data(), size(), __s, __pos, __n);419    }420 421    _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 _LIBCUDACXX_INLINE_VISIBILITY422    size_type find(const _CharT* __s, size_type __pos = 0) const423    {424        _LIBCUDACXX_ASSERT(__s != nullptr, "string_view::find(): received nullptr");425        return __str_find<value_type, size_type, traits_type, npos>426            (data(), size(), __s, __pos, traits_type::length(__s));427    }428 429    // rfind430    _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 _LIBCUDACXX_INLINE_VISIBILITY431    size_type rfind(basic_string_view __s, size_type __pos = npos) const noexcept432    {433        _LIBCUDACXX_ASSERT(__s.size() == 0 || __s.data() != nullptr, "string_view::find(): received nullptr");434        return __str_rfind<value_type, size_type, traits_type, npos>435            (data(), size(), __s.data(), __pos, __s.size());436    }437 438    _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 _LIBCUDACXX_INLINE_VISIBILITY439    size_type rfind(_CharT __c, size_type __pos = npos) const noexcept440    {441        return __str_rfind<value_type, size_type, traits_type, npos>442            (data(), size(), __c, __pos);443    }444 445    _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 _LIBCUDACXX_INLINE_VISIBILITY446    size_type rfind(const _CharT* __s, size_type __pos, size_type __n) const447    {448        _LIBCUDACXX_ASSERT(__n == 0 || __s != nullptr, "string_view::rfind(): received nullptr");449        return __str_rfind<value_type, size_type, traits_type, npos>450            (data(), size(), __s, __pos, __n);451    }452 453    _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 _LIBCUDACXX_INLINE_VISIBILITY454    size_type rfind(const _CharT* __s, size_type __pos=npos) const455    {456        _LIBCUDACXX_ASSERT(__s != nullptr, "string_view::rfind(): received nullptr");457        return __str_rfind<value_type, size_type, traits_type, npos>458            (data(), size(), __s, __pos, traits_type::length(__s));459    }460 461    // find_first_of462    _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 _LIBCUDACXX_INLINE_VISIBILITY463    size_type find_first_of(basic_string_view __s, size_type __pos = 0) const noexcept464    {465        _LIBCUDACXX_ASSERT(__s.size() == 0 || __s.data() != nullptr, "string_view::find_first_of(): received nullptr");466        return __str_find_first_of<value_type, size_type, traits_type, npos>467            (data(), size(), __s.data(), __pos, __s.size());468    }469 470    _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 _LIBCUDACXX_INLINE_VISIBILITY471    size_type find_first_of(_CharT __c, size_type __pos = 0) const noexcept472    { return find(__c, __pos); }473 474    _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 _LIBCUDACXX_INLINE_VISIBILITY475    size_type find_first_of(const _CharT* __s, size_type __pos, size_type __n) const476    {477        _LIBCUDACXX_ASSERT(__n == 0 || __s != nullptr, "string_view::find_first_of(): received nullptr");478        return __str_find_first_of<value_type, size_type, traits_type, npos>479            (data(), size(), __s, __pos, __n);480    }481 482    _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 _LIBCUDACXX_INLINE_VISIBILITY483    size_type find_first_of(const _CharT* __s, size_type __pos=0) const484    {485        _LIBCUDACXX_ASSERT(__s != nullptr, "string_view::find_first_of(): received nullptr");486        return __str_find_first_of<value_type, size_type, traits_type, npos>487            (data(), size(), __s, __pos, traits_type::length(__s));488    }489 490    // find_last_of491    _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 _LIBCUDACXX_INLINE_VISIBILITY492    size_type find_last_of(basic_string_view __s, size_type __pos=npos) const noexcept493    {494        _LIBCUDACXX_ASSERT(__s.size() == 0 || __s.data() != nullptr, "string_view::find_last_of(): received nullptr");495        return __str_find_last_of<value_type, size_type, traits_type, npos>496            (data(), size(), __s.data(), __pos, __s.size());497    }498 499    _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 _LIBCUDACXX_INLINE_VISIBILITY500    size_type find_last_of(_CharT __c, size_type __pos = npos) const noexcept501    { return rfind(__c, __pos); }502 503    _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 _LIBCUDACXX_INLINE_VISIBILITY504    size_type find_last_of(const _CharT* __s, size_type __pos, size_type __n) const505    {506        _LIBCUDACXX_ASSERT(__n == 0 || __s != nullptr, "string_view::find_last_of(): received nullptr");507        return __str_find_last_of<value_type, size_type, traits_type, npos>508            (data(), size(), __s, __pos, __n);509    }510 511    _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 _LIBCUDACXX_INLINE_VISIBILITY512    size_type find_last_of(const _CharT* __s, size_type __pos=npos) const513    {514        _LIBCUDACXX_ASSERT(__s != nullptr, "string_view::find_last_of(): received nullptr");515        return __str_find_last_of<value_type, size_type, traits_type, npos>516            (data(), size(), __s, __pos, traits_type::length(__s));517    }518 519    // find_first_not_of520    _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 _LIBCUDACXX_INLINE_VISIBILITY521    size_type find_first_not_of(basic_string_view __s, size_type __pos=0) const noexcept522    {523        _LIBCUDACXX_ASSERT(__s.size() == 0 || __s.data() != nullptr, "string_view::find_first_not_of(): received nullptr");524        return __str_find_first_not_of<value_type, size_type, traits_type, npos>525            (data(), size(), __s.data(), __pos, __s.size());526    }527 528    _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 _LIBCUDACXX_INLINE_VISIBILITY529    size_type find_first_not_of(_CharT __c, size_type __pos=0) const noexcept530    {531        return __str_find_first_not_of<value_type, size_type, traits_type, npos>532            (data(), size(), __c, __pos);533    }534 535    _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 _LIBCUDACXX_INLINE_VISIBILITY536    size_type find_first_not_of(const _CharT* __s, size_type __pos, size_type __n) const537    {538        _LIBCUDACXX_ASSERT(__n == 0 || __s != nullptr, "string_view::find_first_not_of(): received nullptr");539        return __str_find_first_not_of<value_type, size_type, traits_type, npos>540            (data(), size(), __s, __pos, __n);541    }542 543    _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 _LIBCUDACXX_INLINE_VISIBILITY544    size_type find_first_not_of(const _CharT* __s, size_type __pos=0) const545    {546        _LIBCUDACXX_ASSERT(__s != nullptr, "string_view::find_first_not_of(): received nullptr");547        return __str_find_first_not_of<value_type, size_type, traits_type, npos>548            (data(), size(), __s, __pos, traits_type::length(__s));549    }550 551    // find_last_not_of552    _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 _LIBCUDACXX_INLINE_VISIBILITY553    size_type find_last_not_of(basic_string_view __s, size_type __pos=npos) const noexcept554    {555        _LIBCUDACXX_ASSERT(__s.size() == 0 || __s.data() != nullptr, "string_view::find_last_not_of(): received nullptr");556        return __str_find_last_not_of<value_type, size_type, traits_type, npos>557            (data(), size(), __s.data(), __pos, __s.size());558    }559 560    _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 _LIBCUDACXX_INLINE_VISIBILITY561    size_type find_last_not_of(_CharT __c, size_type __pos=npos) const noexcept562    {563        return __str_find_last_not_of<value_type, size_type, traits_type, npos>564            (data(), size(), __c, __pos);565    }566 567    _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 _LIBCUDACXX_INLINE_VISIBILITY568    size_type find_last_not_of(const _CharT* __s, size_type __pos, size_type __n) const569    {570        _LIBCUDACXX_ASSERT(__n == 0 || __s != nullptr, "string_view::find_last_not_of(): received nullptr");571        return __str_find_last_not_of<value_type, size_type, traits_type, npos>572            (data(), size(), __s, __pos, __n);573    }574 575    _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 _LIBCUDACXX_INLINE_VISIBILITY576    size_type find_last_not_of(const _CharT* __s, size_type __pos=npos) const577    {578        _LIBCUDACXX_ASSERT(__s != nullptr, "string_view::find_last_not_of(): received nullptr");579        return __str_find_last_not_of<value_type, size_type, traits_type, npos>580            (data(), size(), __s, __pos, traits_type::length(__s));581    }582 583#if _LIBCUDACXX_STD_VER > 17584    _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 _LIBCUDACXX_INLINE_VISIBILITY585    bool starts_with(basic_string_view __s) const noexcept586    { return size() >= __s.size() && compare(0, __s.size(), __s) == 0; }587 588    _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 _LIBCUDACXX_INLINE_VISIBILITY589    bool starts_with(value_type __c) const noexcept590    { return !empty() && _Traits::eq(front(), __c); }591 592    _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 _LIBCUDACXX_INLINE_VISIBILITY593    bool starts_with(const value_type* __s) const noexcept594    { return starts_with(basic_string_view(__s)); }595 596    _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 _LIBCUDACXX_INLINE_VISIBILITY597    bool ends_with(basic_string_view __s) const noexcept598    { return size() >= __s.size() && compare(size() - __s.size(), npos, __s) == 0; }599 600    _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 _LIBCUDACXX_INLINE_VISIBILITY601    bool ends_with(value_type __c) const noexcept602    { return !empty() && _Traits::eq(back(), __c); }603 604    _LIBCUDACXX_CONSTEXPR_AFTER_CXX11 _LIBCUDACXX_INLINE_VISIBILITY605    bool ends_with(const value_type* __s) const noexcept606    { return ends_with(basic_string_view(__s)); }607#endif608 609private:610    const   value_type* __data;611    size_type           __size;612};613 614 615// [string.view.comparison]616// operator ==617template<class _CharT, class _Traits>618_LIBCUDACXX_CONSTEXPR_AFTER_CXX11 _LIBCUDACXX_INLINE_VISIBILITY619bool operator==(basic_string_view<_CharT, _Traits> __lhs,620                basic_string_view<_CharT, _Traits> __rhs) noexcept621{622    if ( __lhs.size() != __rhs.size()) return false;623    return __lhs.compare(__rhs) == 0;624}625 626template<class _CharT, class _Traits>627_LIBCUDACXX_CONSTEXPR_AFTER_CXX11 _LIBCUDACXX_INLINE_VISIBILITY628bool operator==(basic_string_view<_CharT, _Traits> __lhs,629                typename common_type<basic_string_view<_CharT, _Traits> >::type __rhs) noexcept630{631    if ( __lhs.size() != __rhs.size()) return false;632    return __lhs.compare(__rhs) == 0;633}634 635template<class _CharT, class _Traits>636_LIBCUDACXX_CONSTEXPR_AFTER_CXX11 _LIBCUDACXX_INLINE_VISIBILITY637bool operator==(typename common_type<basic_string_view<_CharT, _Traits> >::type __lhs,638                basic_string_view<_CharT, _Traits> __rhs) noexcept639{640    if ( __lhs.size() != __rhs.size()) return false;641    return __lhs.compare(__rhs) == 0;642}643 644 645// operator !=646template<class _CharT, class _Traits>647_LIBCUDACXX_CONSTEXPR_AFTER_CXX11 _LIBCUDACXX_INLINE_VISIBILITY648bool operator!=(basic_string_view<_CharT, _Traits> __lhs, basic_string_view<_CharT, _Traits> __rhs) noexcept649{650    if ( __lhs.size() != __rhs.size())651        return true;652    return __lhs.compare(__rhs) != 0;653}654 655template<class _CharT, class _Traits>656_LIBCUDACXX_CONSTEXPR_AFTER_CXX11 _LIBCUDACXX_INLINE_VISIBILITY657bool operator!=(basic_string_view<_CharT, _Traits> __lhs,658                typename common_type<basic_string_view<_CharT, _Traits> >::type __rhs) noexcept659{660    if ( __lhs.size() != __rhs.size())661        return true;662    return __lhs.compare(__rhs) != 0;663}664 665template<class _CharT, class _Traits>666_LIBCUDACXX_CONSTEXPR_AFTER_CXX11 _LIBCUDACXX_INLINE_VISIBILITY667bool operator!=(typename common_type<basic_string_view<_CharT, _Traits> >::type __lhs,668                basic_string_view<_CharT, _Traits> __rhs) noexcept669{670    if ( __lhs.size() != __rhs.size())671        return true;672    return __lhs.compare(__rhs) != 0;673}674 675 676// operator <677template<class _CharT, class _Traits>678_LIBCUDACXX_CONSTEXPR_AFTER_CXX11 _LIBCUDACXX_INLINE_VISIBILITY679bool operator<(basic_string_view<_CharT, _Traits> __lhs, basic_string_view<_CharT, _Traits> __rhs) noexcept680{681    return __lhs.compare(__rhs) < 0;682}683 684template<class _CharT, class _Traits>685_LIBCUDACXX_CONSTEXPR_AFTER_CXX11 _LIBCUDACXX_INLINE_VISIBILITY686bool operator<(basic_string_view<_CharT, _Traits> __lhs,687                typename common_type<basic_string_view<_CharT, _Traits> >::type __rhs) noexcept688{689    return __lhs.compare(__rhs) < 0;690}691 692template<class _CharT, class _Traits>693_LIBCUDACXX_CONSTEXPR_AFTER_CXX11 _LIBCUDACXX_INLINE_VISIBILITY694bool operator<(typename common_type<basic_string_view<_CharT, _Traits> >::type __lhs,695                basic_string_view<_CharT, _Traits> __rhs) noexcept696{697    return __lhs.compare(__rhs) < 0;698}699 700 701// operator >702template<class _CharT, class _Traits>703_LIBCUDACXX_CONSTEXPR_AFTER_CXX11 _LIBCUDACXX_INLINE_VISIBILITY704bool operator> (basic_string_view<_CharT, _Traits> __lhs, basic_string_view<_CharT, _Traits> __rhs) noexcept705{706    return __lhs.compare(__rhs) > 0;707}708 709template<class _CharT, class _Traits>710_LIBCUDACXX_CONSTEXPR_AFTER_CXX11 _LIBCUDACXX_INLINE_VISIBILITY711bool operator>(basic_string_view<_CharT, _Traits> __lhs,712                typename common_type<basic_string_view<_CharT, _Traits> >::type __rhs) noexcept713{714    return __lhs.compare(__rhs) > 0;715}716 717template<class _CharT, class _Traits>718_LIBCUDACXX_CONSTEXPR_AFTER_CXX11 _LIBCUDACXX_INLINE_VISIBILITY719bool operator>(typename common_type<basic_string_view<_CharT, _Traits> >::type __lhs,720                basic_string_view<_CharT, _Traits> __rhs) noexcept721{722    return __lhs.compare(__rhs) > 0;723}724 725 726// operator <=727template<class _CharT, class _Traits>728_LIBCUDACXX_CONSTEXPR_AFTER_CXX11 _LIBCUDACXX_INLINE_VISIBILITY729bool operator<=(basic_string_view<_CharT, _Traits> __lhs, basic_string_view<_CharT, _Traits> __rhs) noexcept730{731    return __lhs.compare(__rhs) <= 0;732}733 734template<class _CharT, class _Traits>735_LIBCUDACXX_CONSTEXPR_AFTER_CXX11 _LIBCUDACXX_INLINE_VISIBILITY736bool operator<=(basic_string_view<_CharT, _Traits> __lhs,737                typename common_type<basic_string_view<_CharT, _Traits> >::type __rhs) noexcept738{739    return __lhs.compare(__rhs) <= 0;740}741 742template<class _CharT, class _Traits>743_LIBCUDACXX_CONSTEXPR_AFTER_CXX11 _LIBCUDACXX_INLINE_VISIBILITY744bool operator<=(typename common_type<basic_string_view<_CharT, _Traits> >::type __lhs,745                basic_string_view<_CharT, _Traits> __rhs) noexcept746{747    return __lhs.compare(__rhs) <= 0;748}749 750 751// operator >=752template<class _CharT, class _Traits>753_LIBCUDACXX_CONSTEXPR_AFTER_CXX11 _LIBCUDACXX_INLINE_VISIBILITY754bool operator>=(basic_string_view<_CharT, _Traits> __lhs, basic_string_view<_CharT, _Traits> __rhs) noexcept755{756    return __lhs.compare(__rhs) >= 0;757}758 759 760template<class _CharT, class _Traits>761_LIBCUDACXX_CONSTEXPR_AFTER_CXX11 _LIBCUDACXX_INLINE_VISIBILITY762bool operator>=(basic_string_view<_CharT, _Traits> __lhs,763                typename common_type<basic_string_view<_CharT, _Traits> >::type __rhs) noexcept764{765    return __lhs.compare(__rhs) >= 0;766}767 768template<class _CharT, class _Traits>769_LIBCUDACXX_CONSTEXPR_AFTER_CXX11 _LIBCUDACXX_INLINE_VISIBILITY770bool operator>=(typename common_type<basic_string_view<_CharT, _Traits> >::type __lhs,771                basic_string_view<_CharT, _Traits> __rhs) noexcept772{773    return __lhs.compare(__rhs) >= 0;774}775 776 777template<class _CharT, class _Traits>778basic_ostream<_CharT, _Traits>&779operator<<(basic_ostream<_CharT, _Traits>& __os,780           basic_string_view<_CharT, _Traits> __str);781 782typedef basic_string_view<char>     string_view;783#ifndef _LIBCUDACXX_NO_HAS_CHAR8_T784typedef basic_string_view<char8_t>  u8string_view;785#endif786typedef basic_string_view<char16_t> u16string_view;787typedef basic_string_view<char32_t> u32string_view;788typedef basic_string_view<wchar_t>  wstring_view;789 790// [string.view.hash]791template<class _CharT>792struct _LIBCUDACXX_TEMPLATE_VIS hash<basic_string_view<_CharT, char_traits<_CharT> > >793    : public __unary_function<basic_string_view<_CharT, char_traits<_CharT> >, size_t>794{795    _LIBCUDACXX_INLINE_VISIBILITY796    size_t operator()(const basic_string_view<_CharT, char_traits<_CharT> > __val) const noexcept {797        return __do_string_hash(__val.data(), __val.data() + __val.size());798    }799};800 801 802#if _LIBCUDACXX_STD_VER > 11803inline namespace literals804{805  inline namespace string_view_literals806  {807    inline _LIBCUDACXX_INLINE_VISIBILITY constexpr808    basic_string_view<char> operator "" sv(const char *__str, size_t __len) noexcept809    {810        return basic_string_view<char> (__str, __len);811    }812 813    inline _LIBCUDACXX_INLINE_VISIBILITY constexpr814    basic_string_view<wchar_t> operator "" sv(const wchar_t *__str, size_t __len) noexcept815    {816        return basic_string_view<wchar_t> (__str, __len);817    }818 819#ifndef _LIBCUDACXX_NO_HAS_CHAR8_T820    inline _LIBCUDACXX_INLINE_VISIBILITY constexpr821    basic_string_view<char8_t> operator "" sv(const char8_t *__str, size_t __len) noexcept822    {823        return basic_string_view<char8_t> (__str, __len);824    }825#endif826 827    inline _LIBCUDACXX_INLINE_VISIBILITY constexpr828    basic_string_view<char16_t> operator "" sv(const char16_t *__str, size_t __len) noexcept829    {830        return basic_string_view<char16_t> (__str, __len);831    }832 833    inline _LIBCUDACXX_INLINE_VISIBILITY constexpr834    basic_string_view<char32_t> operator "" sv(const char32_t *__str, size_t __len) noexcept835    {836        return basic_string_view<char32_t> (__str, __len);837    }838  }839}840#endif841_LIBCUDACXX_END_NAMESPACE_STD842 843_LIBCUDACXX_POP_MACROS844 845#endif // _LIBCUDACXX_STRING_VIEW846 
codekingpro/portable-devtools · Team Ai