WWW.DISSERS.RU

БЕСПЛАТНАЯ ЭЛЕКТРОННАЯ БИБЛИОТЕКА

   Добро пожаловать!


Pages:     | 1 |   ...   | 12 | 13 || 15 | 16 |

const size_type len1 = min(n1, size() - pos1);

const size_type len2 = min(n2, s.size() - pos2);

if (size() - len1 >= max_size() - len2) _M_throw_length_error();

return replace(_M_start + pos1, _M_start + pos1 + len1, s._M_start + pos2, s._M_start + pos2 + len2);

} basic_string& replace(size_type pos, size_type n1, const _CharT* s, size_type n2) { if (pos > size()) _M_throw_out_of_range();

const size_type len = min(n1, size() - pos);

if (n2 > max_size() || size() - len >= max_size() - n2) _M_throw_length_error();

return replace(_M_start + pos, _M_start + pos + len, s, s + n2);

} basic_string& replace(size_type pos, size_type n1, const _CharT* s) { if (pos > size()) _M_throw_out_of_range();

const size_type len = min(n1, size() - pos);

const size_type n2 = _Traits::length(s);

if (n2 > max_size() || size() - len >= max_size() - n2) _M_throw_length_error();

return replace(_M_start + pos, _M_start + pos + len, s, s + _Traits::length(s));

} basic_string& replace(size_type pos, size_type n1, size_type n2, _CharT c) { if (pos > size()) _M_throw_out_of_range();

const size_type len = min(n1, size() - pos);

if (n2 > max_size() || size() - len >= max_size() - n2) _M_throw_length_error();

return replace(_M_start + pos, _M_start + pos + len, n2, c);

} basic_string& replace(iterator first, iterator last, const basic_string& s) { return replace(first, last, s.begin(), s.end()); } - 108 - УМП «Автоматизированные методы разработки архитектуры ПО» basic_string& replace(iterator first, iterator last, const _CharT* s, size_type n) { return replace(first, last, s, s + n); } basic_string& replace(iterator first, iterator last, const _CharT* s) { return replace(first, last, s, s + _Traits::length(s));

} basic_string& replace(iterator first, iterator last, size_type n, _CharT c);

// Check to see if _InputIterator is an integer type. If so, then // it can't be an iterator.

#ifdef STL_MEMBER_TEMPLATES template basic_string& replace(iterator first, iterator last, _InputIter f, _InputIter l) { typedef typename _Is_integer<_InputIter>::_Integral _Integral;

return _M_replace_dispatch(first, last, f, l, _Integral());

} #else /* STL_MEMBER_TEMPLATES */ basic_string& replace(iterator first, iterator last, const _CharT* f, const _CharT* l);

#endif /* STL_MEMBER_TEMPLATES */ private: // Helper functions for replace.

#ifdef STL_MEMBER_TEMPLATES template basic_string& _M_replace_dispatch(iterator first, iterator last, _Integer n, _Integer x, true_type) { return replace(first, last, (size_type) n, (_CharT) x);

} template basic_string& _M_replace_dispatch(iterator first, iterator last, _InputIter f, _InputIter l, false_type) { typedef typename iterator_traits<_InputIter>::iterator_category _Category;

return replace(first, last, f, l, _Category());

} template basic_string& replace(iterator first, iterator last, _InputIter f, _InputIter l, input_iterator_tag);

template basic_string& replace(iterator first, iterator last, _ForwardIter f, _ForwardIter l, forward_iterator_tag);

#endif /* STL_MEMBER_TEMPLATES */ public: // Other modifier member functions.

size_type copy(_CharT* s, size_type n, size_type pos = 0) const { if (pos > size()) _M_throw_out_of_range();

const size_type len = min(n, size() - pos);

_Traits::copy(s, _M_start + pos, len);

return len;

} void swap(basic_string& s) { STD::swap(_M_start, s._M_start);

STD::swap(_M_finish, s._M_finish);

STD::swap(_M_end_of_storage, s._M_end_of_storage);

} public: // Conversion to C string.

const _CharT* c_str() const { return _M_start; } const _CharT* data() const { return _M_start; } public: // find.

- 109 - УМП «Автоматизированные методы разработки архитектуры ПО» size_type find(const basic_string& s, size_type pos = 0) const { return find(s.begin(), pos, s.size()); } size_type find(const _CharT* s, size_type pos = 0) const { return find(s, pos, _Traits::length(s)); } size_type find(const _CharT* s, size_type pos, size_type n) const;

size_type find(_CharT c, size_type pos = 0) const;

public: // rfind.

size_type rfind(const basic_string& s, size_type pos = npos) const { return rfind(s.begin(), pos, s.size()); } size_type rfind(const _CharT* s, size_type pos = npos) const { return rfind(s, pos, _Traits::length(s)); } size_type rfind(const _CharT* s, size_type pos, size_type n) const;

size_type rfind(_CharT c, size_type pos = npos) const;

public: // find_first_of size_type find_first_of(const basic_string& s, size_type pos = 0) const { return find_first_of(s.begin(), pos, s.size()); } size_type find_first_of(const _CharT* s, size_type pos = 0) const { return find_first_of(s, pos, _Traits::length(s)); } size_type find_first_of(const _CharT* s, size_type pos, size_type n) const;

size_type find_first_of(_CharT c, size_type pos = 0) const { return find(c, pos); } public: // find_last_of size_type find_last_of(const basic_string& s, size_type pos = npos) const { return find_last_of(s.begin(), pos, s.size()); } size_type find_last_of(const _CharT* s, size_type pos = npos) const { return find_last_of(s, pos, _Traits::length(s)); } size_type find_last_of(const _CharT* s, size_type pos, size_type n) const;

size_type find_last_of(_CharT c, size_type pos = npos) const { return rfind(c, pos);

} public: // find_first_not_of size_type find_first_not_of(const basic_string& s, size_type pos = 0) const { return find_first_not_of(s.begin(), pos, s.size()); } size_type find_first_not_of(const _CharT* s, size_type pos = 0) const { return find_first_not_of(s, pos, _Traits::length(s)); } size_type find_first_not_of(const _CharT* s, size_type pos, size_type n) const;

size_type find_first_not_of(_CharT c, size_type pos = 0) const;

public: // find_last_not_of size_type find_last_not_of(const basic_string& s, size_type pos = npos) const { return find_last_not_of(s.begin(), pos, s.size()); } size_type find_last_not_of(const _CharT* s, size_type pos = npos) const { return find_last_not_of(s, pos, _Traits::length(s)); } size_type find_last_not_of(const _CharT* s, size_type pos, size_type n) const;

size_type find_last_not_of(_CharT c, size_type pos = npos) const;

public: // Substring.

- 110 - УМП «Автоматизированные методы разработки архитектуры ПО» basic_string substr(size_type pos = 0, size_type n = npos) const { if (pos > size()) _M_throw_out_of_range();

return basic_string(_M_start + pos, _M_start + pos + min(n, size() - pos));

} public: // Compare int compare(const basic_string& s) const { return _M_compare(_M_start, _M_finish, s._M_start, s._M_finish); } int compare(size_type pos1, size_type n1, const basic_string& s) const { if (pos1 > size()) _M_throw_out_of_range();

return _M_compare(_M_start + pos1, _M_start + pos1 + min(n1, size() - pos1), s._M_start, s._M_finish);

} int compare(size_type pos1, size_type n1, const basic_string& s, size_type pos2, size_type n2) const { if (pos1 > size() || pos2 > s.size()) _M_throw_out_of_range();

return _M_compare(_M_start + pos1, _M_start + pos1 + min(n1, size() - pos1), s._M_start + pos2, s._M_start + pos2 + min(n2, size() - pos2));

} int compare(const _CharT* s) const { return _M_compare(_M_start, _M_finish, s, s + _Traits::length(s));

} int compare(size_type pos1, size_type n1, const _CharT* s) const { if (pos1 > size()) _M_throw_out_of_range();

return _M_compare(_M_start + pos1, _M_start + pos1 + min(n1, size() - pos1), s, s + _Traits::length(s));

} int compare(size_type pos1, size_type n1, const _CharT* s, size_type n2) const { if (pos1 > size()) _M_throw_out_of_range();

return _M_compare(_M_start + pos1, _M_start + pos1 + min(n1, size() - pos1), s, s + n2);

} public: // Helper function for compare.

static int _M_compare(const _CharT* f1, const _CharT* l1, const _CharT* f2, const _CharT* l2) { const ptrdiff_t n1 = l1 - f1;

const ptrdiff_t n2 = l2 - f2;

const int cmp = _Traits::compare(f1, f2, min(n1, n2));

return cmp != 0 cmp : (n1 < n2 -1 : (n1 > n2 1 : 0));

} };

// ------------------------------------------------------------ // Non-inline declarations.

template const basic_string<_CharT,_Traits,_Alloc>::size_type basic_string<_CharT,_Traits,_Alloc>::npos = (basic_string<_CharT,_Traits,_Alloc>::size_type) -1;

// Change the string's capacity so that it is large enough to hold // at least res_arg elements, plus the terminating null. Note that, // if res_arg < capacity(), this member function may actually decrease // the string's capacity.

template void basic_string<_CharT,_Traits,_Alloc>::reserve(size_type res_arg) { if (res_arg > max_size()) - 111 - УМП «Автоматизированные методы разработки архитектуры ПО» _M_throw_length_error();

size_type n = max(res_arg, size()) + 1;

pointer new_start = _M_allocate(n);

pointer new_finish = new_start;

STL_TRY { new_finish = uninitialized_copy(_M_start, _M_finish, new_start);

_M_construct_null(new_finish);

} STL_UNWIND((destroy(new_start, new_finish), _M_deallocate(new_start, n)));

destroy(_M_start, _M_finish + 1);

_M_deallocate_block();

_M_start = new_start;

_M_finish = new_finish;

_M_end_of_storage = new_start + n;

} template basic_string<_CharT,_Traits,_Alloc>& basic_string<_CharT,_Traits,_Alloc>::append(size_type n, _CharT c) { if (n > max_size() || size() > max_size() - n) _M_throw_length_error();

if (size() + n > capacity()) reserve(size() + max(size(), n));

if (n > 0) { uninitialized_fill_n(_M_finish + 1, n - 1, c);

STL_TRY { _M_construct_null(_M_finish + n);

} STL_UNWIND(destroy(_M_finish + 1, _M_finish + n));

_Traits::assign(*_M_finish, c);

_M_finish += n;

} return *this;

} #ifdef STL_MEMBER_TEMPLATES template template basic_string<_Tp, _Traits, _Alloc>& basic_string<_Tp, _Traits, _Alloc>::append(_InputIterator first, _InputIterator last, input_iterator_tag) { for ( ; first != last ; ++first) push_back(*first);

return *this;

} template template basic_string<_Tp, _Traits, _Alloc>& basic_string<_Tp, _Traits, _Alloc>::append(_ForwardIter first, _ForwardIter last, forward_iterator_tag) { if (first != last) { const size_type old_size = size();

difference_type n = 0;

distance(first, last, n);

if (static_cast(n) > max_size() || old_size > max_size() - static_cast(n)) _M_throw_length_error();

if (old_size + static_cast(n) > capacity()) { const size_type len = old_size + max(old_size, static_cast(n)) + 1;

pointer new_start = _M_allocate(len);

pointer new_finish = new_start;

STL_TRY { new_finish = uninitialized_copy(_M_start, _M_finish, new_start);

new_finish = uninitialized_copy(first, last, new_finish);

_M_construct_null(new_finish);

} STL_UNWIND((destroy(new_start,new_finish), _M_deallocate(new_start,len)));

destroy(_M_start, _M_finish + 1);

_M_deallocate_block();

_M_start = new_start;

- 112 - УМП «Автоматизированные методы разработки архитектуры ПО» _M_finish = new_finish;

_M_end_of_storage = new_start + len;

} else { _ForwardIter f1 = first;

++f1;

uninitialized_copy(f1, last, _M_finish + 1);

STL_TRY { _M_construct_null(_M_finish + n);

} STL_UNWIND(destroy(_M_finish + 1, _M_finish + n));

_Traits::assign(*_M_finish, *first);

_M_finish += n;

} } return *this;

} #else /* STL_MEMBER_TEMPLATES */ template basic_string<_Tp, _Traits, _Alloc>& basic_string<_Tp, _Traits, _Alloc>::append(const _Tp* first, const _Tp* last) { if (first != last) { const size_type old_size = size();

ptrdiff_t n = last - first;

if (n > max_size() || old_size > max_size() - n) _M_throw_length_error();

if (old_size + n > capacity()) { const size_type len = old_size + max(old_size, (size_t) n) + 1;

pointer new_start = _M_allocate(len);

pointer new_finish = new_start;

STL_TRY { new_finish = uninitialized_copy(_M_start, _M_finish, new_start);

new_finish = uninitialized_copy(first, last, new_finish);

_M_construct_null(new_finish);

} STL_UNWIND((destroy(new_start,new_finish), _M_deallocate(new_start,len)));

destroy(_M_start, _M_finish + 1);

_M_deallocate_block();

_M_start = new_start;

_M_finish = new_finish;

_M_end_of_storage = new_start + len;

} else { const _Tp* f1 = first;

++f1;

uninitialized_copy(f1, last, _M_finish + 1);

STL_TRY { _M_construct_null(_M_finish + n);

} STL_UNWIND(destroy(_M_finish + 1, _M_finish + n));

_Traits::assign(*_M_finish, *first);

_M_finish += n;

} } return *this;

} #endif /* STL_MEMBER_TEMPLATES */ template basic_string<_CharT,_Traits,_Alloc>& basic_string<_CharT,_Traits,_Alloc>::assign(size_type n, _CharT c) { if (n <= size()) { _Traits::assign(_M_start, n, c);

erase(_M_start + n, _M_finish);

} else { _Traits::assign(_M_start, size(), c);

append(n - size(), c);

} return *this;

} #ifdef STL_MEMBER_TEMPLATES - 113 - УМП «Автоматизированные методы разработки архитектуры ПО» template template basic_string<_CharT,_Traits,_Alloc>& basic_string<_CharT,_Traits,_Alloc> ::_M_assign_dispatch(_InputIter f, _InputIter l, false_type) { pointer cur = _M_start;

while (f != l && cur != _M_finish) { _Traits::assign(*cur, *f);

++f;

++cur;

} if (f == l) erase(cur, _M_finish);

else append(f, l);

return *this;

} #endif /* STL_MEMBER_TEMPLATES */ template basic_string<_CharT,_Traits,_Alloc>& basic_string<_CharT,_Traits,_Alloc>::assign(const _CharT* f, const _CharT* l) { const ptrdiff_t n = l - f;

if (static_cast(n) <= size()) { _Traits::copy(_M_start, f, n);

erase(_M_start + n, _M_finish);

} else { _Traits::copy(_M_start, f, size());

append(f + size(), l);

} return *this;

} template basic_string<_CharT,_Traits,_Alloc>::iterator basic_string<_CharT,_Traits,_Alloc> ::_M_insert_aux(basic_string<_CharT,_Traits,_Alloc>::iterator p, _CharT c) { iterator new_pos = p;

if (_M_finish + 1 < _M_end_of_storage) { _M_construct_null(_M_finish + 1);

_Traits::move(p + 1, p, _M_finish - p);

_Traits::assign(*p, c);

++_M_finish;

} else { const size_type old_len = size();

const size_type len = old_len + max(old_len, static_cast(1)) + 1;

iterator new_start = _M_allocate(len);

iterator new_finish = new_start;

STL_TRY { new_pos = uninitialized_copy(_M_start, p, new_start);

construct(new_pos, c);

new_finish = new_pos + 1;

new_finish = uninitialized_copy(p, _M_finish, new_finish);

_M_construct_null(new_finish);

} STL_UNWIND((destroy(new_start,new_finish), _M_deallocate(new_start,len)));

destroy(_M_start, _M_finish + 1);

_M_deallocate_block();

_M_start = new_start;

_M_finish = new_finish;

_M_end_of_storage = new_start + len;

} return new_pos;

Pages:     | 1 |   ...   | 12 | 13 || 15 | 16 |






















© 2011 www.dissers.ru - «Бесплатная электронная библиотека»

Материалы этого сайта размещены для ознакомления, все права принадлежат их авторам.
Если Вы не согласны с тем, что Ваш материал размещён на этом сайте, пожалуйста, напишите нам, мы в течении 1-2 рабочих дней удалим его.