Changeset ed81b1f in mainline
- Timestamp:
- 2018-07-05T21:41:18Z (7 years ago)
- 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)
- Location:
- uspace/lib/cpp
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/cpp/include/impl/string.hpp
r2d302d6 red81b1f 331 331 : data_{}, size_{}, capacity_{}, allocator_{alloc} 332 332 { 333 init_(str, traits_type::length(str) + 1);333 init_(str, traits_type::length(str)); 334 334 } 335 335 … … 361 361 { 362 362 auto len = static_cast<size_type>(last - first); 363 init_( static_cast<value_type*>(first), len);363 init_(first, len); 364 364 } 365 365 } … … 501 501 size_type length() const noexcept 502 502 { 503 return size _;503 return size(); 504 504 } 505 505 … … 652 652 // TODO: if (size_ + n > max_size()) throw length_error 653 653 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; 656 656 ensure_null_terminator_(); 657 657 … … 661 661 basic_string& append(const value_type* str) 662 662 { 663 return append(str, traits_type::length(str) + 1);663 return append(str, traits_type::length(str)); 664 664 } 665 665 … … 769 769 770 770 copy_backward_(begin() + pos, end(), end() + n); 771 std::printf("|%s|\n", data_);772 771 copy_(str, str + n, begin() + pos); 773 772 size_ += n; -
uspace/lib/cpp/src/internal/test/string.cpp
r2d302d6 red81b1f 55 55 test_eq( 56 56 "size of string", 57 str1.size(), 6ul57 str1.size(), 5ul 58 58 ); 59 59 test_eq( 60 60 "initialization from a cstring literal", 61 61 str1.begin(), str1.end(), 62 check1, check1 + 662 check1, check1 + 5 63 63 ); 64 64 … … 140 140 141 141 std::string str5{"hello, "}; 142 str5.append({'w', 'o', 'r', 'l', 'd' , '\0'});142 str5.append({'w', 'o', 'r', 'l', 'd'}); 143 143 test_eq( 144 144 "append initializer list", … … 187 187 std::string insertee{"ello"}; 188 188 str4.insert(str4.begin() + 1, insertee.begin(), 189 insertee.end() - 1);189 insertee.end()); 190 190 test_eq( 191 191 "insert iterator range", … … 193 193 check.begin(), check.end() 194 194 ); 195 /* std::printf("|%s|\n", str4.c_str()); */ 195 196 std::string str5{"hel, world"}; 197 std::initializer_list<char> init{'l', 'o'}; 198 str5.insert(str5.begin() + 3, init); 199 test_eq( 200 "insert initializer list", 201 str5.begin(), str5.end(), 202 check.begin(), check.end() 203 ); 196 204 } 197 205 }
Note:
See TracChangeset
for help on using the changeset viewer.