1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
pub use const_str_proc_macro::convert_case;
/// Converts a string literal to a specified case.
///
/// These variants require the feature `case`.
///
/// + camel
/// + kebab
/// + snake
/// + shouty_snake
/// + shouty_kebab
///
// #[doc = convert_case_doc!() ] // stable since 1.54
#[cfg(not(feature = "case"))]
#[macro_export]
macro_rules! convert_case {
(lower, $s: literal) => {
$crate::__proc::to_lowercase!($s)
};
(upper, $s: literal) => {
$crate::__proc::to_uppercase!($s)
};
}
/// Converts a string literal to a specified case.
///
/// These variants require the feature `case`.
///
/// + camel
/// + kebab
/// + snake
/// + shouty_snake
/// + shouty_kebab
///
/// # Examples
/// ```
/// use const_str::convert_case;
///
/// const S1: &str = convert_case!(lower, "Lower Case");
/// const S2: &str = convert_case!(upper, "Upper Case");
/// # #[cfg(feature = "case")]
/// const S3: &str = convert_case!(camel, "camel case");
/// # #[cfg(feature = "case")]
/// const S4: &str = convert_case!(snake, "snake case");
/// # #[cfg(feature = "case")]
/// const S5: &str = convert_case!(kebab, "kebab case");
/// # #[cfg(feature = "case")]
/// const S6: &str = convert_case!(shouty_snake, "shouty snake case");
/// # #[cfg(feature = "case")]
/// const S7: &str = convert_case!(shouty_kebab, "shouty kebab case");
///
/// assert_eq!(S1, "lower case");
/// assert_eq!(S2, "UPPER CASE");
/// # #[cfg(feature = "case")]
/// assert_eq!(S3, "CamelCase");
/// # #[cfg(feature = "case")]
/// assert_eq!(S4, "snake_case");
/// # #[cfg(feature = "case")]
/// assert_eq!(S5, "kebab-case");
/// # #[cfg(feature = "case")]
/// assert_eq!(S6, "SHOUTY_SNAKE_CASE");
/// # #[cfg(feature = "case")]
/// assert_eq!(S7, "SHOUTY-KEBAB-CASE");
/// ```
#[cfg(feature = "case")]
#[macro_export]
macro_rules! convert_case {
(lower, $s: literal) => {
$crate::__proc::convert_case!(lower, $s)
};
(upper, $s: literal) => {
$crate::__proc::convert_case!(upper, $s)
};
(camel, $s: literal) => {
$crate::__proc::convert_case!(camel, $s)
};
(snake, $s: literal) => {
$crate::__proc::convert_case!(snake, $s)
};
(kebab, $s: literal) => {
$crate::__proc::convert_case!(kebab, $s)
};
(shouty_snake, $s: literal) => {
$crate::__proc::convert_case!(shouty_snake, $s)
};
(shouty_kebab, $s: literal) => {
$crate::__proc::convert_case!(shouty_kebab, $s)
};
}