Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mqtt rust keywords 4863 v1 #11316

Closed
8 changes: 7 additions & 1 deletion rust/derive/src/applayerevent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,14 +111,19 @@ pub fn derive_app_layer_event(input: TokenStream) -> TokenStream {
/// Transform names such as "OneTwoThree" to "one_two_three".
pub fn transform_name(in_name: &str) -> String {
let mut out = String::new();
let mut lower = false;
for (i, c) in in_name.chars().enumerate() {
if i == 0 {
out.push_str(&c.to_lowercase().to_string());
} else if c.is_uppercase() {
out.push('_');
if lower {
out.push('_');
lower = false;
}
out.push_str(&c.to_lowercase().to_string());
} else {
out.push(c);
lower = true;
}
}
out
Expand Down Expand Up @@ -159,5 +164,6 @@ mod test {
transform_name("UnassignedMsgType"),
"unassigned_msg_type".to_string()
);
assert_eq!(transform_name("SAMECASE"), "samecase".to_string());
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fine in a test.

}
}