Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Closed
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
c05276a
Stabilize pin_static_ref.
m-ou-se Feb 2, 2022
bc4b0a7
Fix macro reexports duplicates in the sidebar
GuillaumeGomez Feb 14, 2022
d9ea7bc
Add test for duplicated macros in the sidebar
GuillaumeGomez Feb 14, 2022
4b5beae
adapt static-nobundle test to use llvm-nm
krasimirgg Feb 15, 2022
0647e38
add llvm-nm to bootstrap dist bin's
krasimirgg Feb 16, 2022
e5f7239
use BOOL for TCP_NODELAY setsockopt value on Windows
chrisnc Feb 17, 2022
5cf8274
Add module-level docs for `rustc_middle::query`
pierwill Feb 17, 2022
f7448a7
core: Implement trim functions on byte slices
dbrgn Feb 6, 2022
0f14bea
Optimize char_try_from_u32
digama0 Feb 18, 2022
56aba3c
document rustc_middle::mir::Field
MakitaToki Feb 18, 2022
7c3ebec
fix
digama0 Feb 18, 2022
6210208
fix some typos
MakitaToki Feb 18, 2022
b78123c
Fix miniz_oxide types showing up in std
GuillaumeGomez Feb 18, 2022
fd2e631
Rollup merge of #93580 - m-ou-se:stabilize-pin-static-ref, r=scottmcm
matthiaskrgr Feb 19, 2022
c41c187
Rollup merge of #93686 - dbrgn:trim-on-byte-slices, r=joshtriplett
matthiaskrgr Feb 19, 2022
fc8c26f
Rollup merge of #94002 - GuillaumeGomez:duplicated-sidebar-macro, r=n…
matthiaskrgr Feb 19, 2022
149168b
Rollup merge of #94023 - krasimirgg:head-llvm-use-llvm-nm, r=Mark-Sim…
matthiaskrgr Feb 19, 2022
a8cb229
Rollup merge of #94094 - chrisnc:tcp-nodelay-windows-bool, r=dtolnay
matthiaskrgr Feb 19, 2022
5a13f5a
Rollup merge of #94097 - pierwill:doc-rustc-middle-query, r=cjgillot
matthiaskrgr Feb 19, 2022
37a183c
Rollup merge of #94112 - digama0:patch-3, r=scottmcm
matthiaskrgr Feb 19, 2022
b33836f
Rollup merge of #94113 - Mizobrook-kan:issue-94025, r=estebank
matthiaskrgr Feb 19, 2022
25e3b81
Rollup merge of #94122 - GuillaumeGomez:miniz-oxide-std, r=notriddle
matthiaskrgr Feb 19, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
core: Implement trim functions on byte slices
Co-authored-by: Jubilee Young <[email protected]>
  • Loading branch information
dbrgn and workingjubilee committed Feb 17, 2022
commit f7448a77e4d9ddb2e0b52905a6a89cab86ea35f6
78 changes: 78 additions & 0 deletions library/core/src/slice/ascii.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,84 @@ impl [u8] {
pub fn escape_ascii(&self) -> EscapeAscii<'_> {
EscapeAscii { inner: self.iter().flat_map(EscapeByte) }
}

/// Returns a byte slice with leading ASCII whitespace bytes removed.
///
/// 'Whitespace' refers to the definition used by
/// `u8::is_ascii_whitespace`.
///
/// # Examples
///
/// ```
/// #![feature(byte_slice_trim_ascii)]
///
/// assert_eq!(b" \t hello world\n".trim_ascii_start(), b"hello world\n");
/// assert_eq!(b" ".trim_ascii_start(), b"");
/// assert_eq!(b"".trim_ascii_start(), b"");
/// ```
#[unstable(feature = "byte_slice_trim_ascii", issue = "94035")]
pub const fn trim_ascii_start(&self) -> &[u8] {
let mut bytes = self;
// Note: A pattern matching based approach (instead of indexing) allows
// making the function const.
while let [first, rest @ ..] = bytes {
if first.is_ascii_whitespace() {
bytes = rest;
} else {
break;
}
}
bytes
}

/// Returns a byte slice with trailing ASCII whitespace bytes removed.
///
/// 'Whitespace' refers to the definition used by
/// `u8::is_ascii_whitespace`.
///
/// # Examples
///
/// ```
/// #![feature(byte_slice_trim_ascii)]
///
/// assert_eq!(b"\r hello world\n ".trim_ascii_end(), b"\r hello world");
/// assert_eq!(b" ".trim_ascii_end(), b"");
/// assert_eq!(b"".trim_ascii_end(), b"");
/// ```
#[unstable(feature = "byte_slice_trim_ascii", issue = "94035")]
pub const fn trim_ascii_end(&self) -> &[u8] {
let mut bytes = self;
// Note: A pattern matching based approach (instead of indexing) allows
// making the function const.
while let [rest @ .., last] = bytes {
if last.is_ascii_whitespace() {
bytes = rest;
} else {
break;
}
}
bytes
}

/// Returns a byte slice with leading and trailing ASCII whitespace bytes
/// removed.
///
/// 'Whitespace' refers to the definition used by
/// `u8::is_ascii_whitespace`.
///
/// # Examples
///
/// ```
/// #![feature(byte_slice_trim_ascii)]
///
/// assert_eq!(b"\r hello world\n ".trim_ascii(), b"hello world");
/// assert_eq!(b" ".trim_ascii(), b"");
/// assert_eq!(b"".trim_ascii(), b"");
/// ```
#[unstable(feature = "byte_slice_trim_ascii", issue = "94035")]
pub const fn trim_ascii(&self) -> &[u8] {
self.trim_ascii_start().trim_ascii_end()
}
}

impl_fn_for_zst! {
Expand Down