📄 basic_string.h
字号:
{ return const_iterator(_M_data()); } iterator end() { _M_leak(); return iterator(_M_data() + this->size()); } const_iterator end() const { return const_iterator(_M_data() + this->size()); } reverse_iterator rbegin() { return reverse_iterator(this->end()); } const_reverse_iterator rbegin() const { return const_reverse_iterator(this->end()); } reverse_iterator rend() { return reverse_iterator(this->begin()); } const_reverse_iterator rend() const { return const_reverse_iterator(this->begin()); } public: // Capacity: size_type size() const { return _M_rep()->_M_length; } size_type length() const { return _M_rep()->_M_length; } size_type max_size() const { return _Rep::_S_max_size; } void resize(size_type __n, _CharT __c); void resize(size_type __n) { this->resize(__n, _CharT()); } size_type capacity() const { return _M_rep()->_M_capacity; } void reserve(size_type __res_arg = 0); void clear() { _M_mutate(0, this->size(), 0); } bool empty() const { return this->size() == 0; } // Element access: const_reference operator[] (size_type __pos) const { return _M_data()[__pos]; } reference operator[](size_type __pos) { _M_leak(); return _M_data()[__pos]; } const_reference at(size_type __n) const { __OUTOFRANGE(__n >= this->size()); return _M_data()[__n]; } reference at(size_type __n) { __OUTOFRANGE(__n >= size()); _M_leak(); return _M_data()[__n]; } // Modifiers: basic_string& operator+=(const basic_string& __str) { return this->append(__str); } basic_string& operator+=(const _CharT* __s) { return this->append(__s); } basic_string& operator+=(_CharT __c) { return this->append(size_type(1), __c); } basic_string& append(const basic_string& __str) { // Iff appending itself, string needs to pre-reserve the // correct size so that _M_mutate does not clobber the // iterators formed here. size_type __size = __str.size(); size_type __len = __size + this->size(); if (__len > this->capacity()) this->reserve(__len); return this->replace(_M_iend(), _M_iend(), __str._M_ibegin(), __str._M_iend()); } basic_string& append(const basic_string& __str, size_type __pos, size_type __n) { // Iff appending itself, string needs to pre-reserve the // correct size so that _M_mutate does not clobber the // iterators formed here. size_type __len = min(__str.size() - __pos, __n) + this->size(); if (__len > this->capacity()) this->reserve(__len); return this->replace(_M_iend(), _M_iend(), __str._M_check(__pos), __str._M_fold(__pos, __n)); } basic_string& append(const _CharT* __s, size_type __n) { size_type __size = min(traits_type::length(__s), __n); size_type __len = __size + this->size(); if (__len > this->capacity()) this->reserve(__len); return this->replace(_M_iend(), _M_iend(), __s, __s + __size); } basic_string& append(const _CharT* __s) { return this->append(__s, traits_type::length(__s)); } basic_string& append(size_type __n, _CharT __c) { size_type __len = __n + this->size(); if (__len > this->capacity()) this->reserve(__len); return this->replace(_M_iend(), _M_iend(), __n, __c); } template<class _InputIterator> basic_string& append(_InputIterator __first, _InputIterator __last) { return this->replace(_M_iend(), _M_iend(), __first, __last); } void push_back(_CharT __c) { this->replace(_M_iend(), _M_iend(), 1, __c); } basic_string& assign(const basic_string& __str); basic_string& assign(const basic_string& __str, size_type __pos, size_type __n) { return this->assign(__str._M_check(__pos), __str._M_fold(__pos, __n)); } basic_string& assign(const _CharT* __s, size_type __n) { return this->assign(__s, __s + __n); } basic_string& assign(const _CharT* __s) { return this->assign(__s, __s + traits_type::length(__s)); } basic_string& assign(size_type __n, _CharT __c) { return this->replace(_M_ibegin(), _M_iend(), __n, __c); } template<class _InputIterator> basic_string& assign(_InputIterator __first, _InputIterator __last) { return this->replace(_M_ibegin(), _M_iend(), __first, __last); } void insert(iterator __p, size_type __n, _CharT __c) { this->replace(__p, __p, __n, __c); } template<class _InputIterator> void insert(iterator __p, _InputIterator __beg, _InputIterator __end) { this->replace(__p, __p, __beg, __end); } basic_string& insert(size_type __pos1, const basic_string& __str) { iterator __p = _M_check(__pos1); this->replace(__p, __p, __str._M_ibegin(), __str._M_iend()); return *this; } basic_string& insert(size_type __pos1, const basic_string& __str, size_type __pos2, size_type __n) { iterator __p = _M_check(__pos1); this->replace(__p, __p, __str._M_check(__pos2), __str._M_fold(__pos2, __n)); return *this; } basic_string& insert(size_type __pos, const _CharT* __s, size_type __n) { iterator __p = _M_check(__pos); this->replace(__p, __p, __s, __s + __n); return *this; } basic_string& insert(size_type __pos, const _CharT* __s) { return this->insert(__pos, __s, traits_type::length(__s)); } basic_string& insert(size_type __pos, size_type __n, _CharT __c) { this->insert(_M_check(__pos), __n, __c); return *this; } iterator insert(iterator __p, _CharT __c = _CharT()) { size_type __pos = __p - _M_ibegin(); this->insert(_M_check(__pos), size_type(1), __c); _M_rep()->_M_state = -1; return this->_M_ibegin() + __pos; } basic_string& erase(size_type __pos = 0, size_type __n = npos) { return this->replace(_M_check(__pos), _M_fold(__pos, __n), _M_data(), _M_data()); } iterator erase(iterator __position) { size_type __i = __position - _M_ibegin(); this->replace(__position, __position + 1, _M_data(), _M_data()); _M_rep()->_M_state = -1; return _M_ibegin() + __i; } iterator erase(iterator __first, iterator __last) { size_type __i = __first - _M_ibegin(); this->replace(__first, __last, _M_data(), _M_data()); _M_rep()->_M_state = -1; return _M_ibegin() + __i; } basic_string& replace(size_type __pos, size_type __n, const basic_string& __str) { return this->replace(_M_check(__pos), _M_fold(__pos, __n), __str.begin(), __str.end()); } basic_string& replace(size_type __pos1, size_type __n1, const basic_string& __str, size_type __pos2, size_type __n2); basic_string& replace(size_type __pos, size_type __n1, const _CharT* __s, size_type __n2) { return this->replace(_M_check(__pos), _M_fold(__pos, __n1), __s, __s + __n2); } basic_string& replace(size_type __pos, size_type __n1, const _CharT* __s) { return this->replace(_M_check(__pos), _M_fold(__pos, __n1), __s, __s + traits_type::length(__s)); } basic_string& replace(size_type __pos, size_type __n1, size_type __n2, _CharT __c) { return this->replace(_M_check(__pos), _M_fold(__pos, __n1), __n2, __c); } basic_string& replace(iterator __i1, iterator __i2, const basic_string& __str) { return this->replace(__i1, __i2, __str.begin(), __str.end()); } basic_string& replace(iterator __i1, iterator __i2, const _CharT* __s, size_type __n) { return this->replace(__i1, __i2, __s, __s + __n); } basic_string& replace(iterator __i1, iterator __i2, const _CharT* __s) { return this->replace(__i1, __i2, __s, __s + traits_type::length(__s)); } basic_string& replace(iterator __i1, iterator __i2, size_type __n, _CharT __c); template<class _InputIterator> basic_string& replace(iterator __i1, iterator __i2, _InputIterator __j1, _InputIterator __j2) { return _M_replace(__i1, __i2, __j1, __j2, typename iterator_traits<_InputIterator>::iterator_category()); } private: template<class _InputIterator> basic_string& _M_replace(iterator __i1, iterator __i2, _InputIterator __j1, _InputIterator __j2, input_iterator_tag); template<class _FwdIterator> basic_string& _M_replace(iterator __i1, iterator __i2, _FwdIterator __j1, _FwdIterator __j2, forward_iterator_tag); template<class _InIter> static _CharT* _S_construct(_InIter __beg, _InIter __end, const _Alloc& __a) { typedef typename iterator_traits<_InIter>::iterator_category _Tag; return _S_construct(__beg, __end, __a, _Tag()); } // For Input Iterators, used in istreambuf_iterators, etc. template<class _InIter> static _CharT* _S_construct(_InIter __beg, _InIter __end, const _Alloc& __a, input_iterator_tag); // For forward_iterators up to random_access_iterators, used for // string::iterator, _CharT*, etc. template<class _FwdIter> static _CharT* _S_construct(_FwdIter __end, _FwdIter __beg, const _Alloc& __a, forward_iterator_tag); static _CharT* _S_construct(size_type __req, _CharT __c, const _Alloc& __a); public: size_type copy(_CharT* __s, size_type __n, size_type __pos = 0) const;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -