提交 bc450b17 编写于 作者: B Brian Anderson

core: Change the argument order on splitn and rsplitn for strs.

This makes it consistent with the same functions for slices,
and allows the search closure to be specified last.

[breaking-change]
上级 4e1024f8
......@@ -233,7 +233,7 @@ fn parse_exec_env(line: &str) -> Option<(String, String)> {
parse_name_value_directive(line, "exec-env").map(|nv| {
// nv is either FOO or FOO=BAR
let mut strs: Vec<String> = nv.as_slice()
.splitn('=', 1)
.splitn(1, '=')
.map(|s| s.to_string())
.collect();
......
......@@ -1147,22 +1147,22 @@ pub trait StrSlice<'a> {
/// # Example
///
/// ```rust
/// let v: Vec<&str> = "Mary had a little lambda".splitn(' ', 2).collect();
/// let v: Vec<&str> = "Mary had a little lambda".splitn(2, ' ').collect();
/// assert_eq!(v, vec!["Mary", "had", "a little lambda"]);
///
/// let v: Vec<&str> = "abc1def2ghi".splitn(|c: char| c.is_digit(), 1).collect();
/// let v: Vec<&str> = "abc1def2ghi".splitn(1, |c: char| c.is_digit()).collect();
/// assert_eq!(v, vec!["abc", "def2ghi"]);
///
/// let v: Vec<&str> = "lionXXtigerXleopard".splitn('X', 2).collect();
/// let v: Vec<&str> = "lionXXtigerXleopard".splitn(2, 'X').collect();
/// assert_eq!(v, vec!["lion", "", "tigerXleopard"]);
///
/// let v: Vec<&str> = "abcXdef".splitn('X', 0).collect();
/// let v: Vec<&str> = "abcXdef".splitn(0, 'X').collect();
/// assert_eq!(v, vec!["abcXdef"]);
///
/// let v: Vec<&str> = "".splitn('X', 1).collect();
/// let v: Vec<&str> = "".splitn(1, 'X').collect();
/// assert_eq!(v, vec![""]);
/// ```
fn splitn<Sep: CharEq>(&self, sep: Sep, count: uint) -> CharSplitsN<'a, Sep>;
fn splitn<Sep: CharEq>(&self, count: uint, sep: Sep) -> CharSplitsN<'a, Sep>;
/// An iterator over substrings of `self`, separated by characters
/// matched by `sep`.
......@@ -1197,16 +1197,16 @@ pub trait StrSlice<'a> {
/// # Example
///
/// ```rust
/// let v: Vec<&str> = "Mary had a little lamb".rsplitn(' ', 2).collect();
/// let v: Vec<&str> = "Mary had a little lamb".rsplitn(2, ' ').collect();
/// assert_eq!(v, vec!["lamb", "little", "Mary had a"]);
///
/// let v: Vec<&str> = "abc1def2ghi".rsplitn(|c: char| c.is_digit(), 1).collect();
/// let v: Vec<&str> = "abc1def2ghi".rsplitn(1, |c: char| c.is_digit()).collect();
/// assert_eq!(v, vec!["ghi", "abc1def"]);
///
/// let v: Vec<&str> = "lionXXtigerXleopard".rsplitn('X', 2).collect();
/// let v: Vec<&str> = "lionXXtigerXleopard".rsplitn(2, 'X').collect();
/// assert_eq!(v, vec!["leopard", "tiger", "lionX"]);
/// ```
fn rsplitn<Sep: CharEq>(&self, sep: Sep, count: uint) -> CharSplitsN<'a, Sep>;
fn rsplitn<Sep: CharEq>(&self, count: uint, sep: Sep) -> CharSplitsN<'a, Sep>;
/// An iterator over the start and end indices of the disjoint
/// matches of `sep` within `self`.
......@@ -1697,7 +1697,7 @@ fn split<Sep: CharEq>(&self, sep: Sep) -> CharSplits<'a, Sep> {
}
#[inline]
fn splitn<Sep: CharEq>(&self, sep: Sep, count: uint)
fn splitn<Sep: CharEq>(&self, count: uint, sep: Sep)
-> CharSplitsN<'a, Sep> {
CharSplitsN {
iter: self.split(sep),
......@@ -1716,7 +1716,7 @@ fn split_terminator<Sep: CharEq>(&self, sep: Sep)
}
#[inline]
fn rsplitn<Sep: CharEq>(&self, sep: Sep, count: uint)
fn rsplitn<Sep: CharEq>(&self, count: uint, sep: Sep)
-> CharSplitsN<'a, Sep> {
CharSplitsN {
iter: self.split(sep),
......
......@@ -341,7 +341,7 @@ impl<T: FromStr + Clone + Integer + PartialOrd>
FromStr for Ratio<T> {
/// Parses `numer/denom` or just `numer`.
fn from_str(s: &str) -> Option<Ratio<T>> {
let mut split = s.splitn('/', 1);
let mut split = s.splitn(1, '/');
let num = split.next().and_then(|n| FromStr::from_str(n));
let den = split.next().or(Some("1")).and_then(|d| FromStr::from_str(d));
......@@ -357,7 +357,7 @@ impl<T: FromStrRadix + Clone + Integer + PartialOrd>
FromStrRadix for Ratio<T> {
/// Parses `numer/denom` where the numbers are in base `radix`.
fn from_str_radix(s: &str, radix: uint) -> Option<Ratio<T>> {
let split: Vec<&str> = s.splitn('/', 1).collect();
let split: Vec<&str> = s.splitn(1, '/').collect();
if split.len() < 2 {
None
} else {
......
......@@ -13,6 +13,7 @@
use std::fmt;
use std::iter;
use std::num;
use std::slice;
/// Static data containing Unicode ranges for general categories and scripts.
use unicode::regex::{UNICODE_CLASSES, PERLD, PERLS, PERLW};
......@@ -518,7 +519,7 @@ fn parse_counted(&mut self) -> Result<(), Error> {
min = try!(self.parse_uint(inner.as_slice()));
max = Some(min);
} else {
let pieces: Vec<&str> = inner.as_slice().splitn(',', 1).collect();
let pieces: Vec<&str> = inner.as_slice().splitn(1, ',').collect();
let (smin, smax) = (pieces[0], pieces[1]);
if smin.len() == 0 {
return self.err("Max repetitions cannot be specified \
......@@ -1017,9 +1018,9 @@ fn is_valid_cap(c: char) -> bool {
}
fn find_class(classes: NamedClasses, name: &str) -> Option<Vec<(char, char)>> {
match classes.bsearch(|&(s, _)| s.cmp(&name)) {
Some(i) => Some(Vec::from_slice(classes[i].val1())),
None => None,
match classes.binary_search(|&(s, _)| s.cmp(&name)) {
slice::Found(i) => Some(Vec::from_slice(classes[i].val1())),
slice::NotFound(_) => None,
}
}
......
......@@ -35,7 +35,6 @@
use std::cmp;
use std::mem;
use std::slice;
use std::slice::MutableSlice;
use compile::{
Program,
......
......@@ -353,7 +353,7 @@ pub fn build_codegen_options(matches: &getopts::Matches) -> CodegenOptions
{
let mut cg = basic_codegen_options();
for option in matches.opt_strs("C").move_iter() {
let mut iter = option.as_slice().splitn('=', 1);
let mut iter = option.as_slice().splitn(1, '=');
let key = iter.next().unwrap();
let value = iter.next();
let option_to_lookup = key.replace("-", "_");
......@@ -750,7 +750,7 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options {
let mut externs = HashMap::new();
for arg in matches.opt_strs("extern").iter() {
let mut parts = arg.as_slice().splitn('=', 1);
let mut parts = arg.as_slice().splitn(1, '=');
let name = match parts.next() {
Some(s) => s,
None => early_error("--extern value must not be empty"),
......
......@@ -356,7 +356,7 @@ pub enum PpMode {
}
fn parse_pretty(sess: &Session, name: &str) -> (PpMode, Option<driver::UserIdentifiedItem>) {
let mut split = name.splitn('=', 1);
let mut split = name.splitn(1, '=');
let first = split.next().unwrap();
let opt_second = split.next();
let first = match first {
......
......@@ -328,7 +328,7 @@ fn acquire_input(input: &str,
fn parse_externs(matches: &getopts::Matches) -> Result<core::Externs, String> {
let mut externs = HashMap::new();
for arg in matches.opt_strs("extern").iter() {
let mut parts = arg.as_slice().splitn('=', 1);
let mut parts = arg.as_slice().splitn(1, '=');
let name = match parts.next() {
Some(s) => s,
None => {
......
......@@ -51,7 +51,7 @@ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
impl FromStr for CrateId {
fn from_str(s: &str) -> Option<CrateId> {
let pieces: Vec<&str> = s.splitn('#', 1).collect();
let pieces: Vec<&str> = s.splitn(1, '#').collect();
let path = pieces.get(0).to_string();
if path.as_slice().starts_with("/") || path.as_slice().ends_with("/") ||
......@@ -60,7 +60,7 @@ fn from_str(s: &str) -> Option<CrateId> {
}
let path_pieces: Vec<&str> = path.as_slice()
.rsplitn('/', 1)
.rsplitn(1, '/')
.collect();
let inferred_name = *path_pieces.get(0);
......@@ -68,7 +68,7 @@ fn from_str(s: &str) -> Option<CrateId> {
(inferred_name.to_string(), None)
} else {
let hash_pieces: Vec<&str> = pieces.get(1)
.splitn(':', 1)
.splitn(1, ':')
.collect();
let (hash_name, hash_version) = if hash_pieces.len() == 1 {
("", *hash_pieces.get(0))
......
......@@ -396,7 +396,7 @@ fn maybe_push_value(map: &mut HashMap<String, Vec<String>>,
}
fn split_char_first(s: &str, c: char) -> (&str, &str) {
let mut iter = s.splitn(c, 1);
let mut iter = s.splitn(1, c);
match (iter.next(), iter.next()) {
(Some(a), Some(b)) => (a, b),
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册