Skip to content
This repository has been archived by the owner on Oct 6, 2024. It is now read-only.

Commit

Permalink
add lowerCamel
Browse files Browse the repository at this point in the history
  • Loading branch information
iuser committed Aug 13, 2022
1 parent 7480d0a commit 7392338
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 2 deletions.
10 changes: 10 additions & 0 deletions rustfmt.toml
Original file line number Diff line number Diff line change
@@ -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
31 changes: 29 additions & 2 deletions src/segment.rs
Original file line number Diff line number Diff line change
@@ -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),
Expand Down Expand Up @@ -192,6 +194,31 @@ pub(crate) fn paste(segments: &[Segment]) -> Result<String> {
}
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 = '_';
Expand Down

0 comments on commit 7392338

Please sign in to comment.