Skip to content

Commit e781659

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 351f7af + 8c93705 commit e781659

File tree

21 files changed

+382
-174
lines changed

21 files changed

+382
-174
lines changed

src/compiletest/runtest.rs

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

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

src/libcollections/str.rs

+9-5
Original file line numberDiff line numberDiff line change
@@ -626,7 +626,9 @@ pub trait StrAllocating: Str {
626626
let me = self.as_slice();
627627
let mut out = String::with_capacity(me.len());
628628
for c in me.chars() {
629-
c.escape_default(|c| out.push(c));
629+
for c in c.escape_default() {
630+
out.push(c);
631+
}
630632
}
631633
out
632634
}
@@ -636,7 +638,9 @@ pub trait StrAllocating: Str {
636638
let me = self.as_slice();
637639
let mut out = String::with_capacity(me.len());
638640
for c in me.chars() {
639-
c.escape_unicode(|c| out.push(c));
641+
for c in c.escape_unicode() {
642+
out.push(c);
643+
}
640644
}
641645
out
642646
}
@@ -1185,7 +1189,7 @@ mod tests {
11851189
assert_eq!("11foo1bar11".trim_left_chars('1'), "foo1bar11");
11861190
let chars: &[char] = &['1', '2'];
11871191
assert_eq!("12foo1bar12".trim_left_chars(chars), "foo1bar12");
1188-
assert_eq!("123foo1bar123".trim_left_chars(|c: char| c.is_digit()), "foo1bar123");
1192+
assert_eq!("123foo1bar123".trim_left_chars(|c: char| c.is_numeric()), "foo1bar123");
11891193
}
11901194

11911195
#[test]
@@ -1200,7 +1204,7 @@ mod tests {
12001204
assert_eq!("11foo1bar11".trim_right_chars('1'), "11foo1bar");
12011205
let chars: &[char] = &['1', '2'];
12021206
assert_eq!("12foo1bar12".trim_right_chars(chars), "12foo1bar");
1203-
assert_eq!("123foo1bar123".trim_right_chars(|c: char| c.is_digit()), "123foo1bar");
1207+
assert_eq!("123foo1bar123".trim_right_chars(|c: char| c.is_numeric()), "123foo1bar");
12041208
}
12051209

12061210
#[test]
@@ -1215,7 +1219,7 @@ mod tests {
12151219
assert_eq!("11foo1bar11".trim_chars('1'), "foo1bar");
12161220
let chars: &[char] = &['1', '2'];
12171221
assert_eq!("12foo1bar12".trim_chars(chars), "foo1bar");
1218-
assert_eq!("123foo1bar123".trim_chars(|c: char| c.is_digit()), "foo1bar");
1222+
assert_eq!("123foo1bar123".trim_chars(|c: char| c.is_numeric()), "foo1bar");
12191223
}
12201224

12211225
#[test]

0 commit comments

Comments
 (0)