Skip to content

Commit

Permalink
Use regex to replace symbols
Browse files Browse the repository at this point in the history
  • Loading branch information
gephaistos committed Jul 26, 2024
1 parent b2cf6eb commit 42c0dad
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions src/generate/device.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::svd::{array::names, Device, Peripheral};
use proc_macro2::{Span, TokenStream};
use quote::{quote, ToTokens};
use regex::Regex;
use syn::Ident;

use log::debug;
Expand Down Expand Up @@ -273,12 +274,10 @@ pub fn render(d: &Device, config: &Config, device_x: &mut String) -> Result<Toke

// Generate unique identifier to prevent linkage errors when using multiple devices.
let mut id = String::from("TAKEN_");
for ch in d.name.chars() {
if ch == ' ' || ch == '-' {
id.push('_');
} else {
id.extend(ch.to_uppercase());
}
let re = Regex::new(r"[^A-Za-z0-9_]").unwrap();
let result = re.replace_all(&d.name, "_");
for ch in result.chars() {
id.extend(ch.to_uppercase());
}

let taken: Ident = syn::parse_str(&id)?;
Expand Down

0 comments on commit 42c0dad

Please sign in to comment.