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/libstd | |
| parent | 80b971a9b86cf56eab5a6f707107175d4bf2bbe1 (diff) | |
| parent | 6174b8d726ed5764694e5404329d8b5e66517ed5 (diff) | |
| download | rust-fd302a95e1197e5f8401ecaa15f2cb0f81c830c3.tar.gz rust-fd302a95e1197e5f8401ecaa15f2cb0f81c830c3.zip | |
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/libstd')
| -rw-r--r-- | src/libstd/lib.rs | 1 | ||||
| -rw-r--r-- | src/libstd/sys/common/wtf8.rs | 11 |
2 files changed, 6 insertions, 6 deletions
diff --git a/src/libstd/lib.rs b/src/libstd/lib.rs index 179f0727d46..fca4c66112e 100644 --- a/src/libstd/lib.rs +++ b/src/libstd/lib.rs @@ -242,6 +242,7 @@ #![feature(unicode)] #![feature(unique)] #![feature(unsafe_no_drop_flag, filling_drop)] +#![feature(decode_utf16)] #![feature(vec_push_all)] #![feature(vec_resize)] #![feature(wrapping)] diff --git a/src/libstd/sys/common/wtf8.rs b/src/libstd/sys/common/wtf8.rs index 9e4a80a411b..eb313d275a1 100644 --- a/src/libstd/sys/common/wtf8.rs +++ b/src/libstd/sys/common/wtf8.rs @@ -37,7 +37,6 @@ use hash::{Hash, Hasher}; use iter::FromIterator; use mem; use ops; -use rustc_unicode::str::{Utf16Item, utf16_items}; use slice; use str; use string::String; @@ -186,14 +185,14 @@ impl Wtf8Buf { /// will always return the original code units. pub fn from_wide(v: &[u16]) -> Wtf8Buf { let mut string = Wtf8Buf::with_capacity(v.len()); - for item in utf16_items(v) { + for item in char::decode_utf16(v.iter().cloned()) { match item { - Utf16Item::ScalarValue(c) => string.push_char(c), - Utf16Item::LoneSurrogate(s) => { + Ok(ch) => string.push_char(ch), + Err(surrogate) => { // Surrogates are known to be in the code point range. - let code_point = unsafe { CodePoint::from_u32_unchecked(s as u32) }; + let code_point = unsafe { CodePoint::from_u32_unchecked(surrogate as u32) }; // Skip the WTF-8 concatenation check, - // surrogate pairs are already decoded by utf16_items + // surrogate pairs are already decoded by decode_utf16 string.push_code_point_unchecked(code_point) } } |
