mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-08-04 02:39:32 +00:00
Move snake case method to heck
This commit is contained in:
parent
ba8ffab644
commit
66882f1a24
2 changed files with 16 additions and 15 deletions
|
@ -102,3 +102,17 @@ pub fn timeit(label: &'static str) -> impl Drop {
|
|||
|
||||
Guard { label, start: Instant::now() }
|
||||
}
|
||||
|
||||
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() {
|
||||
if c.is_ascii_uppercase() && prev {
|
||||
buf.push('_')
|
||||
}
|
||||
prev = true;
|
||||
|
||||
buf.push(c.to_ascii_lowercase());
|
||||
}
|
||||
buf
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue