|
13 | 13 | #include <limits> |
14 | 14 | #include <stdexcept> |
15 | 15 | #include <string> |
| 16 | +#include <utility> |
16 | 17 |
|
17 | 18 | #if __cpp_lib_string_view |
18 | 19 | #include <string_view> |
@@ -88,6 +89,10 @@ class basic_string_view { |
88 | 89 | constexpr const_reference front() const noexcept; |
89 | 90 | constexpr const_reference back() const noexcept; |
90 | 91 |
|
| 92 | + void remove_prefix(size_type n); |
| 93 | + void remove_suffix(size_type n); |
| 94 | + void swap(basic_string_view &v) noexcept; |
| 95 | + |
91 | 96 | int compare(const basic_string_view &other) const noexcept; |
92 | 97 |
|
93 | 98 | private: |
@@ -320,6 +325,47 @@ basic_string_view<CharT, Traits>::front() const noexcept |
320 | 325 | return operator[](0); |
321 | 326 | } |
322 | 327 |
|
| 328 | +/** |
| 329 | + * Moves the start of the view forward by n characters. |
| 330 | + * The behavior is undefined if n > size(). |
| 331 | + * |
| 332 | + * @param[in] n number of characters to remove from the start of the view |
| 333 | + */ |
| 334 | +template <typename CharT, typename Traits> |
| 335 | +void |
| 336 | +basic_string_view<CharT, Traits>::remove_prefix(size_type n) |
| 337 | +{ |
| 338 | + data_ += n; |
| 339 | + size_ -= n; |
| 340 | +} |
| 341 | + |
| 342 | +/** |
| 343 | + * Moves the end of the view back by n characters. |
| 344 | + * The behavior is undefined if n > size(). |
| 345 | + * |
| 346 | + * @param[in] n number of characters to remove from the end of the view |
| 347 | + */ |
| 348 | +template <typename CharT, typename Traits> |
| 349 | +void |
| 350 | +basic_string_view<CharT, Traits>::remove_suffix(size_type n) |
| 351 | +{ |
| 352 | + size_ -= n; |
| 353 | +} |
| 354 | + |
| 355 | +/** |
| 356 | + * Exchanges the view with that of v. |
| 357 | + * |
| 358 | + * @param[in] v view to swap with |
| 359 | + */ |
| 360 | +template <typename CharT, typename Traits> |
| 361 | +void |
| 362 | +basic_string_view<CharT, Traits>::swap( |
| 363 | + basic_string_view<CharT, Traits> &v) noexcept |
| 364 | +{ |
| 365 | + std::swap(data_, v.data_); |
| 366 | + std::swap(size_, v.size_); |
| 367 | +} |
| 368 | + |
323 | 369 | /** |
324 | 370 | * Compares this string_view with other. Works in the same way as |
325 | 371 | * std::basic_string::compare. |
|
0 commit comments