Handle trailing underscores in function name

This commit is contained in:
Luke Street 2023-08-23 09:57:38 -04:00
parent 4ddceaec0e
commit 0f20b45a49
2 changed files with 10 additions and 2 deletions

View File

@ -1,6 +1,6 @@
[package]
name = "cwdemangle"
version = "0.1.5"
version = "0.1.6"
edition = "2018"
authors = ["Luke Street <luke@street.dev>"]
license = "MIT OR Apache-2.0"

View File

@ -324,7 +324,11 @@ pub fn demangle(mut str: &str, options: &DemangleOptions) -> Option<String> {
str = &str[2..];
}
{
let idx = str.find("__")?;
let mut idx = str.find("__")?;
// Handle any trailing underscores in the function name
while str.chars().nth(idx + 2) == Some('_') {
idx += 1;
}
let (fn_name_out, mut rest) = str.split_at(idx);
if special {
if fn_name_out == "init" {
@ -686,6 +690,10 @@ mod tests {
),
Some("nw4r::ut::CharStrmReader::CharStrmReader(unsigned short (nw4r::ut::CharStrmReader::*)())".to_string())
);
assert_eq!(
demangle("QuerySymbolToMapFile___Q24nw4r2dbFPUcPC12OSModuleInfoUlPUcUl", &options),
Some("nw4r::db::QuerySymbolToMapFile_(unsigned char*, const OSModuleInfo*, unsigned long, unsigned char*, unsigned long)".to_string())
);
}
#[test]