Skip to content

Commit 44e64ba

Browse files
committed
v0: use strip_prefix instead of manual work
1 parent cc1023a commit 44e64ba

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

src/v0.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,16 +38,15 @@ pub fn demangle(s: &str) -> Result<(Demangle, &str), ParseError> {
3838
// First validate the symbol. If it doesn't look like anything we're
3939
// expecting, we just print it literally. Note that we must handle non-Rust
4040
// symbols because we could have any function in the backtrace.
41-
let inner;
42-
if s.len() > 2 && s.starts_with("_R") {
43-
inner = &s[2..];
44-
} else if s.len() > 1 && s.starts_with('R') {
41+
let inner = if let Some(s) = s.strip_prefix("_R") {
42+
s
43+
} else if let Some(s) = s.strip_prefix('R') {
4544
// On Windows, dbghelp strips leading underscores, so we accept "R..."
4645
// form too.
47-
inner = &s[1..];
48-
} else if s.len() > 3 && s.starts_with("__R") {
46+
s
47+
} else if let Some(s) = s.strip_prefix("__R") {
4948
// On OSX, symbols are prefixed with an extra _
50-
inner = &s[3..];
49+
s
5150
} else {
5251
return Err(ParseError::Invalid);
5352
}

0 commit comments

Comments
 (0)