diff options
| author | bors <bors@rust-lang.org> | 2015-08-27 00:41:13 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2015-08-27 00:41:13 +0000 |
| commit | fd302a95e1197e5f8401ecaa15f2cb0f81c830c3 (patch) | |
| tree | f067678d29ba74bb76bea9397da4b06ed975ea87 /src/libcoretest | |
| parent | 80b971a9b86cf56eab5a6f707107175d4bf2bbe1 (diff) | |
| parent | 6174b8d726ed5764694e5404329d8b5e66517ed5 (diff) | |
Auto merge of #27808 - SimonSapin:utf16decoder, r=alexcrichton
* Rename `Utf16Items` to `Utf16Decoder`. "Items" is meaningless. * Generalize it to any `u16` iterator, not just `[u16].iter()` * Make it yield `Result` instead of a custom `Utf16Item` enum that was isomorphic to `Result`. This enable using the `FromIterator for Result` impl. * Replace `Utf16Item::to_char_lossy` with a `Utf16Decoder::lossy` iterator adaptor. This is a [breaking change], but only for users of the unstable `rustc_unicode` crate. I’d like this functionality to be stabilized and re-exported in `std` eventually, as the "low-level equivalent" of `String::from_utf16` and `String::from_utf16_lossy` like #27784 is the low-level equivalent of #27714. CC @aturon, @alexcrichton
Diffstat (limited to 'src/libcoretest')
| -rw-r--r-- | src/libcoretest/char.rs | 9 | ||||
| -rw-r--r-- | src/libcoretest/lib.rs | 1 |
2 files changed, 10 insertions, 0 deletions
diff --git a/src/libcoretest/char.rs b/src/libcoretest/char.rs index f03f8e0ee78..d23442379bc 100644 --- a/src/libcoretest/char.rs +++ b/src/libcoretest/char.rs @@ -207,3 +207,12 @@ fn test_len_utf16() { assert!('\u{a66e}'.len_utf16() == 1); assert!('\u{1f4a9}'.len_utf16() == 2); } + +#[test] +fn test_decode_utf16() { + fn check(s: &[u16], expected: &[Result<char, u16>]) { + assert_eq!(::std::char::decode_utf16(s.iter().cloned()).collect::<Vec<_>>(), expected); + } + check(&[0xD800, 0x41, 0x42], &[Err(0xD800), Ok('A'), Ok('B')]); + check(&[0xD800, 0], &[Err(0xD800), Ok('\0')]); +} diff --git a/src/libcoretest/lib.rs b/src/libcoretest/lib.rs index 6313e42e0ed..dda1b096e88 100644 --- a/src/libcoretest/lib.rs +++ b/src/libcoretest/lib.rs @@ -19,6 +19,7 @@ #![feature(float_from_str_radix)] #![feature(flt2dec)] #![feature(dec2flt)] +#![feature(decode_utf16)] #![feature(fmt_radix)] #![feature(iter_arith)] #![feature(iter_arith)] |
