Skip to content
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
22 changes: 22 additions & 0 deletions examples/char_methods.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
use cheetah_string::CheetahString;

fn main() {
let s = CheetahString::from("hello world");

// Use starts_with_char method to check characters
println!("starts_with_char('h'): {}", s.starts_with_char('h'));
println!("starts_with_char('+'): {}", s.starts_with_char('+'));

// Use ends_with_char method to check characters
println!("ends_with_char('d'): {}", s.ends_with_char('d'));
println!("ends_with_char('+'): {}", s.ends_with_char('+'));

// Use contains_char method to check characters
println!("contains_char('o'): {}", s.contains_char('o'));
println!("contains_char('+'): {}", s.contains_char('+'));

// Original methods still work with strings
println!("starts_with(\"hello\"): {}", s.starts_with("hello"));
println!("ends_with(\"world\"): {}", s.ends_with("world"));
println!("contains(\"llo\"): {}", s.contains("llo"));
}
48 changes: 48 additions & 0 deletions src/cheetah_string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,22 @@ impl CheetahString {
self.as_str().starts_with(pat.as_ref())
}

/// Returns `true` if the string starts with the given character.
///
/// # Examples
///
/// ```
/// use cheetah_string::CheetahString;
///
/// let s = CheetahString::from("hello world");
/// assert!(s.starts_with_char('h'));
/// assert!(!s.starts_with_char('w'));
/// ```
#[inline]
pub fn starts_with_char(&self, pat: char) -> bool {
self.as_str().starts_with(pat)
}

/// Returns `true` if the string ends with the given pattern.
///
/// # Examples
Expand All @@ -484,6 +500,22 @@ impl CheetahString {
self.as_str().ends_with(pat.as_ref())
}

/// Returns `true` if the string ends with the given character.
///
/// # Examples
///
/// ```
/// use cheetah_string::CheetahString;
///
/// let s = CheetahString::from("hello world");
/// assert!(s.ends_with_char('d'));
/// assert!(!s.ends_with_char('h'));
/// ```
#[inline]
pub fn ends_with_char(&self, pat: char) -> bool {
self.as_str().ends_with(pat)
}

/// Returns `true` if the string contains the given pattern.
///
/// # Examples
Expand All @@ -500,6 +532,22 @@ impl CheetahString {
self.as_str().contains(pat.as_ref())
}

/// Returns `true` if the string contains the given character.
///
/// # Examples
///
/// ```
/// use cheetah_string::CheetahString;
///
/// let s = CheetahString::from("hello world");
/// assert!(s.contains_char('o'));
/// assert!(!s.contains_char('x'));
/// ```
#[inline]
pub fn contains_char(&self, pat: char) -> bool {
self.as_str().contains(pat)
}

/// Returns the byte index of the first occurrence of the pattern, or `None` if not found.
///
/// # Examples
Expand Down
Loading