Skip to content

add is_alphabetic to the UnicodeStrPrelude trait #19550

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

Closed
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
18 changes: 18 additions & 0 deletions src/libunicode/u_str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,21 @@ pub trait UnicodeStrPrelude for Sized? {
/// ```
fn is_whitespace(&self) -> bool;

/// Returns true if the string contains only alphabetic code
/// points.
///
/// Alphabetic characters are determined by `char::is_alphabetic`.
///
/// # Example
///
/// ```rust
/// assert!("Löwe老虎Léopard".is_alphabetic());
/// assert!("".is_alphabetic());
///
/// assert!( !" &*~".is_alphabetic());
/// ```
fn is_alphabetic(&self) -> bool;

/// Returns true if the string contains only alphanumeric code
/// points.
///
Expand Down Expand Up @@ -149,6 +164,9 @@ impl UnicodeStrPrelude for str {
#[inline]
fn is_whitespace(&self) -> bool { self.chars().all(|c| c.is_whitespace()) }

#[inline]
fn is_alphabetic(&self) -> bool { self.chars().all(|c| c.is_alphabetic()) }

#[inline]
fn is_alphanumeric(&self) -> bool { self.chars().all(|c| c.is_alphanumeric()) }

Expand Down