| 1 |
#ifndef _STRING_ |
| 2 |
#define _STRING_ |
| 3 |
|
| 4 |
// For size_t |
| 5 |
#include <string.h> |
| 6 |
|
| 7 |
typedef unsigned __INT16_TYPE__ char16; |
| 8 |
typedef unsigned __INT32_TYPE__ char32; |
| 9 |
|
| 10 |
namespace std { |
| 11 |
template <typename T> |
| 12 |
class allocator {}; |
| 13 |
|
| 14 |
template <typename T> |
| 15 |
class char_traits {}; |
| 16 |
|
| 17 |
template <typename C, typename T = char_traits<C>> |
| 18 |
struct basic_string_view; |
| 19 |
|
| 20 |
template <typename C, typename T = char_traits<C>, typename A = allocator<C>> |
| 21 |
struct basic_string { |
| 22 |
typedef size_t size_type; |
| 23 |
typedef basic_string<C, T, A> _Type; |
| 24 |
basic_string(); |
| 25 |
basic_string(const C *p, const A &a = A()); |
| 26 |
basic_string(const C *p, size_type count); |
| 27 |
basic_string(const C *b, const C *e); |
| 28 |
|
| 29 |
~basic_string(); |
| 30 |
|
| 31 |
const C *c_str() const; |
| 32 |
const C *data() const; |
| 33 |
|
| 34 |
bool empty() const; |
| 35 |
size_type size() const; |
| 36 |
size_type length() const; |
| 37 |
|
| 38 |
_Type& append(const C *s); |
| 39 |
_Type& append(const C *s, size_type n); |
| 40 |
_Type& assign(const C *s); |
| 41 |
_Type& assign(const C *s, size_type n); |
| 42 |
|
| 43 |
int compare(const _Type&) const; |
| 44 |
int compare(const C* s) const; |
| 45 |
int compare(size_type pos, size_type len, const _Type&) const; |
| 46 |
int compare(size_type pos, size_type len, const C* s) const; |
| 47 |
template<class StringViewLike> |
| 48 |
int compare(size_type pos1, size_type count1, const StringViewLike& t) const; |
| 49 |
|
| 50 |
size_type find(const _Type& str, size_type pos = 0) const; |
| 51 |
size_type find(const C* s, size_type pos = 0) const; |
| 52 |
size_type find(const C* s, size_type pos, size_type n) const; |
| 53 |
|
| 54 |
size_type rfind(const _Type& str, size_type pos = npos) const; |
| 55 |
size_type rfind(const C* s, size_type pos, size_type count) const; |
| 56 |
size_type rfind(const C* s, size_type pos = npos) const; |
| 57 |
size_type rfind(C ch, size_type pos = npos) const; |
| 58 |
|
| 59 |
_Type& insert(size_type pos, const _Type& str); |
| 60 |
_Type& insert(size_type pos, const C* s); |
| 61 |
_Type& insert(size_type pos, const C* s, size_type n); |
| 62 |
|
| 63 |
constexpr bool starts_with(std::basic_string_view<C, T> sv) const noexcept; |
| 64 |
constexpr bool starts_with(C ch) const noexcept; |
| 65 |
constexpr bool starts_with(const C* s) const; |
| 66 |
|
| 67 |
_Type& operator[](size_type); |
| 68 |
const _Type& operator[](size_type) const; |
| 69 |
|
| 70 |
_Type& operator+=(const _Type& str); |
| 71 |
_Type& operator+=(const C* s); |
| 72 |
_Type& operator=(const _Type& str); |
| 73 |
_Type& operator=(const C* s); |
| 74 |
|
| 75 |
static constexpr size_t npos = -1; |
| 76 |
}; |
| 77 |
|
| 78 |
typedef basic_string<char> string; |
| 79 |
typedef basic_string<wchar_t> wstring; |
| 80 |
typedef basic_string<char16> u16string; |
| 81 |
typedef basic_string<char32> u32string; |
| 82 |
|
| 83 |
template <typename C, typename T> |
| 84 |
struct basic_string_view { |
| 85 |
typedef size_t size_type; |
| 86 |
typedef basic_string_view<C, T> _Type; |
| 87 |
|
| 88 |
const C *str; |
| 89 |
constexpr basic_string_view(const C* s) : str(s) {} |
| 90 |
|
| 91 |
const C *data() const; |
| 92 |
|
| 93 |
bool empty() const; |
| 94 |
size_type size() const; |
| 95 |
size_type length() const; |
| 96 |
|
| 97 |
size_type find(_Type v, size_type pos = 0) const; |
| 98 |
size_type find(C ch, size_type pos = 0) const; |
| 99 |
size_type find(const C* s, size_type pos, size_type count) const; |
| 100 |
size_type find(const C* s, size_type pos = 0) const; |
| 101 |
|
| 102 |
size_type rfind(_Type v, size_type pos = npos) const; |
| 103 |
size_type rfind(C ch, size_type pos = npos) const; |
| 104 |
size_type rfind(const C* s, size_type pos, size_type count) const; |
| 105 |
size_type rfind(const C* s, size_type pos = npos) const; |
| 106 |
|
| 107 |
constexpr bool starts_with(basic_string_view sv) const noexcept; |
| 108 |
constexpr bool starts_with(C ch) const noexcept; |
| 109 |
constexpr bool starts_with(const C* s) const; |
| 110 |
|
| 111 |
constexpr int compare(basic_string_view sv) const noexcept; |
| 112 |
|
| 113 |
static constexpr size_t npos = -1; |
| 114 |
}; |
| 115 |
|
| 116 |
typedef basic_string_view<char> string_view; |
| 117 |
typedef basic_string_view<wchar_t> wstring_view; |
| 118 |
typedef basic_string_view<char16> u16string_view; |
| 119 |
typedef basic_string_view<char32> u32string_view; |
| 120 |
|
| 121 |
std::string operator+(const std::string&, const std::string&); |
| 122 |
std::string operator+(const std::string&, const char*); |
| 123 |
std::string operator+(const char*, const std::string&); |
| 124 |
|
| 125 |
bool operator==(const std::string&, const std::string&); |
| 126 |
bool operator==(const std::string&, const char*); |
| 127 |
bool operator==(const char*, const std::string&); |
| 128 |
|
| 129 |
bool operator!=(const std::string&, const std::string&); |
| 130 |
bool operator!=(const std::string&, const char*); |
| 131 |
bool operator!=(const char*, const std::string&); |
| 132 |
|
| 133 |
bool operator==(const std::wstring&, const std::wstring&); |
| 134 |
bool operator==(const std::wstring&, const wchar_t*); |
| 135 |
bool operator==(const wchar_t*, const std::wstring&); |
| 136 |
|
| 137 |
bool operator==(const std::string_view&, const std::string_view&); |
| 138 |
bool operator==(const std::string_view&, const char*); |
| 139 |
bool operator==(const char*, const std::string_view&); |
| 140 |
|
| 141 |
bool operator!=(const std::string_view&, const std::string_view&); |
| 142 |
bool operator!=(const std::string_view&, const char*); |
| 143 |
bool operator!=(const char*, const std::string_view&); |
| 144 |
|
| 145 |
size_t strlen(const char* str); |
| 146 |
} |
| 147 |
|
| 148 |
#endif // _STRING_ |