Skip to content

Commit

Permalink
Use constant case for enum cases and interrupts.
Browse files Browse the repository at this point in the history
  • Loading branch information
Dirbaio committed Oct 27, 2024
1 parent c425255 commit 37f89fc
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/transform/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ impl Sanitize {
pub fn run(&self, ir: &mut IR) -> anyhow::Result<()> {
map_names(ir, |k, p| match k {
NameKind::Device => *p = sanitize_path(p),
NameKind::DevicePeripheral => *p = p.to_sanitized_upper_case().to_string(),
NameKind::DeviceInterrupt => *p = p.to_sanitized_upper_case().to_string(),
NameKind::DevicePeripheral => *p = p.to_sanitized_constant_case().to_string(),
NameKind::DeviceInterrupt => *p = p.to_sanitized_constant_case().to_string(),
NameKind::Block => *p = sanitize_path(p),
NameKind::Fieldset => *p = sanitize_path(p),
NameKind::Enum => *p = sanitize_path(p),
NameKind::BlockItem => *p = p.to_sanitized_snake_case().to_string(),
NameKind::Field => *p = p.to_sanitized_snake_case().to_string(),
NameKind::EnumVariant => *p = p.to_sanitized_upper_case().to_string(),
NameKind::EnumVariant => *p = p.to_sanitized_constant_case().to_string(),
});
Ok(())
}
Expand Down
5 changes: 5 additions & 0 deletions src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ fn sanitize_ident(s: String) -> String {
pub trait StringExt {
fn to_sanitized_pascal_case(&self) -> String;
fn to_sanitized_upper_case(&self) -> String;
fn to_sanitized_constant_case(&self) -> String;
fn to_sanitized_snake_case(&self) -> String;
}

Expand All @@ -46,6 +47,10 @@ impl StringExt for str {
sanitize_ident(self.to_upper_case())
}

fn to_sanitized_constant_case(&self) -> String {
sanitize_ident(self.to_constant_case())
}

fn to_sanitized_pascal_case(&self) -> String {
sanitize_ident(self.to_pascal_case())
}
Expand Down

0 comments on commit 37f89fc

Please sign in to comment.