Skip to content

Commit 81eeec0

Browse files
committed
auto merge of #18603 : brson/rust/stdchar, r=aturon
* Deprecate the free functions in favor of methods, except the two ctors `from_u32` and `from_digit`, whose methods are deprecated. * Mark the `Char` and `UnicodeChar` traits experimental until we decide for sure that we won't have some sort of inherent methods for primitives. * The `UnicodeChar` methods related to numerics are now called e.g. `is_numeric` to match the 'numeric' unicode character class, and the `*_digit_radix` methods on `Char` now just called `*_digit`. * `len_utf8_bytes` -> `len_utf8` * Converted methods to take self by-value * Converted `escape_default` and `escape_unicode` to iterators over chars. * Renamed `is_XID_start`, `is_XID_continue` to `is_xid_start`, `is_xid_continue` to match conventions This also converts `encode_utf8` and `encode_utf16` to return iterators. I suspect this is not the final form of these methods. Perf is worse (numbers in the commit). Many of the uses ended up being awkward, copying into a buffer then writing that buffer to a `Writer`. It might be more appropriate for these to return `Reader`s instead, but that type is defined in `std`. Note: although I *did* add the `from_u32` ctor to the `Char` trait, I deprecated it again later, preferring the free ctors. I've been sitting on this for a while. cc @aturon
2 parents cd75847 + 75ffadf commit 81eeec0

File tree

20 files changed

+379
-171
lines changed

20 files changed

+379
-171
lines changed

src/compiletest/runtest.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1566,7 +1566,7 @@ fn _arm_exec_compiled_test(config: &Config,
15661566

15671567
let mut exitcode: int = 0;
15681568
for c in exitcode_out.as_slice().chars() {
1569-
if !c.is_digit() { break; }
1569+
if !c.is_numeric() { break; }
15701570
exitcode = exitcode * 10 + match c {
15711571
'0' ... '9' => c as int - ('0' as int),
15721572
_ => 101,

src/libcollections/str.rs

+9-5
Original file line numberDiff line numberDiff line change
@@ -630,7 +630,9 @@ pub trait StrAllocating: Str {
630630
let me = self.as_slice();
631631
let mut out = String::with_capacity(me.len());
632632
for c in me.chars() {
633-
c.escape_default(|c| out.push(c));
633+
for c in c.escape_default() {
634+
out.push(c);
635+
}
634636
}
635637
out
636638
}
@@ -640,7 +642,9 @@ pub trait StrAllocating: Str {
640642
let me = self.as_slice();
641643
let mut out = String::with_capacity(me.len());
642644
for c in me.chars() {
643-
c.escape_unicode(|c| out.push(c));
645+
for c in c.escape_unicode() {
646+
out.push(c);
647+
}
644648
}
645649
out
646650
}
@@ -1189,7 +1193,7 @@ mod tests {
11891193
assert_eq!("11foo1bar11".trim_left_chars('1'), "foo1bar11");
11901194
let chars: &[char] = &['1', '2'];
11911195
assert_eq!("12foo1bar12".trim_left_chars(chars), "foo1bar12");
1192-
assert_eq!("123foo1bar123".trim_left_chars(|c: char| c.is_digit()), "foo1bar123");
1196+
assert_eq!("123foo1bar123".trim_left_chars(|c: char| c.is_numeric()), "foo1bar123");
11931197
}
11941198

11951199
#[test]
@@ -1204,7 +1208,7 @@ mod tests {
12041208
assert_eq!("11foo1bar11".trim_right_chars('1'), "11foo1bar");
12051209
let chars: &[char] = &['1', '2'];
12061210
assert_eq!("12foo1bar12".trim_right_chars(chars), "12foo1bar");
1207-
assert_eq!("123foo1bar123".trim_right_chars(|c: char| c.is_digit()), "123foo1bar");
1211+
assert_eq!("123foo1bar123".trim_right_chars(|c: char| c.is_numeric()), "123foo1bar");
12081212
}
12091213

12101214
#[test]
@@ -1219,7 +1223,7 @@ mod tests {
12191223
assert_eq!("11foo1bar11".trim_chars('1'), "foo1bar");
12201224
let chars: &[char] = &['1', '2'];
12211225
assert_eq!("12foo1bar12".trim_chars(chars), "foo1bar");
1222-
assert_eq!("123foo1bar123".trim_chars(|c: char| c.is_digit()), "foo1bar");
1226+
assert_eq!("123foo1bar123".trim_chars(|c: char| c.is_numeric()), "foo1bar");
12231227
}
12241228

12251229
#[test]

0 commit comments

Comments
 (0)