diff options
Diffstat (limited to 'crates/stdx')
-rw-r--r-- | crates/stdx/src/lib.rs | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/crates/stdx/src/lib.rs b/crates/stdx/src/lib.rs index 011935cad..522a9c1ab 100644 --- a/crates/stdx/src/lib.rs +++ b/crates/stdx/src/lib.rs | |||
@@ -32,8 +32,12 @@ pub fn to_lower_snake_case(s: &str) -> String { | |||
32 | let mut buf = String::with_capacity(s.len()); | 32 | let mut buf = String::with_capacity(s.len()); |
33 | let mut prev = false; | 33 | let mut prev = false; |
34 | for c in s.chars() { | 34 | for c in s.chars() { |
35 | // `&& prev` is required to not insert `_` before the first symbol. | ||
35 | if c.is_ascii_uppercase() && prev { | 36 | if c.is_ascii_uppercase() && prev { |
36 | buf.push('_') | 37 | // This check is required to not translate `Weird_Case` into `weird__case`. |
38 | if buf.chars().last() != Some('_') { | ||
39 | buf.push('_') | ||
40 | } | ||
37 | } | 41 | } |
38 | prev = true; | 42 | prev = true; |
39 | 43 | ||