From d2af1fc00436b4ab5110a3bef88a4a415fac6a82 Mon Sep 17 00:00:00 2001 From: Paul Woolcock Date: Thu, 4 Dec 2014 21:38:43 -0500 Subject: [PATCH] add `is_alphabetic` to the UnicodeStrPrelude trait --- src/libunicode/u_str.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/libunicode/u_str.rs b/src/libunicode/u_str.rs index a5f7614257595..61787520a9580 100644 --- a/src/libunicode/u_str.rs +++ b/src/libunicode/u_str.rs @@ -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. /// @@ -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()) }