Derive a function name from REM comment text. Takes the first REM line text and converts it into a snake_case-like identifier. For example, "VALIDATE CONFIGURATION" becomes "`VALIDATE_CONFIGURATION`".
(rem_comments: &[String])
| 75 | /// Takes the first REM line text and converts it into a snake_case-like |
| 76 | /// identifier. For example, "VALIDATE CONFIGURATION" becomes "`VALIDATE_CONFIGURATION`". |
| 77 | pub(crate) fn derive_function_name(rem_comments: &[String]) -> String { |
| 78 | if rem_comments.is_empty() { |
| 79 | return "UNNAMED_SUB".to_string(); |
| 80 | } |
| 81 | let first = &rem_comments[0]; |
| 82 | // Replace spaces with underscores and keep alphanumeric + underscore. |
| 83 | let name: String = first |
| 84 | .chars() |
| 85 | .map(|c| { |
| 86 | if c.is_alphanumeric() || c == '_' { |
| 87 | c |
| 88 | } else { |
| 89 | '_' |
| 90 | } |
| 91 | }) |
| 92 | .collect(); |
| 93 | // Collapse multiple underscores and trim. |
| 94 | let mut collapsed = String::new(); |
| 95 | let mut prev_underscore = false; |
| 96 | for c in name.chars() { |
| 97 | if c == '_' { |
| 98 | if !prev_underscore && !collapsed.is_empty() { |
| 99 | collapsed.push('_'); |
| 100 | } |
| 101 | prev_underscore = true; |
| 102 | } else { |
| 103 | collapsed.push(c); |
| 104 | prev_underscore = false; |
| 105 | } |
| 106 | } |
| 107 | let trimmed = collapsed.trim_end_matches('_').to_string(); |
| 108 | if trimmed.is_empty() { |
| 109 | "UNNAMED_SUB".to_string() |
| 110 | } else { |
| 111 | trimmed |
| 112 | } |
| 113 | } |
no test coverage detected