Skip to content

Commit bc450b1

Browse files
committed
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]
1 parent 4e1024f commit bc450b1

File tree

10 files changed

+28
-28
lines changed

10 files changed

+28
-28
lines changed

src/compiletest/header.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ fn parse_exec_env(line: &str) -> Option<(String, String)> {
233233
parse_name_value_directive(line, "exec-env").map(|nv| {
234234
// nv is either FOO or FOO=BAR
235235
let mut strs: Vec<String> = nv.as_slice()
236-
.splitn('=', 1)
236+
.splitn(1, '=')
237237
.map(|s| s.to_string())
238238
.collect();
239239

src/libcore/str.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1147,22 +1147,22 @@ pub trait StrSlice<'a> {
11471147
/// # Example
11481148
///
11491149
/// ```rust
1150-
/// let v: Vec<&str> = "Mary had a little lambda".splitn(' ', 2).collect();
1150+
/// let v: Vec<&str> = "Mary had a little lambda".splitn(2, ' ').collect();
11511151
/// assert_eq!(v, vec!["Mary", "had", "a little lambda"]);
11521152
///
1153-
/// let v: Vec<&str> = "abc1def2ghi".splitn(|c: char| c.is_digit(), 1).collect();
1153+
/// let v: Vec<&str> = "abc1def2ghi".splitn(1, |c: char| c.is_digit()).collect();
11541154
/// assert_eq!(v, vec!["abc", "def2ghi"]);
11551155
///
1156-
/// let v: Vec<&str> = "lionXXtigerXleopard".splitn('X', 2).collect();
1156+
/// let v: Vec<&str> = "lionXXtigerXleopard".splitn(2, 'X').collect();
11571157
/// assert_eq!(v, vec!["lion", "", "tigerXleopard"]);
11581158
///
1159-
/// let v: Vec<&str> = "abcXdef".splitn('X', 0).collect();
1159+
/// let v: Vec<&str> = "abcXdef".splitn(0, 'X').collect();
11601160
/// assert_eq!(v, vec!["abcXdef"]);
11611161
///
1162-
/// let v: Vec<&str> = "".splitn('X', 1).collect();
1162+
/// let v: Vec<&str> = "".splitn(1, 'X').collect();
11631163
/// assert_eq!(v, vec![""]);
11641164
/// ```
1165-
fn splitn<Sep: CharEq>(&self, sep: Sep, count: uint) -> CharSplitsN<'a, Sep>;
1165+
fn splitn<Sep: CharEq>(&self, count: uint, sep: Sep) -> CharSplitsN<'a, Sep>;
11661166

11671167
/// An iterator over substrings of `self`, separated by characters
11681168
/// matched by `sep`.
@@ -1197,16 +1197,16 @@ pub trait StrSlice<'a> {
11971197
/// # Example
11981198
///
11991199
/// ```rust
1200-
/// let v: Vec<&str> = "Mary had a little lamb".rsplitn(' ', 2).collect();
1200+
/// let v: Vec<&str> = "Mary had a little lamb".rsplitn(2, ' ').collect();
12011201
/// assert_eq!(v, vec!["lamb", "little", "Mary had a"]);
12021202
///
1203-
/// let v: Vec<&str> = "abc1def2ghi".rsplitn(|c: char| c.is_digit(), 1).collect();
1203+
/// let v: Vec<&str> = "abc1def2ghi".rsplitn(1, |c: char| c.is_digit()).collect();
12041204
/// assert_eq!(v, vec!["ghi", "abc1def"]);
12051205
///
1206-
/// let v: Vec<&str> = "lionXXtigerXleopard".rsplitn('X', 2).collect();
1206+
/// let v: Vec<&str> = "lionXXtigerXleopard".rsplitn(2, 'X').collect();
12071207
/// assert_eq!(v, vec!["leopard", "tiger", "lionX"]);
12081208
/// ```
1209-
fn rsplitn<Sep: CharEq>(&self, sep: Sep, count: uint) -> CharSplitsN<'a, Sep>;
1209+
fn rsplitn<Sep: CharEq>(&self, count: uint, sep: Sep) -> CharSplitsN<'a, Sep>;
12101210

12111211
/// An iterator over the start and end indices of the disjoint
12121212
/// matches of `sep` within `self`.
@@ -1697,7 +1697,7 @@ impl<'a> StrSlice<'a> for &'a str {
16971697
}
16981698

16991699
#[inline]
1700-
fn splitn<Sep: CharEq>(&self, sep: Sep, count: uint)
1700+
fn splitn<Sep: CharEq>(&self, count: uint, sep: Sep)
17011701
-> CharSplitsN<'a, Sep> {
17021702
CharSplitsN {
17031703
iter: self.split(sep),
@@ -1716,7 +1716,7 @@ impl<'a> StrSlice<'a> for &'a str {
17161716
}
17171717

17181718
#[inline]
1719-
fn rsplitn<Sep: CharEq>(&self, sep: Sep, count: uint)
1719+
fn rsplitn<Sep: CharEq>(&self, count: uint, sep: Sep)
17201720
-> CharSplitsN<'a, Sep> {
17211721
CharSplitsN {
17221722
iter: self.split(sep),

src/libnum/rational.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ impl<T: FromStr + Clone + Integer + PartialOrd>
341341
FromStr for Ratio<T> {
342342
/// Parses `numer/denom` or just `numer`.
343343
fn from_str(s: &str) -> Option<Ratio<T>> {
344-
let mut split = s.splitn('/', 1);
344+
let mut split = s.splitn(1, '/');
345345

346346
let num = split.next().and_then(|n| FromStr::from_str(n));
347347
let den = split.next().or(Some("1")).and_then(|d| FromStr::from_str(d));
@@ -357,7 +357,7 @@ impl<T: FromStrRadix + Clone + Integer + PartialOrd>
357357
FromStrRadix for Ratio<T> {
358358
/// Parses `numer/denom` where the numbers are in base `radix`.
359359
fn from_str_radix(s: &str, radix: uint) -> Option<Ratio<T>> {
360-
let split: Vec<&str> = s.splitn('/', 1).collect();
360+
let split: Vec<&str> = s.splitn(1, '/').collect();
361361
if split.len() < 2 {
362362
None
363363
} else {

src/libregex/parse.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ use std::cmp;
1313
use std::fmt;
1414
use std::iter;
1515
use std::num;
16+
use std::slice;
1617

1718
/// Static data containing Unicode ranges for general categories and scripts.
1819
use unicode::regex::{UNICODE_CLASSES, PERLD, PERLS, PERLW};
@@ -518,7 +519,7 @@ impl<'a> Parser<'a> {
518519
min = try!(self.parse_uint(inner.as_slice()));
519520
max = Some(min);
520521
} else {
521-
let pieces: Vec<&str> = inner.as_slice().splitn(',', 1).collect();
522+
let pieces: Vec<&str> = inner.as_slice().splitn(1, ',').collect();
522523
let (smin, smax) = (pieces[0], pieces[1]);
523524
if smin.len() == 0 {
524525
return self.err("Max repetitions cannot be specified \
@@ -1017,9 +1018,9 @@ fn is_valid_cap(c: char) -> bool {
10171018
}
10181019

10191020
fn find_class(classes: NamedClasses, name: &str) -> Option<Vec<(char, char)>> {
1020-
match classes.bsearch(|&(s, _)| s.cmp(&name)) {
1021-
Some(i) => Some(Vec::from_slice(classes[i].val1())),
1022-
None => None,
1021+
match classes.binary_search(|&(s, _)| s.cmp(&name)) {
1022+
slice::Found(i) => Some(Vec::from_slice(classes[i].val1())),
1023+
slice::NotFound(_) => None,
10231024
}
10241025
}
10251026

src/libregex/vm.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535

3636
use std::cmp;
3737
use std::mem;
38-
use std::slice;
3938
use std::slice::MutableSlice;
4039
use compile::{
4140
Program,

src/librustc/driver/config.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ pub fn build_codegen_options(matches: &getopts::Matches) -> CodegenOptions
353353
{
354354
let mut cg = basic_codegen_options();
355355
for option in matches.opt_strs("C").move_iter() {
356-
let mut iter = option.as_slice().splitn('=', 1);
356+
let mut iter = option.as_slice().splitn(1, '=');
357357
let key = iter.next().unwrap();
358358
let value = iter.next();
359359
let option_to_lookup = key.replace("-", "_");
@@ -750,7 +750,7 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options {
750750

751751
let mut externs = HashMap::new();
752752
for arg in matches.opt_strs("extern").iter() {
753-
let mut parts = arg.as_slice().splitn('=', 1);
753+
let mut parts = arg.as_slice().splitn(1, '=');
754754
let name = match parts.next() {
755755
Some(s) => s,
756756
None => early_error("--extern value must not be empty"),

src/librustc/driver/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ pub enum PpMode {
356356
}
357357

358358
fn parse_pretty(sess: &Session, name: &str) -> (PpMode, Option<driver::UserIdentifiedItem>) {
359-
let mut split = name.splitn('=', 1);
359+
let mut split = name.splitn(1, '=');
360360
let first = split.next().unwrap();
361361
let opt_second = split.next();
362362
let first = match first {

src/librustdoc/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ fn acquire_input(input: &str,
328328
fn parse_externs(matches: &getopts::Matches) -> Result<core::Externs, String> {
329329
let mut externs = HashMap::new();
330330
for arg in matches.opt_strs("extern").iter() {
331-
let mut parts = arg.as_slice().splitn('=', 1);
331+
let mut parts = arg.as_slice().splitn(1, '=');
332332
let name = match parts.next() {
333333
Some(s) => s,
334334
None => {

src/libsyntax/crateid.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ impl fmt::Show for CrateId {
5151

5252
impl FromStr for CrateId {
5353
fn from_str(s: &str) -> Option<CrateId> {
54-
let pieces: Vec<&str> = s.splitn('#', 1).collect();
54+
let pieces: Vec<&str> = s.splitn(1, '#').collect();
5555
let path = pieces.get(0).to_string();
5656

5757
if path.as_slice().starts_with("/") || path.as_slice().ends_with("/") ||
@@ -60,15 +60,15 @@ impl FromStr for CrateId {
6060
}
6161

6262
let path_pieces: Vec<&str> = path.as_slice()
63-
.rsplitn('/', 1)
63+
.rsplitn(1, '/')
6464
.collect();
6565
let inferred_name = *path_pieces.get(0);
6666

6767
let (name, version) = if pieces.len() == 1 {
6868
(inferred_name.to_string(), None)
6969
} else {
7070
let hash_pieces: Vec<&str> = pieces.get(1)
71-
.splitn(':', 1)
71+
.splitn(1, ':')
7272
.collect();
7373
let (hash_name, hash_version) = if hash_pieces.len() == 1 {
7474
("", *hash_pieces.get(0))

src/liburl/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,7 @@ pub fn decode_form_urlencoded(s: &[u8])
396396
}
397397

398398
fn split_char_first(s: &str, c: char) -> (&str, &str) {
399-
let mut iter = s.splitn(c, 1);
399+
let mut iter = s.splitn(1, c);
400400

401401
match (iter.next(), iter.next()) {
402402
(Some(a), Some(b)) => (a, b),

0 commit comments

Comments
 (0)