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

add lowerCamel #84

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
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