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

cpp: finished std::string::insert tests and fixed some problems with length and other bugs revealed by the tests

File:
1 edited

Legend:

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

    r2d302d6 red81b1f  
    331331                : data_{}, size_{}, capacity_{}, allocator_{alloc}
    332332            {
    333                 init_(str, traits_type::length(str) + 1);
     333                init_(str, traits_type::length(str));
    334334            }
    335335
     
    361361                {
    362362                    auto len = static_cast<size_type>(last - first);
    363                     init_(static_cast<value_type*>(first), len);
     363                    init_(first, len);
    364364                }
    365365            }
     
    501501            size_type length() const noexcept
    502502            {
    503                 return size_;
     503                return size();
    504504            }
    505505
     
    652652                // TODO: if (size_ + n > max_size()) throw length_error
    653653                ensure_free_space_(n);
    654                 traits_type::copy(data_ + size_ - 1, str, n);
    655                 size_ += n - 1; // We are not copying str's null terminator.
     654                traits_type::copy(data_ + size(), str, n);
     655                size_ += n;
    656656                ensure_null_terminator_();
    657657
     
    661661            basic_string& append(const value_type* str)
    662662            {
    663                 return append(str, traits_type::length(str) + 1);
     663                return append(str, traits_type::length(str));
    664664            }
    665665
     
    769769
    770770                copy_backward_(begin() + pos, end(), end() + n);
    771                 std::printf("|%s|\n", data_);
    772771                copy_(str, str + n, begin() + pos);
    773772                size_ += n;
Note: See TracChangeset for help on using the changeset viewer.