aboutsummaryrefslogtreecommitdiff
path: root/crates/stdx/src
diff options
context:
space:
mode:
authorKirill Bulatov <[email protected]>2020-05-03 19:35:21 +0100
committerKirill Bulatov <[email protected]>2020-05-03 19:35:21 +0100
commit66882f1a249983a1b262a219dbcd47a0e2835418 (patch)
tree57e672bb5bc4a0aba430740650ce29fdc1982db1 /crates/stdx/src
parentba8ffab6444e0a6f4b9e5254adbef2adc6169cf9 (diff)
Move snake case method to heck
Diffstat (limited to 'crates/stdx/src')
-rw-r--r--crates/stdx/src/lib.rs14
1 files changed, 14 insertions, 0 deletions
diff --git a/crates/stdx/src/lib.rs b/crates/stdx/src/lib.rs
index 01cdf452c..0f34ce70e 100644
--- a/crates/stdx/src/lib.rs
+++ b/crates/stdx/src/lib.rs
@@ -102,3 +102,17 @@ pub fn timeit(label: &'static str) -> impl Drop {
102 102
103 Guard { label, start: Instant::now() } 103 Guard { label, start: Instant::now() }
104} 104}
105
106pub fn to_lower_snake_case(s: &str) -> String {
107 let mut buf = String::with_capacity(s.len());
108 let mut prev = false;
109 for c in s.chars() {
110 if c.is_ascii_uppercase() && prev {
111 buf.push('_')
112 }
113 prev = true;
114
115 buf.push(c.to_ascii_lowercase());
116 }
117 buf
118}