Skip to content

Commit

Permalink
Rollup merge of rust-lang#49381 - withoutboats:str_unicode, r=SimonSapin
Browse files Browse the repository at this point in the history
Add is_whitespace and is_alphanumeric to str.

The other methods from `UnicodeStr` are already stable inherent
methods on str, but these have not been included.

r? @SimonSapin
  • Loading branch information
kennytm authored Mar 27, 2018
2 parents dbd6c56 + 5fc7e0a commit 1c45f6c
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 2 deletions.
42 changes: 42 additions & 0 deletions src/liballoc/str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2122,6 +2122,48 @@ impl str {
unsafe { String::from_utf8_unchecked(buf) }
}

/// Returns true if this `str` is entirely whitespace, and false otherwise.
///
/// 'Whitespace' is defined according to the terms of the Unicode Derived Core
/// Property `White_Space`.
///
/// # Examples
///
/// Basic usage:
///
/// ```
/// assert!(" \t ".is_whitespace());
///
/// // a non-breaking space
/// assert!("\u{A0}".is_whitespace());
///
/// assert!(!" 越".is_whitespace());
/// ```
#[stable(feature = "unicode_methods_on_intrinsics", since = "1.27.0")]
#[inline]
pub fn is_whitespace(&self) -> bool {
UnicodeStr::is_whitespace(self)
}

/// Returns true if this `str` is entirely alphanumeric, and false otherwise.
///
/// 'Alphanumeric'-ness is defined in terms of the Unicode General Categories
/// 'Nd', 'Nl', 'No' and the Derived Core Property 'Alphabetic'.
///
/// # Examples
///
/// Basic usage:
///
/// ```
/// assert!("٣7৬Kو藏".is_alphanumeric());
/// assert!(!"¾①".is_alphanumeric());
/// ```
#[stable(feature = "unicode_methods_on_intrinsics", since = "1.27.0")]
#[inline]
pub fn is_alphanumeric(&self) -> bool {
UnicodeStr::is_alphanumeric(self)
}

/// Checks if all characters in this string are within the ASCII range.
///
/// # Examples
Expand Down
2 changes: 0 additions & 2 deletions src/librustdoc/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -406,8 +406,6 @@ pub fn make_test(s: &str,

// FIXME(aburka): use a real parser to deal with multiline attributes
fn partition_source(s: &str) -> (String, String) {
use std_unicode::str::UnicodeStr;

let mut after_header = false;
let mut before = String::new();
let mut after = String::new();
Expand Down

0 comments on commit 1c45f6c

Please sign in to comment.