mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-18 08:10:11 +00:00
Improve string helpers functions
This commit is contained in:
parent
21dd704b6b
commit
17f1026c46
2 changed files with 13 additions and 2 deletions
|
@ -32,8 +32,12 @@ pub fn to_lower_snake_case(s: &str) -> String {
|
|||
let mut buf = String::with_capacity(s.len());
|
||||
let mut prev = false;
|
||||
for c in s.chars() {
|
||||
// `&& prev` is required to not insert `_` before the first symbol.
|
||||
if c.is_ascii_uppercase() && prev {
|
||||
buf.push('_')
|
||||
// This check is required to not translate `Weird_Case` into `weird__case`.
|
||||
if buf.chars().last() != Some('_') {
|
||||
buf.push('_')
|
||||
}
|
||||
}
|
||||
prev = true;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue