Skip to content

Commit

Permalink
Addressed PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Kimundi committed Feb 19, 2015
1 parent a641996 commit c8dd2d0
Show file tree
Hide file tree
Showing 18 changed files with 233 additions and 86 deletions.
2 changes: 1 addition & 1 deletion src/compiletest/compiletest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
#![feature(env)]
#![feature(core)]

// #![deny(warnings)]
#![deny(warnings)]

extern crate test;
extern crate getopts;
Expand Down
2 changes: 1 addition & 1 deletion src/compiletest/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ pub fn load_errors(testfile: &Path) -> Vec<ExpectedError> {
fn parse_expected(last_nonfollow_error: Option<uint>,
line_num: uint,
line: &str) -> Option<(WhichLine, ExpectedError)> {
let start = match line.find_str("//~") { Some(i) => i, None => return None };
let start = match line.find("//~") { Some(i) => i, None => return None };
let (follow, adjusts) = if line.char_at(start + 3) == '|' {
(true, 0)
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/compiletest/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ fn parse_name_directive(line: &str, directive: &str) -> bool {
pub fn parse_name_value_directive(line: &str, directive: &str)
-> Option<String> {
let keycolon = format!("{}:", directive);
match line.find_str(&keycolon) {
match line.find(&keycolon) {
Some(colon) => {
let value = line[(colon + keycolon.len()) .. line.len()].to_string();
debug!("{}: {}", directive, value);
Expand Down
4 changes: 2 additions & 2 deletions src/compiletest/runtest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -847,7 +847,7 @@ fn check_debugger_output(debugger_run_result: &ProcRes, check_lines: &[String])
check_lines.iter().map(|s| {
s
.trim()
.split_str("[...]")
.split("[...]")
.map(|x| x.to_string())
.collect()
}).collect();
Expand All @@ -866,7 +866,7 @@ fn check_debugger_output(debugger_run_result: &ProcRes, check_lines: &[String])
None
}
} else {
rest.find_str(frag)
rest.find(frag)
};
match found {
None => {
Expand Down
28 changes: 17 additions & 11 deletions src/libcollections/str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -547,8 +547,8 @@ pub trait StrExt: Index<RangeFull, Output = str> {
/// ```rust
/// assert!("hello".contains_char('e'));
/// ```
#[unstable(feature = "collections",
reason = "might get removed in favour of a more generic contains()")]
#[unstable(feature = "collections")]
#[deprecated(since = "1.0.0", reason = "use `contains()` with a char")]
fn contains_char<'a, P: Pattern<'a>>(&'a self, pat: P) -> bool {
core_str::StrExt::contains_char(&self[..], pat)
}
Expand Down Expand Up @@ -660,7 +660,7 @@ pub trait StrExt: Index<RangeFull, Output = str> {
/// let v: Vec<&str> = "lionXXtigerXleopard".split('X').rev().collect();
/// assert_eq!(v, vec!["leopard", "tiger", "", "lion"]);
/// ```
#[unstable(feature = "collections", reason = "might get removed")]
#[stable(feature = "rust1", since = "1.0.0")]
fn split_terminator<'a, P: Pattern<'a>>(&'a self, pat: P) -> SplitTerminator<'a, P> {
core_str::StrExt::split_terminator(&self[..], pat)
}
Expand Down Expand Up @@ -708,6 +708,8 @@ pub trait StrExt: Index<RangeFull, Output = str> {
/// ```
#[unstable(feature = "collections",
reason = "might have its iterator type changed")]
// NB: Right now MatchIndices yields `(usize, usize)`,
// but it would be more consistent and useful to return `(usize, &str)`
fn match_indices<'a, P: Pattern<'a>>(&'a self, pat: P) -> MatchIndices<'a, P> {
core_str::StrExt::match_indices(&self[..], pat)
}
Expand All @@ -723,8 +725,8 @@ pub trait StrExt: Index<RangeFull, Output = str> {
/// let v: Vec<&str> = "1abcabc2".split_str("abc").collect();
/// assert_eq!(v, vec!["1", "", "2"]);
/// ```
#[unstable(feature = "collections",
reason = "might get removed in the future in favor of a more generic split()")]
#[unstable(feature = "collections")]
#[deprecated(since = "1.0.0", reason = "use `split()` with a `&str`")]
fn split_str<'a, P: Pattern<'a>>(&'a self, pat: P) -> SplitStr<'a, P> {
core_str::StrExt::split_str(&self[..], pat)
}
Expand Down Expand Up @@ -840,7 +842,8 @@ pub trait StrExt: Index<RangeFull, Output = str> {
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
fn ends_with<'a, P: Pattern<'a>>(&'a self, pat: P) -> bool
where P::Searcher: ReverseSearcher<'a> {
where P::Searcher: ReverseSearcher<'a>
{
core_str::StrExt::ends_with(&self[..], pat)
}

Expand All @@ -861,7 +864,8 @@ pub trait StrExt: Index<RangeFull, Output = str> {
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
fn trim_matches<'a, P: Pattern<'a>>(&'a self, pat: P) -> &'a str
where P::Searcher: DoubleEndedSearcher<'a> {
where P::Searcher: DoubleEndedSearcher<'a>
{
core_str::StrExt::trim_matches(&self[..], pat)
}

Expand Down Expand Up @@ -902,7 +906,8 @@ pub trait StrExt: Index<RangeFull, Output = str> {
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
fn trim_right_matches<'a, P: Pattern<'a>>(&'a self, pat: P) -> &'a str
where P::Searcher: ReverseSearcher<'a> {
where P::Searcher: ReverseSearcher<'a>
{
core_str::StrExt::trim_right_matches(&self[..], pat)
}

Expand Down Expand Up @@ -1108,7 +1113,8 @@ pub trait StrExt: Index<RangeFull, Output = str> {
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
fn rfind<'a, P: Pattern<'a>>(&'a self, pat: P) -> Option<usize>
where P::Searcher: ReverseSearcher<'a> {
where P::Searcher: ReverseSearcher<'a>
{
core_str::StrExt::rfind(&self[..], pat)
}

Expand All @@ -1131,8 +1137,8 @@ pub trait StrExt: Index<RangeFull, Output = str> {
/// assert_eq!(s.find_str("老虎 L"), Some(6));
/// assert_eq!(s.find_str("muffin man"), None);
/// ```
#[unstable(feature = "collections",
reason = "might get removed in favor of a more generic find in the future")]
#[unstable(feature = "collections")]
#[deprecated(since = "1.0.0", reason = "use `find()` with a `&str`")]
fn find_str<'a, P: Pattern<'a>>(&'a self, needle: P) -> Option<usize> {
core_str::StrExt::find_str(&self[..], needle)
}
Expand Down
40 changes: 28 additions & 12 deletions src/libcore/str/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -242,8 +242,10 @@ pub unsafe fn from_c_str(s: *const i8) -> &'static str {
}

/// Something that can be used to compare against a character
#[unstable(feature = "core",
reason = "definition may change as pattern-related methods are stabilized")]
#[unstable(feature = "core")]
#[deprecated(since = "1.0.0",
reason = "use `Pattern` instead")]
// NB: Rather than removing it, make it private and move it into self::pattern
pub trait CharEq {
/// Determine if the splitter should split at the given character
fn matches(&mut self, char) -> bool;
Expand All @@ -252,6 +254,7 @@ pub trait CharEq {
fn only_ascii(&self) -> bool;
}

#[allow(deprecated) /* for CharEq */ ]
impl CharEq for char {
#[inline]
fn matches(&mut self, c: char) -> bool { *self == c }
Expand All @@ -260,6 +263,7 @@ impl CharEq for char {
fn only_ascii(&self) -> bool { (*self as u32) < 128 }
}

#[allow(deprecated) /* for CharEq */ ]
impl<F> CharEq for F where F: FnMut(char) -> bool {
#[inline]
fn matches(&mut self, c: char) -> bool { (*self)(c) }
Expand All @@ -268,13 +272,16 @@ impl<F> CharEq for F where F: FnMut(char) -> bool {
fn only_ascii(&self) -> bool { false }
}

#[allow(deprecated) /* for CharEq */ ]
impl<'a> CharEq for &'a [char] {
#[inline]
#[allow(deprecated) /* for CharEq */ ]
fn matches(&mut self, c: char) -> bool {
self.iter().any(|&m| { let mut m = m; m.matches(c) })
}

#[inline]
#[allow(deprecated) /* for CharEq */ ]
fn only_ascii(&self) -> bool {
self.iter().all(|m| m.only_ascii())
}
Expand Down Expand Up @@ -764,7 +771,7 @@ impl TwoWaySearcher {
// that (u, v) is a critical factorization for the needle.
#[inline]
fn next(&mut self, haystack: &[u8], needle: &[u8], long_period: bool)
-> Option<(usize, usize)> {
-> Option<(usize, usize)> {
'search: loop {
// Check that we have room to search in
if self.position + needle.len() > haystack.len() {
Expand Down Expand Up @@ -866,6 +873,8 @@ impl TwoWaySearcher {
/// The internal state of an iterator that searches for matches of a substring
/// within a larger string using a dynamically chosen search algorithm
#[derive(Clone)]
// NB: This is kept around for convenience because
// it is planned to be used again in the future
enum OldSearcher {
TwoWay(TwoWaySearcher),
TwoWayLong(TwoWaySearcher),
Expand Down Expand Up @@ -896,6 +905,8 @@ impl OldSearcher {
}

#[derive(Clone)]
// NB: This is kept around for convenience because
// it is planned to be used again in the future
struct OldMatchIndices<'a, 'b> {
// constants
haystack: &'a str,
Expand All @@ -921,7 +932,8 @@ impl<'a, P: Pattern<'a>> Iterator for MatchIndices<'a, P> {

/// An iterator over the substrings of a string separated by a given
/// search string
#[unstable(feature = "core", reason = "type may be removed")]
#[unstable(feature = "core")]
#[deprecated(since = "1.0.0", reason = "use `Split` with a `&str`")]
pub struct SplitStr<'a, P: Pattern<'a>>(Split<'a, P>);
impl<'a, P: Pattern<'a>> Iterator for SplitStr<'a, P> {
type Item = &'a str;
Expand Down Expand Up @@ -1282,8 +1294,7 @@ where P::Searcher: DoubleEndedSearcher<'a> {
}

/// Return type of `StrExt::split_terminator`
#[unstable(feature = "core",
reason = "might get removed in favour of a constructor method on Split")]
#[stable(feature = "rust1", since = "1.0.0")]
pub struct SplitTerminator<'a, P: Pattern<'a>>(CharSplits<'a, P>);
delegate_iter!{pattern &'a str : SplitTerminator<'a, P>}

Expand Down Expand Up @@ -1421,6 +1432,7 @@ impl StrExt for str {
}

#[inline]
#[allow(deprecated) /* for SplitStr */ ]
fn split_str<'a, P: Pattern<'a>>(&'a self, pat: P) -> SplitStr<'a, P> {
SplitStr(self.split(pat))
}
Expand Down Expand Up @@ -1477,18 +1489,20 @@ impl StrExt for str {

#[inline]
fn starts_with<'a, P: Pattern<'a>>(&'a self, pat: P) -> bool {
pat.match_starts_at(self, 0)
pat.is_prefix_of(self)
}

#[inline]
fn ends_with<'a, P: Pattern<'a>>(&'a self, pat: P) -> bool
where P::Searcher: ReverseSearcher<'a> {
pat.match_ends_at(self, self.len())
where P::Searcher: ReverseSearcher<'a>
{
pat.is_suffix_of(self)
}

#[inline]
fn trim_matches<'a, P: Pattern<'a>>(&'a self, pat: P) -> &'a str
where P::Searcher: DoubleEndedSearcher<'a> {
where P::Searcher: DoubleEndedSearcher<'a>
{
let mut i = 0;
let mut j = 0;
let mut matcher = pat.into_searcher(self);
Expand Down Expand Up @@ -1521,7 +1535,8 @@ impl StrExt for str {

#[inline]
fn trim_right_matches<'a, P: Pattern<'a>>(&'a self, pat: P) -> &'a str
where P::Searcher: ReverseSearcher<'a> {
where P::Searcher: ReverseSearcher<'a>
{
let mut j = 0;
let mut matcher = pat.into_searcher(self);
if let Some((_, b)) = matcher.next_reject_back() {
Expand Down Expand Up @@ -1599,7 +1614,8 @@ impl StrExt for str {
}

fn rfind<'a, P: Pattern<'a>>(&'a self, pat: P) -> Option<usize>
where P::Searcher: ReverseSearcher<'a> {
where P::Searcher: ReverseSearcher<'a>
{
pat.into_searcher(self).next_match_back().map(|(i, _)| i)
}

Expand Down
Loading

0 comments on commit c8dd2d0

Please sign in to comment.