Commit Graph

18 Commits

Author SHA1 Message Date
Dylan DPC f7febc8865
Rollup merge of #82570 - WaffleLapkin:split_whitespace_as_str, r=m-ou-se
Add `as_str` method for split whitespace str iterators

This PR adds `as_str` methods to `SplitWhitespace` and `SplitAsciiWhitespace`
str iterators. The methods return the remainder, similar to `as_str` methods on
`Chars` and other split iterators. This PR is a continuation of https://github.com/rust-lang/rust/pull/75265, which added `as_str` for all other str split iterators.

The feature gate for new methods is `#![feature(str_split_whitespace_as_str)]`.

`SplitWhitespace` and `SplitAsciiWhitespace` use iterators under the hood, so to implement `as_str` it's required to either
1. Make fields of some iterators `pub(crate)`
2. Add getter methods (like `into_inner`, `inner`, `inner_mut`...) to some (all) iterators
3. Completely rewrite `SplitWhitespace` and `SplitAsciiWhitespace`

This PR uses the 1. approach since it's easier to implement and requires fewer changes (and no changes to the public API). If you think that's not the right way, please, tell me.

r? `@m-ou-se`
2021-03-19 23:01:35 +01:00
Waffle d4fd8538cb Change formatting of safety comment 2021-02-27 02:33:09 +03:00
Waffle 12d6238f4d Add `as_str` method for split whitespace str iterators
This commit adds `as_str` methods to `SplitWhitespace` and `SplitAsciiWhitespace`
str iterators. The methods return the remainder, similar to `as_str` methods on
`Chars` and other split iterators.

This commit also makes fields of some iterators `pub(crate)`.
2021-02-27 01:46:04 +03:00
Tomasz Miąsko dc3304c341 Turn may_have_side_effect into an associated constant
The `may_have_side_effect` is an implementation detail of `TrustedRandomAccess`
trait. It describes if obtaining an iterator element may have side effects. It
is currently implemented as an associated function.

Turn `may_have_side_effect` into an associated constant. This makes the
value immediately available to the optimizer.
2021-02-15 17:36:29 +01:00
Giles Cope a623ea5301
Same instructions, but simpler. 2021-01-26 21:57:50 +00:00
Giles Cope c07e5585b3
Let's try the most idiomatic way. 2021-01-26 11:36:02 +00:00
Giles Cope 425a70a460
Removing if so it's more like the previous implementation. 2021-01-26 11:26:58 +00:00
Giles Cope 328abfb943
Slight simplification of chars().count() 2021-01-26 11:14:57 +00:00
Ashley Mannix e4a2f33360
bump split_inclusive stabilization to 1.51.0 2021-01-13 13:50:39 +10:00
Ian Jackson 2c1d6557c9 Remove two obsolete uses of #![feature(split_inclusive)]
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
2021-01-04 16:29:12 +00:00
Ian Jackson be226e49e4 Stabilize split_inclusive
Closes #72360.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
2021-01-04 16:20:08 +00:00
Mara Bos 76daca2791 Add #[inline] to some core::str functions.
Almost all these functions already had #[inline]. These were missing.
2020-10-18 15:39:09 +02:00
Waffle 7bd6403b38 fill in the tracking issue 2020-10-16 01:11:39 +03:00
Waffle 076514c8a8 add `str::SplitInclusive::as_str` method
This commit entroduces `core::str::SplitInclusive::as_str` method similar to
`core::str::Split::as_str`, but under different gate -
"str_split_inclusive_as_str" (this is done so because `SplitInclusive` is
itself unstable).
2020-10-01 23:40:42 +03:00
Waffle 4747215d77 add `str::{SplitN, RSplitN, SplitTerminator, RSplitTerminator}::as_str` methods
This commit entroduce 4 methods smililar to `Split::as_str` all under the same
gate "str_split_as_str".
2020-10-01 23:08:15 +03:00
Waffle 0b923d3ca0 add `str::{Split,RSplit}::as_str` methods
This commit introduses 2 methods under "str_split_as_str" gate with common
signature of `&Split<'a, _> -> &'a str'`. Both of them work like
`Chars::as_str` - return unyield part of the inner string.
2020-10-01 22:53:15 +03:00
Lzu Tao 90c813a0f0 Move utf-8 validating helpers to new mod 2020-09-26 05:20:53 +00:00
Lzu Tao 5f0d724e29 Move str's impl of iterations to new mod 2020-09-26 05:20:51 +00:00