Skip to content

Commit 608c1eb

Browse files
committed
v0: use strip_prefix instead of manual work
1 parent 6c3882c commit 608c1eb

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

src/v0.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,19 +27,18 @@ pub fn demangle(s: &str) -> Result<(Demangle<'_>, &str), Invalid> {
2727
// First validate the symbol. If it doesn't look like anything we're
2828
// expecting, we just print it literally. Note that we must handle non-Rust
2929
// symbols because we could have any function in the backtrace.
30-
let inner;
31-
if s.len() > 2 && s.starts_with("_R") {
32-
inner = &s[2..];
33-
} else if s.len() > 1 && s.starts_with('R') {
30+
let inner = if let Some(s) = s.strip_prefix("_R") {
31+
s
32+
} else if let Some(s) = s.strip_prefix('R') {
3433
// On Windows, dbghelp strips leading underscores, so we accept "R..."
3534
// form too.
36-
inner = &s[1..];
37-
} else if s.len() > 3 && s.starts_with("__R") {
35+
s
36+
} else if let Some(s) = s.strip_prefix("__R") {
3837
// On OSX, symbols are prefixed with an extra _
39-
inner = &s[3..];
38+
s
4039
} else {
4140
return Err(Invalid);
42-
}
41+
};
4342

4443
// Paths always start with uppercase characters.
4544
match inner.as_bytes()[0] {

0 commit comments

Comments
 (0)