Skip to content

Commit 0a47cd5

Browse files
committed
Un-renamed trim and substr functions.
1 parent ee2f3d9 commit 0a47cd5

File tree

15 files changed

+80
-80
lines changed

15 files changed

+80
-80
lines changed

doc/tutorial.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1363,11 +1363,11 @@ let crayon_names = crayons.map(|v| crayon_to_str(*v));
13631363
let favorite_crayon_name = crayon_names[0];
13641364
13651365
// Remove whitespace from before and after the string
1366-
let new_favorite_crayon_name = favorite_crayon_name.trim_DBGBRWD();
1366+
let new_favorite_crayon_name = favorite_crayon_name.trim();
13671367
13681368
if favorite_crayon_name.len() > 5 {
13691369
// Create a substring
1370-
println(favorite_crayon_name.substr_DBGBRWD(0, 5));
1370+
println(favorite_crayon_name.substr(0, 5));
13711371
}
13721372
~~~
13731373

src/compiletest/runtest.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ fn run_debuginfo_test(config: config, props: TestProps, testfile: &Path) {
268268
// output (in order)
269269
let mut i = 0u;
270270
for str::lines(ProcRes.stdout).each |line| {
271-
if props.check_lines[i].trim_DBGBRWD() == line.trim_DBGBRWD() {
271+
if props.check_lines[i].trim() == line.trim() {
272272
i += 1u;
273273
}
274274
if i == num_check_lines {

src/libcore/str.rs

Lines changed: 58 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ pub fn unshift_char(s: &mut ~str, ch: char) {
313313
* * chars_to_trim - A vector of chars
314314
*
315315
*/
316-
pub pure fn trim_left_chars_DBGBRWD(s: &'a str, chars_to_trim: &[char]) -> &'a str {
316+
pub pure fn trim_left_chars(s: &'a str, chars_to_trim: &[char]) -> &'a str {
317317
if chars_to_trim.is_empty() { return s; }
318318

319319
match find(s, |c| !chars_to_trim.contains(&c)) {
@@ -331,7 +331,7 @@ pub pure fn trim_left_chars_DBGBRWD(s: &'a str, chars_to_trim: &[char]) -> &'a s
331331
* * chars_to_trim - A vector of chars
332332
*
333333
*/
334-
pub pure fn trim_right_chars_DBGBRWD(s: &'a str, chars_to_trim: &[char]) -> &'a str {
334+
pub pure fn trim_right_chars(s: &'a str, chars_to_trim: &[char]) -> &'a str {
335335
if chars_to_trim.is_empty() { return s; }
336336

337337
match rfind(s, |c| !chars_to_trim.contains(&c)) {
@@ -352,20 +352,20 @@ pub pure fn trim_right_chars_DBGBRWD(s: &'a str, chars_to_trim: &[char]) -> &'a
352352
* * chars_to_trim - A vector of chars
353353
*
354354
*/
355-
pub pure fn trim_chars_DBGBRWD(s: &'a str, chars_to_trim: &[char]) -> &'a str {
356-
trim_left_chars_DBGBRWD(trim_right_chars_DBGBRWD(s, chars_to_trim), chars_to_trim)
355+
pub pure fn trim_chars(s: &'a str, chars_to_trim: &[char]) -> &'a str {
356+
trim_left_chars(trim_right_chars(s, chars_to_trim), chars_to_trim)
357357
}
358358

359359
/// Returns a string with leading whitespace removed
360-
pub pure fn trim_left_DBGBRWD(s: &'a str) -> &'a str {
360+
pub pure fn trim_left(s: &'a str) -> &'a str {
361361
match find(s, |c| !char::is_whitespace(c)) {
362362
None => "",
363363
Some(first) => unsafe { raw::slice_bytes(s, first, len(s)) }
364364
}
365365
}
366366

367367
/// Returns a string with trailing whitespace removed
368-
pub pure fn trim_right_DBGBRWD(s: &'a str) -> &'a str {
368+
pub pure fn trim_right(s: &'a str) -> &'a str {
369369
match rfind(s, |c| !char::is_whitespace(c)) {
370370
None => "",
371371
Some(last) => {
@@ -376,7 +376,7 @@ pub pure fn trim_right_DBGBRWD(s: &'a str) -> &'a str {
376376
}
377377

378378
/// Returns a string with leading and trailing whitespace removed
379-
pub pure fn trim_DBGBRWD(s: &'a str) -> &'a str { trim_left_DBGBRWD(trim_right_DBGBRWD(s)) }
379+
pub pure fn trim(s: &'a str) -> &'a str { trim_left(trim_right(s)) }
380380

381381
/*
382382
Section: Transforming strings
@@ -421,7 +421,7 @@ pub pure fn chars(s: &str) -> ~[char] {
421421
* Returns a string containing `n` characters starting at byte offset
422422
* `begin`.
423423
*/
424-
pub pure fn substr_DBGBRWD(s: &'a str, begin: uint, n: uint) -> &'a str {
424+
pub pure fn substr(s: &'a str, begin: uint, n: uint) -> &'a str {
425425
slice(s, begin, begin + count_bytes(s, begin, n))
426426
}
427427

@@ -2275,17 +2275,17 @@ pub trait StrSlice {
22752275
pure fn split_char(&self, sep: char) -> ~[~str];
22762276
pure fn split_str(&self, sep: &'a str) -> ~[~str];
22772277
pure fn starts_with(&self, needle: &'a str) -> bool;
2278-
pure fn substr_DBGBRWD(&self, begin: uint, n: uint) -> &'self str;
2278+
pure fn substr(&self, begin: uint, n: uint) -> &'self str;
22792279
pure fn to_lower(&self) -> ~str;
22802280
pure fn to_upper(&self) -> ~str;
22812281
pure fn escape_default(&self) -> ~str;
22822282
pure fn escape_unicode(&self) -> ~str;
2283-
pure fn trim_DBGBRWD(&self) -> &'self str;
2284-
pure fn trim_left_DBGBRWD(&self) -> &'self str;
2285-
pure fn trim_right_DBGBRWD(&self) -> &'self str;
2286-
pure fn trim_chars_DBGBRWD(&self, chars_to_trim: &[char]) -> &'self str;
2287-
pure fn trim_left_chars_DBGBRWD(&self, chars_to_trim: &[char]) -> &'self str;
2288-
pure fn trim_right_chars_DBGBRWD(&self, chars_to_trim: &[char]) -> &'self str;
2283+
pure fn trim(&self) -> &'self str;
2284+
pure fn trim_left(&self) -> &'self str;
2285+
pure fn trim_right(&self) -> &'self str;
2286+
pure fn trim_chars(&self, chars_to_trim: &[char]) -> &'self str;
2287+
pure fn trim_left_chars(&self, chars_to_trim: &[char]) -> &'self str;
2288+
pure fn trim_right_chars(&self, chars_to_trim: &[char]) -> &'self str;
22892289
pure fn to_owned(&self) -> ~str;
22902290
pure fn to_managed(&self) -> @str;
22912291
pure fn char_at(&self, i: uint) -> char;
@@ -2419,8 +2419,8 @@ impl StrSlice for &'self str {
24192419
* `begin`.
24202420
*/
24212421
#[inline]
2422-
pure fn substr_DBGBRWD(&self, begin: uint, n: uint) -> &'self str {
2423-
substr_DBGBRWD(*self, begin, n)
2422+
pure fn substr(&self, begin: uint, n: uint) -> &'self str {
2423+
substr(*self, begin, n)
24242424
}
24252425
/// Convert a string to lowercase
24262426
#[inline]
@@ -2437,25 +2437,25 @@ impl StrSlice for &'self str {
24372437
24382438
/// Returns a string with leading and trailing whitespace removed
24392439
#[inline]
2440-
pure fn trim_DBGBRWD(&self) -> &'self str { trim_DBGBRWD(*self) }
2440+
pure fn trim(&self) -> &'self str { trim(*self) }
24412441
/// Returns a string with leading whitespace removed
24422442
#[inline]
2443-
pure fn trim_left_DBGBRWD(&self) -> &'self str { trim_left_DBGBRWD(*self) }
2443+
pure fn trim_left(&self) -> &'self str { trim_left(*self) }
24442444
/// Returns a string with trailing whitespace removed
24452445
#[inline]
2446-
pure fn trim_right_DBGBRWD(&self) -> &'self str { trim_right_DBGBRWD(*self) }
2446+
pure fn trim_right(&self) -> &'self str { trim_right(*self) }
24472447
24482448
#[inline]
2449-
pure fn trim_chars_DBGBRWD(&self, chars_to_trim: &[char]) -> &'self str {
2450-
trim_chars_DBGBRWD(*self, chars_to_trim)
2449+
pure fn trim_chars(&self, chars_to_trim: &[char]) -> &'self str {
2450+
trim_chars(*self, chars_to_trim)
24512451
}
24522452
#[inline]
2453-
pure fn trim_left_chars_DBGBRWD(&self, chars_to_trim: &[char]) -> &'self str {
2454-
trim_left_chars_DBGBRWD(*self, chars_to_trim)
2453+
pure fn trim_left_chars(&self, chars_to_trim: &[char]) -> &'self str {
2454+
trim_left_chars(*self, chars_to_trim)
24552455
}
24562456
#[inline]
2457-
pure fn trim_right_chars_DBGBRWD(&self, chars_to_trim: &[char]) -> &'self str {
2458-
trim_right_chars_DBGBRWD(*self, chars_to_trim)
2457+
pure fn trim_right_chars(&self, chars_to_trim: &[char]) -> &'self str {
2458+
trim_right_chars(*self, chars_to_trim)
24592459
}
24602460
24612461
@@ -2817,11 +2817,11 @@ mod tests {
28172817
#[test]
28182818
fn test_substr() {
28192819
fn t(a: &str, b: &str, start: int) {
2820-
fail_unless!(substr_DBGBRWD(a, start as uint, len(b)) == b);
2820+
fail_unless!(substr(a, start as uint, len(b)) == b);
28212821
}
28222822
t("hello", "llo", 2);
28232823
t("hello", "el", 1);
2824-
fail_unless!("ะเทศไท" == substr_DBGBRWD("ประเทศไทย中华Việt Nam", 6u, 6u));
2824+
fail_unless!("ะเทศไท" == substr("ประเทศไทย中华Việt Nam", 6u, 6u));
28252825
}
28262826

28272827
#[test]
@@ -3054,62 +3054,62 @@ mod tests {
30543054

30553055
#[test]
30563056
fn test_trim_left_chars() {
3057-
fail_unless!(trim_left_chars_DBGBRWD(" *** foo *** ", ~[]) ==
3057+
fail_unless!(trim_left_chars(" *** foo *** ", ~[]) ==
30583058
" *** foo *** ");
3059-
fail_unless!(trim_left_chars_DBGBRWD(" *** foo *** ", ~['*', ' ']) ==
3059+
fail_unless!(trim_left_chars(" *** foo *** ", ~['*', ' ']) ==
30603060
"foo *** ");
3061-
fail_unless!(trim_left_chars_DBGBRWD(" *** *** ", ~['*', ' ']) == "");
3062-
fail_unless!(trim_left_chars_DBGBRWD("foo *** ", ~['*', ' ']) ==
3061+
fail_unless!(trim_left_chars(" *** *** ", ~['*', ' ']) == "");
3062+
fail_unless!(trim_left_chars("foo *** ", ~['*', ' ']) ==
30633063
"foo *** ");
30643064
}
30653065

30663066
#[test]
30673067
fn test_trim_right_chars() {
3068-
fail_unless!(trim_right_chars_DBGBRWD(" *** foo *** ", ~[]) ==
3068+
fail_unless!(trim_right_chars(" *** foo *** ", ~[]) ==
30693069
" *** foo *** ");
3070-
fail_unless!(trim_right_chars_DBGBRWD(" *** foo *** ", ~['*', ' ']) ==
3070+
fail_unless!(trim_right_chars(" *** foo *** ", ~['*', ' ']) ==
30713071
" *** foo");
3072-
fail_unless!(trim_right_chars_DBGBRWD(" *** *** ", ~['*', ' ']) == "");
3073-
fail_unless!(trim_right_chars_DBGBRWD(" *** foo", ~['*', ' ']) ==
3072+
fail_unless!(trim_right_chars(" *** *** ", ~['*', ' ']) == "");
3073+
fail_unless!(trim_right_chars(" *** foo", ~['*', ' ']) ==
30743074
" *** foo");
30753075
}
30763076

30773077
#[test]
30783078
fn test_trim_chars() {
3079-
fail_unless!(trim_chars_DBGBRWD(" *** foo *** ", ~[]) == " *** foo *** ");
3080-
fail_unless!(trim_chars_DBGBRWD(" *** foo *** ", ~['*', ' ']) == "foo");
3081-
fail_unless!(trim_chars_DBGBRWD(" *** *** ", ~['*', ' ']) == "");
3082-
fail_unless!(trim_chars_DBGBRWD("foo", ~['*', ' ']) == "foo");
3079+
fail_unless!(trim_chars(" *** foo *** ", ~[]) == " *** foo *** ");
3080+
fail_unless!(trim_chars(" *** foo *** ", ~['*', ' ']) == "foo");
3081+
fail_unless!(trim_chars(" *** *** ", ~['*', ' ']) == "");
3082+
fail_unless!(trim_chars("foo", ~['*', ' ']) == "foo");
30833083
}
30843084

30853085
#[test]
30863086
fn test_trim_left() {
3087-
fail_unless!((trim_left_DBGBRWD("") == ""));
3088-
fail_unless!((trim_left_DBGBRWD("a") == "a"));
3089-
fail_unless!((trim_left_DBGBRWD(" ") == ""));
3090-
fail_unless!((trim_left_DBGBRWD(" blah") == "blah"));
3091-
fail_unless!((trim_left_DBGBRWD(" \u3000 wut") == "wut"));
3092-
fail_unless!((trim_left_DBGBRWD("hey ") == "hey "));
3087+
fail_unless!((trim_left("") == ""));
3088+
fail_unless!((trim_left("a") == "a"));
3089+
fail_unless!((trim_left(" ") == ""));
3090+
fail_unless!((trim_left(" blah") == "blah"));
3091+
fail_unless!((trim_left(" \u3000 wut") == "wut"));
3092+
fail_unless!((trim_left("hey ") == "hey "));
30933093
}
30943094

30953095
#[test]
30963096
fn test_trim_right() {
3097-
fail_unless!((trim_right_DBGBRWD("") == ""));
3098-
fail_unless!((trim_right_DBGBRWD("a") == "a"));
3099-
fail_unless!((trim_right_DBGBRWD(" ") == ""));
3100-
fail_unless!((trim_right_DBGBRWD("blah ") == "blah"));
3101-
fail_unless!((trim_right_DBGBRWD("wut \u3000 ") == "wut"));
3102-
fail_unless!((trim_right_DBGBRWD(" hey") == " hey"));
3097+
fail_unless!((trim_right("") == ""));
3098+
fail_unless!((trim_right("a") == "a"));
3099+
fail_unless!((trim_right(" ") == ""));
3100+
fail_unless!((trim_right("blah ") == "blah"));
3101+
fail_unless!((trim_right("wut \u3000 ") == "wut"));
3102+
fail_unless!((trim_right(" hey") == " hey"));
31033103
}
31043104

31053105
#[test]
31063106
fn test_trim() {
3107-
fail_unless!((trim_DBGBRWD("") == ""));
3108-
fail_unless!((trim_DBGBRWD("a") == "a"));
3109-
fail_unless!((trim_DBGBRWD(" ") == ""));
3110-
fail_unless!((trim_DBGBRWD(" blah ") == "blah"));
3111-
fail_unless!((trim_DBGBRWD("\nwut \u3000 ") == "wut"));
3112-
fail_unless!((trim_DBGBRWD(" hey dude ") == "hey dude"));
3107+
fail_unless!((trim("") == ""));
3108+
fail_unless!((trim("a") == "a"));
3109+
fail_unless!((trim(" ") == ""));
3110+
fail_unless!((trim(" blah ") == "blah"));
3111+
fail_unless!((trim("\nwut \u3000 ") == "wut"));
3112+
fail_unless!((trim(" hey dude ") == "hey dude"));
31133113
}
31143114

31153115
#[test]

src/libcore/unstable/extfmt.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ pub mod ct {
325325
'o' as u8 => TyOctal,
326326
'f' as u8 => TyFloat,
327327
'?' as u8 => TyPoly,
328-
_ => err(~"unknown type in conversion: " + s.substr_DBGBRWD(i, 1))
328+
_ => err(~"unknown type in conversion: " + s.substr(i, 1))
329329
};
330330
331331
Parsed::new(t, i + 1)
@@ -537,7 +537,7 @@ pub mod rt {
537537
let mut unpadded = match cv.precision {
538538
CountImplied => s.to_owned(),
539539
CountIs(max) => if (max as uint) < str::char_len(s) {
540-
str::substr_DBGBRWD(s, 0, max as uint).to_owned()
540+
str::substr(s, 0, max as uint).to_owned()
541541
} else {
542542
s.to_owned()
543543
}

src/librustc/driver/driver.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -543,7 +543,7 @@ pub fn build_session_options(+binary: ~str,
543543
let lint_dict = lint::get_lint_dict();
544544
for lint_levels.each |level| {
545545
let level_name = lint::level_to_str(*level);
546-
let level_short = level_name.substr_DBGBRWD(0,1).to_upper();
546+
let level_short = level_name.substr(0,1).to_upper();
547547
let flags = vec::append(getopts::opt_strs(matches, level_short),
548548
getopts::opt_strs(matches, level_name));
549549
for flags.each |lint_name| {

src/librustc/middle/trans/expr.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1851,5 +1851,5 @@ fn trans_assign_op(bcx: block,
18511851

18521852
// NOTE: Mode neccessary here?
18531853
fn shorten(+x: ~str) -> ~str {
1854-
if x.len() > 60 { x.substr_DBGBRWD(0, 60).to_owned() } else { x }
1854+
if x.len() > 60 { x.substr(0, 60).to_owned() } else { x }
18551855
}

src/librustdoc/text_pass.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ mod test {
311311
let doc = (attr_pass::mk_pass().f)(srv.clone(), doc);
312312
let doc = (desc_to_brief_pass::mk_pass().f)(srv.clone(), doc);
313313
let doc = (sectionalize_pass::mk_pass().f)(srv.clone(), doc);
314-
(mk_pass(~"", |s| str::trim_DBGBRWD(s).to_owned() ).f)(srv.clone(), doc)
314+
(mk_pass(~"", |s| str::trim(s).to_owned() ).f)(srv.clone(), doc)
315315
}
316316
}
317317
}

src/librustdoc/trim_pass.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use text_pass;
2121
use core::str;
2222

2323
pub fn mk_pass() -> Pass {
24-
text_pass::mk_pass(~"trim", |s| s.trim_DBGBRWD().to_owned() )
24+
text_pass::mk_pass(~"trim", |s| s.trim().to_owned() )
2525
}
2626

2727
#[test]

src/librustdoc/unindent_pass.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ fn unindent(s: &str) -> ~str {
7878
};
7979

8080
if !lines.is_empty() {
81-
let unindented = ~[lines.head().trim_DBGBRWD().to_owned()]
81+
let unindented = ~[lines.head().trim().to_owned()]
8282
+ do lines.tail().map |line| {
8383
if str::is_whitespace(*line) {
8484
copy *line

src/librusti/rusti.rc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ fn run_cmd(repl: &mut Repl, _in: @io::Reader, _out: @io::Writer,
283283
for args.each |arg| {
284284
let (crate, filename) =
285285
if arg.ends_with(".rs") || arg.ends_with(".rc") {
286-
(arg.substr_DBGBRWD(0, arg.len() - 3).to_owned(), *arg)
286+
(arg.substr(0, arg.len() - 3).to_owned(), *arg)
287287
} else {
288288
(*arg, arg + ~".rs")
289289
};
@@ -317,7 +317,7 @@ fn run_cmd(repl: &mut Repl, _in: @io::Reader, _out: @io::Writer,
317317
match get_line(~"rusti| ") {
318318
None => fail!(~"unterminated multiline command :{ .. :}"),
319319
Some(line) => {
320-
if str::trim_DBGBRWD(line) == ~":}" {
320+
if str::trim(line) == ~":}" {
321321
end_multiline = true;
322322
} else {
323323
multiline_cmd += line + ~"\n";
@@ -337,7 +337,7 @@ fn run_cmd(repl: &mut Repl, _in: @io::Reader, _out: @io::Writer,
337337
fn run_line(repl: &mut Repl, in: @io::Reader, out: @io::Writer, line: ~str)
338338
-> Option<Repl> {
339339
if line.starts_with(~":") {
340-
let full = line.substr_DBGBRWD(1, line.len() - 1);
340+
let full = line.substr(1, line.len() - 1);
341341
let split = str::words(full);
342342
let len = split.len();
343343

src/libstd/bigint.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,7 @@ pub impl BigUint {
462462
let s = uint::to_str_radix(*n as uint, radix);
463463
str::from_chars(vec::from_elem(l - s.len(), '0')) + s
464464
}));
465-
str::trim_left_chars_DBGBRWD(s, ['0']).to_owned()
465+
str::trim_left_chars(s, ['0']).to_owned()
466466
}
467467
}
468468

src/libstd/semver.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ pub fn parse(s: &str) -> Option<Version> {
223223
if ! str::is_ascii(s) {
224224
return None;
225225
}
226-
let s = s.trim_DBGBRWD();
226+
let s = s.trim();
227227
let mut bad = false;
228228
do bad_parse::cond.trap(|_| { debug!("bad"); bad = true }).in {
229229
do io::with_str_reader(s) |rdr| {

0 commit comments

Comments
 (0)