Changeset 53e8686 in mainline


Ignore:
Timestamp:
2018-07-05T21:41:18Z (6 years ago)
Author:
Dzejrou <dzejrou@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
173a246
Parents:
d466d284
git-author:
Jaroslav Jindrak <dzejrou@…> (2017-11-01 20:30:32)
git-committer:
Dzejrou <dzejrou@…> (2018-07-05 21:41:18)
Message:

cpp: minor refactoring, fixed some bugs found by the replace tests

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/cpp/include/impl/string.hpp

    rd466d284 r53e8686  
    339339                data_ = allocator_.allocate(capacity_);
    340340                for (size_type i = 0; i < size_; ++i)
    341                     traits_type::asign(data_[i], c);
     341                    traits_type::assign(data_[i], c);
    342342                ensure_null_terminator_();
    343343            }
     
    888888                                  size_type n2)
    889889            {
    890                 // TODO: format and comment this properly
    891890                // TODO: throw out_of_range if pos > size()
     891                // TODO: if size() - len > max_size() - n2 throw length_error
    892892                auto len = min(n1, size_ - pos);
    893                 // TODO: if size() - len > max_size() - n2 throw length_error
     893
    894894                basic_string tmp{};
    895895                tmp.resize_without_copy_(size_ - len + n2);
     896
     897                // Prefix.
    896898                copy_(begin(), begin() + pos, tmp.begin());
    897                 traits_type::copy(tmp.begin() + pos + 1, str, n2);
    898                 copy_(begin() + pos + len, end(), tmp.begin() + pos + 1 + n2);
     899
     900                // Substitution.
     901                traits_type::copy(tmp.begin() + pos, str, n2);
     902
     903                // Suffix.
     904                copy_(begin() + pos + len, end(), tmp.begin() + pos + n2);
     905
     906                tmp.size_ = size_ - len + n2;
    899907                swap(tmp);
    900908                return *this;
     
    960968            void swap(basic_string& other)
    961969                noexcept(allocator_traits<allocator_type>::propagate_on_container_swap::value ||
    962                          allocator_traits<allocator_type>::is_always_equal)
     970                         allocator_traits<allocator_type>::is_always_equal::value)
    963971            {
    964972                std::swap(data_, other.data_);
Note: See TracChangeset for help on using the changeset viewer.