Skip to content

Stabilize some ascii_ctype methods #46077

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Nov 29, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
114 changes: 0 additions & 114 deletions src/liballoc/slice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1626,120 +1626,6 @@ impl [u8] {
byte.make_ascii_lowercase();
}
}

/// Checks if all bytes of this slice are ASCII alphabetic characters:
///
/// - U+0041 'A' ... U+005A 'Z', or
/// - U+0061 'a' ... U+007A 'z'.
#[unstable(feature = "ascii_ctype", issue = "39658")]
#[inline]
pub fn is_ascii_alphabetic(&self) -> bool {
self.iter().all(|b| b.is_ascii_alphabetic())
}

/// Checks if all bytes of this slice are ASCII uppercase characters:
/// U+0041 'A' ... U+005A 'Z'.
#[unstable(feature = "ascii_ctype", issue = "39658")]
#[inline]
pub fn is_ascii_uppercase(&self) -> bool {
self.iter().all(|b| b.is_ascii_uppercase())
}

/// Checks if all bytes of this slice are ASCII lowercase characters:
/// U+0061 'a' ... U+007A 'z'.
#[unstable(feature = "ascii_ctype", issue = "39658")]
#[inline]
pub fn is_ascii_lowercase(&self) -> bool {
self.iter().all(|b| b.is_ascii_lowercase())
}

/// Checks if all bytes of this slice are ASCII alphanumeric characters:
///
/// - U+0041 'A' ... U+005A 'Z', or
/// - U+0061 'a' ... U+007A 'z', or
/// - U+0030 '0' ... U+0039 '9'.
#[unstable(feature = "ascii_ctype", issue = "39658")]
#[inline]
pub fn is_ascii_alphanumeric(&self) -> bool {
self.iter().all(|b| b.is_ascii_alphanumeric())
}

/// Checks if all bytes of this slice are ASCII decimal digit:
/// U+0030 '0' ... U+0039 '9'.
#[unstable(feature = "ascii_ctype", issue = "39658")]
#[inline]
pub fn is_ascii_digit(&self) -> bool {
self.iter().all(|b| b.is_ascii_digit())
}

/// Checks if all bytes of this slice are ASCII hexadecimal digits:
///
/// - U+0030 '0' ... U+0039 '9', or
/// - U+0041 'A' ... U+0046 'F', or
/// - U+0061 'a' ... U+0066 'f'.
#[unstable(feature = "ascii_ctype", issue = "39658")]
#[inline]
pub fn is_ascii_hexdigit(&self) -> bool {
self.iter().all(|b| b.is_ascii_hexdigit())
}

/// Checks if all bytes of this slice are ASCII punctuation characters:
///
/// - U+0021 ... U+002F `! " # $ % & ' ( ) * + , - . /`, or
/// - U+003A ... U+0040 `: ; < = > ? @`, or
/// - U+005B ... U+0060 `[ \\ ] ^ _ \``, or
/// - U+007B ... U+007E `{ | } ~`
#[unstable(feature = "ascii_ctype", issue = "39658")]
#[inline]
pub fn is_ascii_punctuation(&self) -> bool {
self.iter().all(|b| b.is_ascii_punctuation())
}

/// Checks if all bytes of this slice are ASCII graphic characters:
/// U+0021 '@' ... U+007E '~'.
#[unstable(feature = "ascii_ctype", issue = "39658")]
#[inline]
pub fn is_ascii_graphic(&self) -> bool {
self.iter().all(|b| b.is_ascii_graphic())
}

/// Checks if all bytes of this slice are ASCII whitespace characters:
/// U+0020 SPACE, U+0009 HORIZONTAL TAB, U+000A LINE FEED,
/// U+000C FORM FEED, or U+000D CARRIAGE RETURN.
///
/// Rust uses the WhatWG Infra Standard's [definition of ASCII
/// whitespace][infra-aw]. There are several other definitions in
/// wide use. For instance, [the POSIX locale][pct] includes
/// U+000B VERTICAL TAB as well as all the above characters,
/// but—from the very same specification—[the default rule for
/// "field splitting" in the Bourne shell][bfs] considers *only*
/// SPACE, HORIZONTAL TAB, and LINE FEED as whitespace.
///
/// If you are writing a program that will process an existing
/// file format, check what that format's definition of whitespace is
/// before using this function.
///
/// [infra-aw]: https://infra.spec.whatwg.org/#ascii-whitespace
/// [pct]: http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap07.html#tag_07_03_01
/// [bfs]: http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_06_05
#[unstable(feature = "ascii_ctype", issue = "39658")]
#[inline]
pub fn is_ascii_whitespace(&self) -> bool {
self.iter().all(|b| b.is_ascii_whitespace())
}

/// Checks if all bytes of this slice are ASCII control characters:
///
/// - U+0000 NUL ... U+001F UNIT SEPARATOR, or
/// - U+007F DELETE.
///
/// Note that most ASCII whitespace characters are control
/// characters, but SPACE is not.
#[unstable(feature = "ascii_ctype", issue = "39658")]
#[inline]
pub fn is_ascii_control(&self) -> bool {
self.iter().all(|b| b.is_ascii_control())
}
}

////////////////////////////////////////////////////////////////////////////////
Expand Down
147 changes: 0 additions & 147 deletions src/liballoc/str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2199,153 +2199,6 @@ impl str {
let me = unsafe { self.as_bytes_mut() };
me.make_ascii_lowercase()
}

/// Checks if all characters of this string are ASCII alphabetic
/// characters:
///
/// - U+0041 'A' ... U+005A 'Z', or
/// - U+0061 'a' ... U+007A 'z'.
#[unstable(feature = "ascii_ctype", issue = "39658")]
#[inline]
pub fn is_ascii_alphabetic(&self) -> bool {
self.bytes().all(|b| b.is_ascii_alphabetic())
}

/// Checks if all characters of this string are ASCII uppercase characters:
/// U+0041 'A' ... U+005A 'Z'.
///
/// # Example
///
/// ```
/// #![feature(ascii_ctype)]
///
/// // Only ascii uppercase characters
/// assert!("HELLO".is_ascii_uppercase());
///
/// // While all characters are ascii, 'y' and 'e' are not uppercase
/// assert!(!"Bye".is_ascii_uppercase());
///
/// // While all characters are uppercase, 'Ü' is not ascii
/// assert!(!"TSCHÜSS".is_ascii_uppercase());
/// ```
#[unstable(feature = "ascii_ctype", issue = "39658")]
#[inline]
pub fn is_ascii_uppercase(&self) -> bool {
self.bytes().all(|b| b.is_ascii_uppercase())
}

/// Checks if all characters of this string are ASCII lowercase characters:
/// U+0061 'a' ... U+007A 'z'.
///
/// # Example
///
/// ```
/// #![feature(ascii_ctype)]
///
/// // Only ascii uppercase characters
/// assert!("hello".is_ascii_lowercase());
///
/// // While all characters are ascii, 'B' is not lowercase
/// assert!(!"Bye".is_ascii_lowercase());
///
/// // While all characters are lowercase, 'Ü' is not ascii
/// assert!(!"tschüss".is_ascii_lowercase());
/// ```
#[unstable(feature = "ascii_ctype", issue = "39658")]
#[inline]
pub fn is_ascii_lowercase(&self) -> bool {
self.bytes().all(|b| b.is_ascii_lowercase())
}

/// Checks if all characters of this string are ASCII alphanumeric
/// characters:
///
/// - U+0041 'A' ... U+005A 'Z', or
/// - U+0061 'a' ... U+007A 'z', or
/// - U+0030 '0' ... U+0039 '9'.
#[unstable(feature = "ascii_ctype", issue = "39658")]
#[inline]
pub fn is_ascii_alphanumeric(&self) -> bool {
self.bytes().all(|b| b.is_ascii_alphanumeric())
}

/// Checks if all characters of this string are ASCII decimal digit:
/// U+0030 '0' ... U+0039 '9'.
#[unstable(feature = "ascii_ctype", issue = "39658")]
#[inline]
pub fn is_ascii_digit(&self) -> bool {
self.bytes().all(|b| b.is_ascii_digit())
}

/// Checks if all characters of this string are ASCII hexadecimal digits:
///
/// - U+0030 '0' ... U+0039 '9', or
/// - U+0041 'A' ... U+0046 'F', or
/// - U+0061 'a' ... U+0066 'f'.
#[unstable(feature = "ascii_ctype", issue = "39658")]
#[inline]
pub fn is_ascii_hexdigit(&self) -> bool {
self.bytes().all(|b| b.is_ascii_hexdigit())
}

/// Checks if all characters of this string are ASCII punctuation
/// characters:
///
/// - U+0021 ... U+002F `! " # $ % & ' ( ) * + , - . /`, or
/// - U+003A ... U+0040 `: ; < = > ? @`, or
/// - U+005B ... U+0060 ``[ \ ] ^ _ ` ``, or
/// - U+007B ... U+007E `{ | } ~`
#[unstable(feature = "ascii_ctype", issue = "39658")]
#[inline]
pub fn is_ascii_punctuation(&self) -> bool {
self.bytes().all(|b| b.is_ascii_punctuation())
}

/// Checks if all characters of this string are ASCII graphic characters:
/// U+0021 '@' ... U+007E '~'.
#[unstable(feature = "ascii_ctype", issue = "39658")]
#[inline]
pub fn is_ascii_graphic(&self) -> bool {
self.bytes().all(|b| b.is_ascii_graphic())
}

/// Checks if all characters of this string are ASCII whitespace characters:
/// U+0020 SPACE, U+0009 HORIZONTAL TAB, U+000A LINE FEED,
/// U+000C FORM FEED, or U+000D CARRIAGE RETURN.
///
/// Rust uses the WhatWG Infra Standard's [definition of ASCII
/// whitespace][infra-aw]. There are several other definitions in
/// wide use. For instance, [the POSIX locale][pct] includes
/// U+000B VERTICAL TAB as well as all the above characters,
/// but—from the very same specification—[the default rule for
/// "field splitting" in the Bourne shell][bfs] considers *only*
/// SPACE, HORIZONTAL TAB, and LINE FEED as whitespace.
///
/// If you are writing a program that will process an existing
/// file format, check what that format's definition of whitespace is
/// before using this function.
///
/// [infra-aw]: https://infra.spec.whatwg.org/#ascii-whitespace
/// [pct]: http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap07.html#tag_07_03_01
/// [bfs]: http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_06_05
#[unstable(feature = "ascii_ctype", issue = "39658")]
#[inline]
pub fn is_ascii_whitespace(&self) -> bool {
self.bytes().all(|b| b.is_ascii_whitespace())
}

/// Checks if all characters of this string are ASCII control characters:
///
/// - U+0000 NUL ... U+001F UNIT SEPARATOR, or
/// - U+007F DELETE.
///
/// Note that most ASCII whitespace characters are control
/// characters, but SPACE is not.
#[unstable(feature = "ascii_ctype", issue = "39658")]
#[inline]
pub fn is_ascii_control(&self) -> bool {
self.bytes().all(|b| b.is_ascii_control())
}
}

/// Converts a boxed slice of bytes to a boxed string slice without checking
Expand Down
20 changes: 10 additions & 10 deletions src/libcore/num/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2420,7 +2420,7 @@ impl u8 {
/// assert!(!lf.is_ascii_alphabetic());
/// assert!(!esc.is_ascii_alphabetic());
/// ```
#[unstable(feature = "ascii_ctype", issue = "39658")]
#[stable(feature = "ascii_ctype_on_intrinsics", since = "1.24.0")]
#[inline]
pub fn is_ascii_alphabetic(&self) -> bool {
if *self >= 0x80 { return false; }
Expand Down Expand Up @@ -2458,7 +2458,7 @@ impl u8 {
/// assert!(!lf.is_ascii_uppercase());
/// assert!(!esc.is_ascii_uppercase());
/// ```
#[unstable(feature = "ascii_ctype", issue = "39658")]
#[stable(feature = "ascii_ctype_on_intrinsics", since = "1.24.0")]
#[inline]
pub fn is_ascii_uppercase(&self) -> bool {
if *self >= 0x80 { return false }
Expand Down Expand Up @@ -2496,7 +2496,7 @@ impl u8 {
/// assert!(!lf.is_ascii_lowercase());
/// assert!(!esc.is_ascii_lowercase());
/// ```
#[unstable(feature = "ascii_ctype", issue = "39658")]
#[stable(feature = "ascii_ctype_on_intrinsics", since = "1.24.0")]
#[inline]
pub fn is_ascii_lowercase(&self) -> bool {
if *self >= 0x80 { return false }
Expand Down Expand Up @@ -2537,7 +2537,7 @@ impl u8 {
/// assert!(!lf.is_ascii_alphanumeric());
/// assert!(!esc.is_ascii_alphanumeric());
/// ```
#[unstable(feature = "ascii_ctype", issue = "39658")]
#[stable(feature = "ascii_ctype_on_intrinsics", since = "1.24.0")]
#[inline]
pub fn is_ascii_alphanumeric(&self) -> bool {
if *self >= 0x80 { return false }
Expand Down Expand Up @@ -2575,7 +2575,7 @@ impl u8 {
/// assert!(!lf.is_ascii_digit());
/// assert!(!esc.is_ascii_digit());
/// ```
#[unstable(feature = "ascii_ctype", issue = "39658")]
#[stable(feature = "ascii_ctype_on_intrinsics", since = "1.24.0")]
#[inline]
pub fn is_ascii_digit(&self) -> bool {
if *self >= 0x80 { return false }
Expand Down Expand Up @@ -2616,7 +2616,7 @@ impl u8 {
/// assert!(!lf.is_ascii_hexdigit());
/// assert!(!esc.is_ascii_hexdigit());
/// ```
#[unstable(feature = "ascii_ctype", issue = "39658")]
#[stable(feature = "ascii_ctype_on_intrinsics", since = "1.24.0")]
#[inline]
pub fn is_ascii_hexdigit(&self) -> bool {
if *self >= 0x80 { return false }
Expand Down Expand Up @@ -2658,7 +2658,7 @@ impl u8 {
/// assert!(!lf.is_ascii_punctuation());
/// assert!(!esc.is_ascii_punctuation());
/// ```
#[unstable(feature = "ascii_ctype", issue = "39658")]
#[stable(feature = "ascii_ctype_on_intrinsics", since = "1.24.0")]
#[inline]
pub fn is_ascii_punctuation(&self) -> bool {
if *self >= 0x80 { return false }
Expand Down Expand Up @@ -2696,7 +2696,7 @@ impl u8 {
/// assert!(!lf.is_ascii_graphic());
/// assert!(!esc.is_ascii_graphic());
/// ```
#[unstable(feature = "ascii_ctype", issue = "39658")]
#[stable(feature = "ascii_ctype_on_intrinsics", since = "1.24.0")]
#[inline]
pub fn is_ascii_graphic(&self) -> bool {
if *self >= 0x80 { return false; }
Expand Down Expand Up @@ -2751,7 +2751,7 @@ impl u8 {
/// assert!(lf.is_ascii_whitespace());
/// assert!(!esc.is_ascii_whitespace());
/// ```
#[unstable(feature = "ascii_ctype", issue = "39658")]
#[stable(feature = "ascii_ctype_on_intrinsics", since = "1.24.0")]
#[inline]
pub fn is_ascii_whitespace(&self) -> bool {
if *self >= 0x80 { return false; }
Expand Down Expand Up @@ -2791,7 +2791,7 @@ impl u8 {
/// assert!(lf.is_ascii_control());
/// assert!(esc.is_ascii_control());
/// ```
#[unstable(feature = "ascii_ctype", issue = "39658")]
#[stable(feature = "ascii_ctype_on_intrinsics", since = "1.24.0")]
#[inline]
pub fn is_ascii_control(&self) -> bool {
if *self >= 0x80 { return false; }
Expand Down
Loading