diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2022-08-20 19:32:07 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-08-20 19:32:07 +0200 |
| commit | d49906519be1e071f771b1126f13d41e8106a24e (patch) | |
| tree | fba3afb7236211e2b40b2064720cac75ddabe0a1 /library/alloc | |
| parent | 2be85b0d03d4650a3f6acec6322faeee3556d5fd (diff) | |
| parent | e8ee0b7b2b9f004c51f7a10eeff0fbfe79af28d8 (diff) | |
| download | rust-d49906519be1e071f771b1126f13d41e8106a24e.tar.gz rust-d49906519be1e071f771b1126f13d41e8106a24e.zip | |
Rollup merge of #99544 - dylni:expose-utf8lossy, r=Mark-Simulacrum
Expose `Utf8Lossy` as `Utf8Chunks` This PR changes the feature for `Utf8Lossy` from `str_internals` to `utf8_lossy` and improves the API. This is done to eventually expose the API as stable. Proposal: rust-lang/libs-team#54 Tracking Issue: #99543
Diffstat (limited to 'library/alloc')
| -rw-r--r-- | library/alloc/src/lib.rs | 1 | ||||
| -rw-r--r-- | library/alloc/src/str.rs | 2 | ||||
| -rw-r--r-- | library/alloc/src/string.rs | 16 |
3 files changed, 11 insertions, 8 deletions
diff --git a/library/alloc/src/lib.rs b/library/alloc/src/lib.rs index 8b6f4054851..e10aaefebe6 100644 --- a/library/alloc/src/lib.rs +++ b/library/alloc/src/lib.rs @@ -145,6 +145,7 @@ #![feature(unchecked_math)] #![feature(unicode_internals)] #![feature(unsize)] +#![feature(utf8_chunks)] #![feature(std_internals)] // // Language features: diff --git a/library/alloc/src/str.rs b/library/alloc/src/str.rs index d5ed2c4adf4..b94b1b1ce21 100644 --- a/library/alloc/src/str.rs +++ b/library/alloc/src/str.rs @@ -71,6 +71,8 @@ pub use core::str::{RSplit, Split}; pub use core::str::{RSplitN, SplitN}; #[stable(feature = "rust1", since = "1.0.0")] pub use core::str::{RSplitTerminator, SplitTerminator}; +#[unstable(feature = "utf8_chunks", issue = "99543")] +pub use core::str::{Utf8Chunk, Utf8Chunks}; /// Note: `str` in `Concat<str>` is not meaningful here. /// This type parameter of the trait only exists to enable another impl. diff --git a/library/alloc/src/string.rs b/library/alloc/src/string.rs index a5118e5333b..7bee894d3e4 100644 --- a/library/alloc/src/string.rs +++ b/library/alloc/src/string.rs @@ -58,9 +58,9 @@ use core::ops::Bound::{Excluded, Included, Unbounded}; use core::ops::{self, Index, IndexMut, Range, RangeBounds}; use core::ptr; use core::slice; -#[cfg(not(no_global_oom_handling))] -use core::str::lossy; use core::str::pattern::Pattern; +#[cfg(not(no_global_oom_handling))] +use core::str::Utf8Chunks; #[cfg(not(no_global_oom_handling))] use crate::borrow::{Cow, ToOwned}; @@ -628,11 +628,11 @@ impl String { #[cfg(not(no_global_oom_handling))] #[stable(feature = "rust1", since = "1.0.0")] pub fn from_utf8_lossy(v: &[u8]) -> Cow<'_, str> { - let mut iter = lossy::Utf8Lossy::from_bytes(v).chunks(); + let mut iter = Utf8Chunks::new(v); let first_valid = if let Some(chunk) = iter.next() { - let lossy::Utf8LossyChunk { valid, broken } = chunk; - if broken.is_empty() { + let valid = chunk.valid(); + if chunk.invalid().is_empty() { debug_assert_eq!(valid.len(), v.len()); return Cow::Borrowed(valid); } @@ -647,9 +647,9 @@ impl String { res.push_str(first_valid); res.push_str(REPLACEMENT); - for lossy::Utf8LossyChunk { valid, broken } in iter { - res.push_str(valid); - if !broken.is_empty() { + for chunk in iter { + res.push_str(chunk.valid()); + if !chunk.invalid().is_empty() { res.push_str(REPLACEMENT); } } |
