Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tracking Issue for split_inclusive #72360

Closed
3 tasks done
golddranks opened this issue May 19, 2020 · 2 comments · Fixed by #77858
Closed
3 tasks done

Tracking Issue for split_inclusive #72360

golddranks opened this issue May 19, 2020 · 2 comments · Fixed by #77858
Labels
A-slice Area: `[T]` A-str Area: str and String B-unstable Blocker: Implemented in the nightly compiler and unstable. C-tracking-issue Category: An issue tracking the progress of sth. like the implementation of an RFC Libs-Small Libs issues that are considered "small" or self-contained Libs-Tracked Libs issues that are tracked on the team's project board. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.

Comments

@golddranks
Copy link
Contributor

golddranks commented May 19, 2020

This is a tracking issue for split_inclusive APIs for slice and str.
The feature gate for the issue is #![feature(split_inclusive)].

API overview

  • Implement split_inclusive for slice and str and split_inclusive_mut for slice
  • split_inclusive is a substring/subslice splitting iterator that includes the matched part in the iterated substrings as a terminator.
  • Two examples below:
    let data = "\nMäry häd ä little lämb\nLittle lämb\n";
    let split: Vec<&str> = data.split_inclusive('\n').collect();
    assert_eq!(split, ["\n", "Märy häd ä little lämb\n", "Little lämb\n"]);
    let uppercase_separated = "SheePSharKTurtlECaT";
    let mut first_char = true;
    let split: Vec<&str> = uppercase_separated.split_inclusive(|c: char| {
        let split = !first_char && c.is_uppercase();
        first_char = split;
        split
    }).collect();
    assert_eq!(split, ["SheeP", "SharK", "TurtlE", "CaT"]);

About tracking issues

Tracking issues are used to record the overall progress of implementation.
They are also uses as hubs connecting to other relevant issues, e.g., bugs or open design questions.
A tracking issue is however not meant for large scale discussion, questions, or bug reports about a feature.
Instead, open a dedicated issue for the specific matter and add the relevant feature gate label.

Steps

Unresolved Questions

No known unresolved questions at the moment.

Implementation history

Implementation: #67330

@golddranks golddranks added the C-tracking-issue Category: An issue tracking the progress of sth. like the implementation of an RFC label May 19, 2020
@jonas-schievink jonas-schievink added B-unstable Blocker: Implemented in the nightly compiler and unstable. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. labels May 19, 2020
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this issue May 20, 2020
…king_issue, r=shepmaster

split_inclusive: add tracking issue number (72360)

Adds tracking issue number ( rust-lang#72360 ) to the unstable feature attributes.
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this issue May 20, 2020
…king_issue, r=shepmaster

split_inclusive: add tracking issue number (72360)

Adds tracking issue number ( rust-lang#72360 ) to the unstable feature attributes.
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this issue May 20, 2020
…king_issue, r=shepmaster

split_inclusive: add tracking issue number (72360)

Adds tracking issue number ( rust-lang#72360 ) to the unstable feature attributes.
@matklad
Copy link
Member

matklad commented Jun 27, 2020

We also need str::lines_inclusive -- like .lines(), but keeps line endings. We can stabilize/implement these separately, but we must make sure that the naming is consistent.

EDIT: wait, I guess lines_inclusive is just .split_inclusive('\n')? By happy accident, it will magically handle both \r\n and optional trailing newline correctly? Then we might get by without dedicated method, and just call out this pattern in the docs.

@golddranks
Copy link
Contributor Author

@matklad I planned using it also for lines_inclusive -like functionality, but didn't thought about it exhaustively. Indeed, it's a nice plus that \r\n seems to work. I guess that \r (and especially the others https://en.wikipedia.org/wiki/Newline#Representation) is such a rarity these days that another method is not warranted.

I'll send a doc PR for that use case!

Also, I think that a stabilization would be warranted soonish. What ya'll think?

@KodrAus KodrAus added A-slice Area: `[T]` A-str Area: str and String I-nominated Libs-Small Libs issues that are considered "small" or self-contained Libs-Tracked Libs issues that are tracked on the team's project board. labels Jul 29, 2020
bors added a commit to rust-lang-ci/rust that referenced this issue Jan 13, 2021
Stabilize split_inclusive

### Contents of this MR

This stabilises:

 * `slice::split_inclusive`
 * `slice::split_inclusive_mut`
 * `str::split_inclusive`

Closes rust-lang#72360.

### A possible concern

The proliferation of `split_*` methods is not particularly pretty.  The existence of `split_inclusive` seems to invite the addition of `rsplit_inclusive`, `splitn_inclusive`, etc.  We could instead have a more general API, along these kinds of lines maybe:
```
   pub fn split_generic('a,P,H>(&'a self, pat: P, how: H) -> ...
       where P: Pattern
       where H: SplitHow;

   pub fn split_generic_mut('a,P,H>(&'a mut self, pat: P, how: H) -> ...
       where P: Pattern
       where H: SplitHow;

   trait SplitHow {
       fn reverse(&self) -> bool;
       fn inclusive -> bool;
       fn limit(&self) -> Option<usize>;
   }

   pub struct SplitFwd;
   ...
   pub struct SplitRevInclN(pub usize);
```
But maybe that is worse.

### Let us defer that? ###

This seems like a can of worms.  I think we can defer opening it now; if and when we have something more general, these two methods can become convenience aliases.  But I thought I would mention it so the lang API team can consider it and have an opinion.
@bors bors closed this as completed in be226e4 Jan 13, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-slice Area: `[T]` A-str Area: str and String B-unstable Blocker: Implemented in the nightly compiler and unstable. C-tracking-issue Category: An issue tracking the progress of sth. like the implementation of an RFC Libs-Small Libs issues that are considered "small" or self-contained Libs-Tracked Libs issues that are tracked on the team's project board. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants