Add a generic string pattern matching API by Kimundi · Pull Request #528 · rust-lang/rfcs (original) (raw)

In more detail, I think we could do something like the following, where the #[stable] methods should be able to be switched to use the proposed RFC backwards-compatibly, and the #[unstable] methods can be removed at that point:

#[stable] fn contains(&self, needle: &str) -> bool;

#[unstable] fn contains_char(&self, needle: char) -> bool;

#[stable] fn split<Sep: CharEq>(&'a self, sep: Sep) -> CharSplits<'a, Sep>; #[stable] fn splitn<Sep: CharEq>(&'a self, count: uint, sep: Sep) -> CharSplitsN<'a, Sep>; #[stable] fn rsplitn<Sep: CharEq>(&'a self, count: uint, sep: Sep) -> CharSplitsN<'a, Sep>; #[stable] fn split_terminator<Sep: CharEq>(&'a self, sep: Sep) -> CharSplits<'a, Sep>;

#[stable] fn match_indices(&'a self, sep: &'a str) -> MatchIndices<'a>;

#[unstable] fn split_str(&'a self, &'a str) -> StrSplits<'a>;

#[stable] fn starts_with(&self, needle: &str) -> bool; #[stable] fn ends_with(&self, needle: &str) -> bool;

#[unstable] fn trim_chars<C: CharEq>(&'a self, to_trim: C) -> &'a str; #[unstable] fn trim_left_chars<C: CharEq>(&'a self, to_trim: C) -> &'a str; #[unstable] fn trim_right_chars<C: CharEq>(&'a self, to_trim: C) -> &'a str;

#[stable] fn find<C: CharEq>(&self, search: C) -> Option; #[stable] fn rfind<C: CharEq>(&self, search: C) -> Option; #[unstable] fn find_str(&self, &str) -> Option;

#[stable] fn replace(&self, from: &str, to: &str) -> String { ... }