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

Commit 7392338

Browse files
author
iuser
committed
add lowerCamel
1 parent 7480d0a commit 7392338

File tree

2 files changed

+39
-2
lines changed

2 files changed

+39
-2
lines changed

rustfmt.toml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
edition = "2021"
2+
tab_spaces = 4
3+
unstable_features = true
4+
condense_wildcard_suffixes = true
5+
newline_style = "Unix"
6+
use_field_init_shorthand = true
7+
use_try_shorthand = true
8+
imports_granularity = "Crate"
9+
group_imports = "StdExternalCrate"
10+
reorder_imports = true

src/segment.rs

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
use crate::error::{Error, Result};
2-
use proc_macro::{token_stream, Delimiter, Ident, Span, TokenTree};
31
use std::iter::Peekable;
42

3+
use proc_macro::{token_stream, Delimiter, Ident, Span, TokenTree};
4+
5+
use crate::error::{Error, Result};
6+
57
pub(crate) enum Segment {
68
String(LitStr),
79
Apostrophe(Span),
@@ -192,6 +194,31 @@ pub(crate) fn paste(segments: &[Segment]) -> Result<String> {
192194
}
193195
evaluated.push(acc.to_lowercase());
194196
}
197+
"lowerCamel" => {
198+
let mut acc = String::new();
199+
let mut prev = '_';
200+
for (idx, ch) in last.chars().enumerate() {
201+
if idx == 0 {
202+
for chl in ch.to_lowercase() {
203+
acc.push(chl);
204+
}
205+
} else if ch != '_' {
206+
if prev == '_' {
207+
for chu in ch.to_uppercase() {
208+
acc.push(chu);
209+
}
210+
} else if prev.is_uppercase() {
211+
for chl in ch.to_lowercase() {
212+
acc.push(chl);
213+
}
214+
} else {
215+
acc.push(ch);
216+
}
217+
}
218+
prev = ch;
219+
}
220+
evaluated.push(acc);
221+
}
195222
"camel" => {
196223
let mut acc = String::new();
197224
let mut prev = '_';

0 commit comments

Comments
 (0)