diff --git a/rustfmt.toml b/rustfmt.toml new file mode 100644 index 0000000..17a3f97 --- /dev/null +++ b/rustfmt.toml @@ -0,0 +1,10 @@ +edition = "2021" +tab_spaces = 4 +unstable_features = true +condense_wildcard_suffixes = true +newline_style = "Unix" +use_field_init_shorthand = true +use_try_shorthand = true +imports_granularity = "Crate" +group_imports = "StdExternalCrate" +reorder_imports = true diff --git a/src/segment.rs b/src/segment.rs index 592a047..0ef9c9d 100644 --- a/src/segment.rs +++ b/src/segment.rs @@ -1,7 +1,9 @@ -use crate::error::{Error, Result}; -use proc_macro::{token_stream, Delimiter, Ident, Span, TokenTree}; use std::iter::Peekable; +use proc_macro::{token_stream, Delimiter, Ident, Span, TokenTree}; + +use crate::error::{Error, Result}; + pub(crate) enum Segment { String(LitStr), Apostrophe(Span), @@ -192,6 +194,31 @@ pub(crate) fn paste(segments: &[Segment]) -> Result { } evaluated.push(acc.to_lowercase()); } + "lowerCamel" => { + let mut acc = String::new(); + let mut prev = '_'; + for (idx, ch) in last.chars().enumerate() { + if idx == 0 { + for chl in ch.to_lowercase() { + acc.push(chl); + } + } else if ch != '_' { + if prev == '_' { + for chu in ch.to_uppercase() { + acc.push(chu); + } + } else if prev.is_uppercase() { + for chl in ch.to_lowercase() { + acc.push(chl); + } + } else { + acc.push(ch); + } + } + prev = ch; + } + evaluated.push(acc); + } "camel" => { let mut acc = String::new(); let mut prev = '_';