blob: 699ff8e7635fd1dca83635e2481deb601ce81038 [file] [log] [blame]
// Copyright 2019 The Fuchsia Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
use {heck::SnakeCase, std::iter};
pub fn to_c_name(name: &str) -> String {
// strip FQN
let name = name.split(".").last().unwrap();
// Force uppercase characters the follow one another to lowercase.
// e.g. GUIDType becomes Guidtype
let mut iter = name.chars();
let name = iter::once(iter.next().unwrap())
.chain(iter.zip(name.chars()).map(|(c1, c2)| {
if c2.is_ascii_uppercase() {
c1.to_ascii_lowercase()
} else {
c1
}
}))
.collect::<String>();
name.trim().to_snake_case()
}