-
Notifications
You must be signed in to change notification settings - Fork 155
Name mangling is lossy around numbers #76
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
Comments
I use the following patch to the diff --git a/src/case.rs b/src/case.rs
index 0c6bea7..a22677f 100644
--- a/src/case.rs
+++ b/src/case.rs
@@ -443,6 +443,12 @@ pub fn is_constant_case(string: &str) -> bool {
string == to_constant_case(string)
}
+/// Checks if a character is a digit.
+#[inline]
+fn is_digit(c: char) -> bool {
+ c >= '0' && c <= '9'
+}
+
/// Checks if a character is a separator.
#[inline]
fn is_separator(c: char) -> bool {
@@ -472,7 +478,15 @@ fn scan_to_camel(state: &mut (bool, Option<char>), curr: char) -> Option<String>
let last = state.1;
state.1 = Some(curr);
- if state.0 {
+ if state.0 && is_digit(curr) {
+ // If the state has signaled the next character must be capitalized,
+ // but it is a digit, then prepend a separator to it.
+ state.0 = false;
+ let mut string = String::with_capacity(2);
+ string.push('_');
+ string.push(curr);
+ Some(string)
+ } else if state.0 {
// If the state has signaled the next character must be capitalized,
// capitalize it and mark the state as finished.
state.0 = false; It is not obvious how or where it should be integrated. |
Note: this is not perfect and results in errors such as follows:
|
The more I think about it, the more I realize that name mangling of types (well, any name mangling that changes separators) is a bad idea.
Therefore I propose to allow non-camel-case types and stop this mangling altogether. |
All <name> tags are supposed to follow C ansi code standards. Code gen from SVD's usually use macro naming conventions, i.e exactly what <name> holds. This issue is a tricky one to fix. Can one possibly make |
One could of course mangle the SVD files in any applicable way to work around a deficiency of svd2rust but I don't think this should be necessary. |
Normalize SVD names to upper case where they were to pascal case Fixes #76. Depends on calebmer/inflections#2.
E.g. both
ADC_SPC_PHASE_22_5
andADC_SPC_PHASE_225
converge toAdcSpcPhase225
.The text was updated successfully, but these errors were encountered: