Struct ncase::Words

source ·
pub struct Words<'a> { /* private fields */ }
Expand description

Sequence of words of some original string.

Divides the case style “enforcement” into two steps:

  1. Split the original string into words.
  2. Capitalise and concatenate the words into a new string.

Implementations§

source§

impl<'a> Words<'a>

source

pub fn with_separator(s: &'a str, sep: &Regex) -> Words<'a>

Creates a new Words of the string slice using the separator regex to split it.

source

pub fn camel(&self) -> String

Returns the words capitalised and concatenated like camelCase as a new String.

source

pub fn pascal(&self) -> String

Returns the words capitalised and concatenated like PascalCase as a new String.

source

pub fn kebab(&self) -> String

Returns the words capitalised and concatenated like kebab-case as a new String.

source

pub fn screaming_kebab(&self) -> String

Returns the words capitalised and concatenated like SCREAMING-KEBAB-CASE as a new String.

source

pub fn lower(&self) -> String

Returns the words capitalised and concatenated like lower case as a new String.

source

pub fn upper(&self) -> String

Returns the words capitalised and concatenated like UPPER CASE as a new String.

source

pub fn snake(&self) -> String

Returns the words capitalised and concatenated like snake_case as a new String.

source

pub fn screaming_snake(&self) -> String

Returns the words capitalised and concatenated like SCREAMING_SNAKE_CASE as a new String.

source

pub fn title(&self) -> String

Returns the words capitalised and concatenated like Title Case as a new String.

source

pub fn toggle(&self) -> String

Returns the words capitalised and concatenated like tOGGLE cASE as a new String.

source

pub fn random(&self) -> String

Returns the words case-randomised and concatenated with a space as a new String.

Trait Implementations§

source§

impl<'a> Debug for Words<'a>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<'a> From<&'a str> for Words<'a>

source§

fn from(s: &'a str) -> Self

Creates a new Words for the string slice.

The string is split into words by the following algorithm:

  1. Trim the string.
  2. If the string contains whitespace, then split it by whitespace.
  3. If the string contains hyphens ‘-’ or underscores ‘_’, then split it by whichever of them is more frequent.
  4. Split the string by case changes: ‘*|Az’ and ‘z|A*’.

Auto Trait Implementations§

§

impl<'a> Freeze for Words<'a>

§

impl<'a> RefUnwindSafe for Words<'a>

§

impl<'a> Send for Words<'a>

§

impl<'a> Sync for Words<'a>

§

impl<'a> Unpin for Words<'a>

§

impl<'a> UnwindSafe for Words<'a>

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

source§

fn vzip(self) -> V