Skip to content

Commit 963ab91

Browse files
authored
Rollup merge of rust-lang#46077 - LukasKalbertodt:stabilize-ascii-ctype, r=alexcrichton
Stabilize some `ascii_ctype` methods As discussed in rust-lang#39658, this PR stabilizes those methods for `u8` and `char`. All inherent `ascii_ctype` for `[u8]` and `str` are removed as we prefer the more explicit version `s.chars().all(|c| c.is_ascii_())`. This PR doesn't modify the `AsciiExt` trait. There, the `ascii_ctype` methods are still unstable. It is planned to remove those in the future (I think). I had to modify some code in `ascii.rs` to properly implement `AsciiExt` for all types. Fixes rust-lang#39658.
2 parents 0ec3aee + c5aad96 commit 963ab91

File tree

5 files changed

+186
-324
lines changed

5 files changed

+186
-324
lines changed

src/liballoc/slice.rs

Lines changed: 0 additions & 114 deletions
Original file line numberDiff line numberDiff line change
@@ -1626,120 +1626,6 @@ impl [u8] {
16261626
byte.make_ascii_lowercase();
16271627
}
16281628
}
1629-
1630-
/// Checks if all bytes of this slice are ASCII alphabetic characters:
1631-
///
1632-
/// - U+0041 'A' ... U+005A 'Z', or
1633-
/// - U+0061 'a' ... U+007A 'z'.
1634-
#[unstable(feature = "ascii_ctype", issue = "39658")]
1635-
#[inline]
1636-
pub fn is_ascii_alphabetic(&self) -> bool {
1637-
self.iter().all(|b| b.is_ascii_alphabetic())
1638-
}
1639-
1640-
/// Checks if all bytes of this slice are ASCII uppercase characters:
1641-
/// U+0041 'A' ... U+005A 'Z'.
1642-
#[unstable(feature = "ascii_ctype", issue = "39658")]
1643-
#[inline]
1644-
pub fn is_ascii_uppercase(&self) -> bool {
1645-
self.iter().all(|b| b.is_ascii_uppercase())
1646-
}
1647-
1648-
/// Checks if all bytes of this slice are ASCII lowercase characters:
1649-
/// U+0061 'a' ... U+007A 'z'.
1650-
#[unstable(feature = "ascii_ctype", issue = "39658")]
1651-
#[inline]
1652-
pub fn is_ascii_lowercase(&self) -> bool {
1653-
self.iter().all(|b| b.is_ascii_lowercase())
1654-
}
1655-
1656-
/// Checks if all bytes of this slice are ASCII alphanumeric characters:
1657-
///
1658-
/// - U+0041 'A' ... U+005A 'Z', or
1659-
/// - U+0061 'a' ... U+007A 'z', or
1660-
/// - U+0030 '0' ... U+0039 '9'.
1661-
#[unstable(feature = "ascii_ctype", issue = "39658")]
1662-
#[inline]
1663-
pub fn is_ascii_alphanumeric(&self) -> bool {
1664-
self.iter().all(|b| b.is_ascii_alphanumeric())
1665-
}
1666-
1667-
/// Checks if all bytes of this slice are ASCII decimal digit:
1668-
/// U+0030 '0' ... U+0039 '9'.
1669-
#[unstable(feature = "ascii_ctype", issue = "39658")]
1670-
#[inline]
1671-
pub fn is_ascii_digit(&self) -> bool {
1672-
self.iter().all(|b| b.is_ascii_digit())
1673-
}
1674-
1675-
/// Checks if all bytes of this slice are ASCII hexadecimal digits:
1676-
///
1677-
/// - U+0030 '0' ... U+0039 '9', or
1678-
/// - U+0041 'A' ... U+0046 'F', or
1679-
/// - U+0061 'a' ... U+0066 'f'.
1680-
#[unstable(feature = "ascii_ctype", issue = "39658")]
1681-
#[inline]
1682-
pub fn is_ascii_hexdigit(&self) -> bool {
1683-
self.iter().all(|b| b.is_ascii_hexdigit())
1684-
}
1685-
1686-
/// Checks if all bytes of this slice are ASCII punctuation characters:
1687-
///
1688-
/// - U+0021 ... U+002F `! " # $ % & ' ( ) * + , - . /`, or
1689-
/// - U+003A ... U+0040 `: ; < = > ? @`, or
1690-
/// - U+005B ... U+0060 `[ \\ ] ^ _ \``, or
1691-
/// - U+007B ... U+007E `{ | } ~`
1692-
#[unstable(feature = "ascii_ctype", issue = "39658")]
1693-
#[inline]
1694-
pub fn is_ascii_punctuation(&self) -> bool {
1695-
self.iter().all(|b| b.is_ascii_punctuation())
1696-
}
1697-
1698-
/// Checks if all bytes of this slice are ASCII graphic characters:
1699-
/// U+0021 '@' ... U+007E '~'.
1700-
#[unstable(feature = "ascii_ctype", issue = "39658")]
1701-
#[inline]
1702-
pub fn is_ascii_graphic(&self) -> bool {
1703-
self.iter().all(|b| b.is_ascii_graphic())
1704-
}
1705-
1706-
/// Checks if all bytes of this slice are ASCII whitespace characters:
1707-
/// U+0020 SPACE, U+0009 HORIZONTAL TAB, U+000A LINE FEED,
1708-
/// U+000C FORM FEED, or U+000D CARRIAGE RETURN.
1709-
///
1710-
/// Rust uses the WhatWG Infra Standard's [definition of ASCII
1711-
/// whitespace][infra-aw]. There are several other definitions in
1712-
/// wide use. For instance, [the POSIX locale][pct] includes
1713-
/// U+000B VERTICAL TAB as well as all the above characters,
1714-
/// but—from the very same specification—[the default rule for
1715-
/// "field splitting" in the Bourne shell][bfs] considers *only*
1716-
/// SPACE, HORIZONTAL TAB, and LINE FEED as whitespace.
1717-
///
1718-
/// If you are writing a program that will process an existing
1719-
/// file format, check what that format's definition of whitespace is
1720-
/// before using this function.
1721-
///
1722-
/// [infra-aw]: https://infra.spec.whatwg.org/#ascii-whitespace
1723-
/// [pct]: http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap07.html#tag_07_03_01
1724-
/// [bfs]: http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_06_05
1725-
#[unstable(feature = "ascii_ctype", issue = "39658")]
1726-
#[inline]
1727-
pub fn is_ascii_whitespace(&self) -> bool {
1728-
self.iter().all(|b| b.is_ascii_whitespace())
1729-
}
1730-
1731-
/// Checks if all bytes of this slice are ASCII control characters:
1732-
///
1733-
/// - U+0000 NUL ... U+001F UNIT SEPARATOR, or
1734-
/// - U+007F DELETE.
1735-
///
1736-
/// Note that most ASCII whitespace characters are control
1737-
/// characters, but SPACE is not.
1738-
#[unstable(feature = "ascii_ctype", issue = "39658")]
1739-
#[inline]
1740-
pub fn is_ascii_control(&self) -> bool {
1741-
self.iter().all(|b| b.is_ascii_control())
1742-
}
17431629
}
17441630

17451631
////////////////////////////////////////////////////////////////////////////////

src/liballoc/str.rs

Lines changed: 0 additions & 147 deletions
Original file line numberDiff line numberDiff line change
@@ -2199,153 +2199,6 @@ impl str {
21992199
let me = unsafe { self.as_bytes_mut() };
22002200
me.make_ascii_lowercase()
22012201
}
2202-
2203-
/// Checks if all characters of this string are ASCII alphabetic
2204-
/// characters:
2205-
///
2206-
/// - U+0041 'A' ... U+005A 'Z', or
2207-
/// - U+0061 'a' ... U+007A 'z'.
2208-
#[unstable(feature = "ascii_ctype", issue = "39658")]
2209-
#[inline]
2210-
pub fn is_ascii_alphabetic(&self) -> bool {
2211-
self.bytes().all(|b| b.is_ascii_alphabetic())
2212-
}
2213-
2214-
/// Checks if all characters of this string are ASCII uppercase characters:
2215-
/// U+0041 'A' ... U+005A 'Z'.
2216-
///
2217-
/// # Example
2218-
///
2219-
/// ```
2220-
/// #![feature(ascii_ctype)]
2221-
///
2222-
/// // Only ascii uppercase characters
2223-
/// assert!("HELLO".is_ascii_uppercase());
2224-
///
2225-
/// // While all characters are ascii, 'y' and 'e' are not uppercase
2226-
/// assert!(!"Bye".is_ascii_uppercase());
2227-
///
2228-
/// // While all characters are uppercase, 'Ü' is not ascii
2229-
/// assert!(!"TSCHÜSS".is_ascii_uppercase());
2230-
/// ```
2231-
#[unstable(feature = "ascii_ctype", issue = "39658")]
2232-
#[inline]
2233-
pub fn is_ascii_uppercase(&self) -> bool {
2234-
self.bytes().all(|b| b.is_ascii_uppercase())
2235-
}
2236-
2237-
/// Checks if all characters of this string are ASCII lowercase characters:
2238-
/// U+0061 'a' ... U+007A 'z'.
2239-
///
2240-
/// # Example
2241-
///
2242-
/// ```
2243-
/// #![feature(ascii_ctype)]
2244-
///
2245-
/// // Only ascii uppercase characters
2246-
/// assert!("hello".is_ascii_lowercase());
2247-
///
2248-
/// // While all characters are ascii, 'B' is not lowercase
2249-
/// assert!(!"Bye".is_ascii_lowercase());
2250-
///
2251-
/// // While all characters are lowercase, 'Ü' is not ascii
2252-
/// assert!(!"tschüss".is_ascii_lowercase());
2253-
/// ```
2254-
#[unstable(feature = "ascii_ctype", issue = "39658")]
2255-
#[inline]
2256-
pub fn is_ascii_lowercase(&self) -> bool {
2257-
self.bytes().all(|b| b.is_ascii_lowercase())
2258-
}
2259-
2260-
/// Checks if all characters of this string are ASCII alphanumeric
2261-
/// characters:
2262-
///
2263-
/// - U+0041 'A' ... U+005A 'Z', or
2264-
/// - U+0061 'a' ... U+007A 'z', or
2265-
/// - U+0030 '0' ... U+0039 '9'.
2266-
#[unstable(feature = "ascii_ctype", issue = "39658")]
2267-
#[inline]
2268-
pub fn is_ascii_alphanumeric(&self) -> bool {
2269-
self.bytes().all(|b| b.is_ascii_alphanumeric())
2270-
}
2271-
2272-
/// Checks if all characters of this string are ASCII decimal digit:
2273-
/// U+0030 '0' ... U+0039 '9'.
2274-
#[unstable(feature = "ascii_ctype", issue = "39658")]
2275-
#[inline]
2276-
pub fn is_ascii_digit(&self) -> bool {
2277-
self.bytes().all(|b| b.is_ascii_digit())
2278-
}
2279-
2280-
/// Checks if all characters of this string are ASCII hexadecimal digits:
2281-
///
2282-
/// - U+0030 '0' ... U+0039 '9', or
2283-
/// - U+0041 'A' ... U+0046 'F', or
2284-
/// - U+0061 'a' ... U+0066 'f'.
2285-
#[unstable(feature = "ascii_ctype", issue = "39658")]
2286-
#[inline]
2287-
pub fn is_ascii_hexdigit(&self) -> bool {
2288-
self.bytes().all(|b| b.is_ascii_hexdigit())
2289-
}
2290-
2291-
/// Checks if all characters of this string are ASCII punctuation
2292-
/// characters:
2293-
///
2294-
/// - U+0021 ... U+002F `! " # $ % & ' ( ) * + , - . /`, or
2295-
/// - U+003A ... U+0040 `: ; < = > ? @`, or
2296-
/// - U+005B ... U+0060 ``[ \ ] ^ _ ` ``, or
2297-
/// - U+007B ... U+007E `{ | } ~`
2298-
#[unstable(feature = "ascii_ctype", issue = "39658")]
2299-
#[inline]
2300-
pub fn is_ascii_punctuation(&self) -> bool {
2301-
self.bytes().all(|b| b.is_ascii_punctuation())
2302-
}
2303-
2304-
/// Checks if all characters of this string are ASCII graphic characters:
2305-
/// U+0021 '@' ... U+007E '~'.
2306-
#[unstable(feature = "ascii_ctype", issue = "39658")]
2307-
#[inline]
2308-
pub fn is_ascii_graphic(&self) -> bool {
2309-
self.bytes().all(|b| b.is_ascii_graphic())
2310-
}
2311-
2312-
/// Checks if all characters of this string are ASCII whitespace characters:
2313-
/// U+0020 SPACE, U+0009 HORIZONTAL TAB, U+000A LINE FEED,
2314-
/// U+000C FORM FEED, or U+000D CARRIAGE RETURN.
2315-
///
2316-
/// Rust uses the WhatWG Infra Standard's [definition of ASCII
2317-
/// whitespace][infra-aw]. There are several other definitions in
2318-
/// wide use. For instance, [the POSIX locale][pct] includes
2319-
/// U+000B VERTICAL TAB as well as all the above characters,
2320-
/// but—from the very same specification—[the default rule for
2321-
/// "field splitting" in the Bourne shell][bfs] considers *only*
2322-
/// SPACE, HORIZONTAL TAB, and LINE FEED as whitespace.
2323-
///
2324-
/// If you are writing a program that will process an existing
2325-
/// file format, check what that format's definition of whitespace is
2326-
/// before using this function.
2327-
///
2328-
/// [infra-aw]: https://infra.spec.whatwg.org/#ascii-whitespace
2329-
/// [pct]: http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap07.html#tag_07_03_01
2330-
/// [bfs]: http://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_06_05
2331-
#[unstable(feature = "ascii_ctype", issue = "39658")]
2332-
#[inline]
2333-
pub fn is_ascii_whitespace(&self) -> bool {
2334-
self.bytes().all(|b| b.is_ascii_whitespace())
2335-
}
2336-
2337-
/// Checks if all characters of this string are ASCII control characters:
2338-
///
2339-
/// - U+0000 NUL ... U+001F UNIT SEPARATOR, or
2340-
/// - U+007F DELETE.
2341-
///
2342-
/// Note that most ASCII whitespace characters are control
2343-
/// characters, but SPACE is not.
2344-
#[unstable(feature = "ascii_ctype", issue = "39658")]
2345-
#[inline]
2346-
pub fn is_ascii_control(&self) -> bool {
2347-
self.bytes().all(|b| b.is_ascii_control())
2348-
}
23492202
}
23502203

23512204
/// Converts a boxed slice of bytes to a boxed string slice without checking

src/libcore/num/mod.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2438,7 +2438,7 @@ impl u8 {
24382438
/// assert!(!lf.is_ascii_alphabetic());
24392439
/// assert!(!esc.is_ascii_alphabetic());
24402440
/// ```
2441-
#[unstable(feature = "ascii_ctype", issue = "39658")]
2441+
#[stable(feature = "ascii_ctype_on_intrinsics", since = "1.24.0")]
24422442
#[inline]
24432443
pub fn is_ascii_alphabetic(&self) -> bool {
24442444
if *self >= 0x80 { return false; }
@@ -2476,7 +2476,7 @@ impl u8 {
24762476
/// assert!(!lf.is_ascii_uppercase());
24772477
/// assert!(!esc.is_ascii_uppercase());
24782478
/// ```
2479-
#[unstable(feature = "ascii_ctype", issue = "39658")]
2479+
#[stable(feature = "ascii_ctype_on_intrinsics", since = "1.24.0")]
24802480
#[inline]
24812481
pub fn is_ascii_uppercase(&self) -> bool {
24822482
if *self >= 0x80 { return false }
@@ -2514,7 +2514,7 @@ impl u8 {
25142514
/// assert!(!lf.is_ascii_lowercase());
25152515
/// assert!(!esc.is_ascii_lowercase());
25162516
/// ```
2517-
#[unstable(feature = "ascii_ctype", issue = "39658")]
2517+
#[stable(feature = "ascii_ctype_on_intrinsics", since = "1.24.0")]
25182518
#[inline]
25192519
pub fn is_ascii_lowercase(&self) -> bool {
25202520
if *self >= 0x80 { return false }
@@ -2555,7 +2555,7 @@ impl u8 {
25552555
/// assert!(!lf.is_ascii_alphanumeric());
25562556
/// assert!(!esc.is_ascii_alphanumeric());
25572557
/// ```
2558-
#[unstable(feature = "ascii_ctype", issue = "39658")]
2558+
#[stable(feature = "ascii_ctype_on_intrinsics", since = "1.24.0")]
25592559
#[inline]
25602560
pub fn is_ascii_alphanumeric(&self) -> bool {
25612561
if *self >= 0x80 { return false }
@@ -2593,7 +2593,7 @@ impl u8 {
25932593
/// assert!(!lf.is_ascii_digit());
25942594
/// assert!(!esc.is_ascii_digit());
25952595
/// ```
2596-
#[unstable(feature = "ascii_ctype", issue = "39658")]
2596+
#[stable(feature = "ascii_ctype_on_intrinsics", since = "1.24.0")]
25972597
#[inline]
25982598
pub fn is_ascii_digit(&self) -> bool {
25992599
if *self >= 0x80 { return false }
@@ -2634,7 +2634,7 @@ impl u8 {
26342634
/// assert!(!lf.is_ascii_hexdigit());
26352635
/// assert!(!esc.is_ascii_hexdigit());
26362636
/// ```
2637-
#[unstable(feature = "ascii_ctype", issue = "39658")]
2637+
#[stable(feature = "ascii_ctype_on_intrinsics", since = "1.24.0")]
26382638
#[inline]
26392639
pub fn is_ascii_hexdigit(&self) -> bool {
26402640
if *self >= 0x80 { return false }
@@ -2676,7 +2676,7 @@ impl u8 {
26762676
/// assert!(!lf.is_ascii_punctuation());
26772677
/// assert!(!esc.is_ascii_punctuation());
26782678
/// ```
2679-
#[unstable(feature = "ascii_ctype", issue = "39658")]
2679+
#[stable(feature = "ascii_ctype_on_intrinsics", since = "1.24.0")]
26802680
#[inline]
26812681
pub fn is_ascii_punctuation(&self) -> bool {
26822682
if *self >= 0x80 { return false }
@@ -2714,7 +2714,7 @@ impl u8 {
27142714
/// assert!(!lf.is_ascii_graphic());
27152715
/// assert!(!esc.is_ascii_graphic());
27162716
/// ```
2717-
#[unstable(feature = "ascii_ctype", issue = "39658")]
2717+
#[stable(feature = "ascii_ctype_on_intrinsics", since = "1.24.0")]
27182718
#[inline]
27192719
pub fn is_ascii_graphic(&self) -> bool {
27202720
if *self >= 0x80 { return false; }
@@ -2769,7 +2769,7 @@ impl u8 {
27692769
/// assert!(lf.is_ascii_whitespace());
27702770
/// assert!(!esc.is_ascii_whitespace());
27712771
/// ```
2772-
#[unstable(feature = "ascii_ctype", issue = "39658")]
2772+
#[stable(feature = "ascii_ctype_on_intrinsics", since = "1.24.0")]
27732773
#[inline]
27742774
pub fn is_ascii_whitespace(&self) -> bool {
27752775
if *self >= 0x80 { return false; }
@@ -2809,7 +2809,7 @@ impl u8 {
28092809
/// assert!(lf.is_ascii_control());
28102810
/// assert!(esc.is_ascii_control());
28112811
/// ```
2812-
#[unstable(feature = "ascii_ctype", issue = "39658")]
2812+
#[stable(feature = "ascii_ctype_on_intrinsics", since = "1.24.0")]
28132813
#[inline]
28142814
pub fn is_ascii_control(&self) -> bool {
28152815
if *self >= 0x80 { return false; }

0 commit comments

Comments
 (0)