summaryrefslogtreecommitdiffstats
path: root/rfc2822/src/roundtrip.rs
diff options
context:
space:
mode:
Diffstat (limited to 'rfc2822/src/roundtrip.rs')
-rw-r--r--rfc2822/src/roundtrip.rs19
1 files changed, 12 insertions, 7 deletions
diff --git a/rfc2822/src/roundtrip.rs b/rfc2822/src/roundtrip.rs
index b9ecfea5..aadd7d9e 100644
--- a/rfc2822/src/roundtrip.rs
+++ b/rfc2822/src/roundtrip.rs
@@ -187,15 +187,20 @@ macro_rules! parser_quickcheck {
} = err
{
eprintln!("Context:");
- // XXX: This won't work with multi-byte
- // characters. But at that point we've
- // already printed the error message.
- for i in (cmp::max(5, start) - 5)
- ..cmp::min(end + 5, s.len() - 1)
- {
+ let chars = s.char_indices()
+ .filter_map(|(i, c)| {
+ if cmp::max(8, start) - 8 <= i
+ && i <= end + 8
+ {
+ Some((i, c))
+ } else {
+ None
+ }
+ });
+ for (i, c) in chars {
eprintln!("{} {}: {:?}",
if i == start { "*" } else { " " },
- i, &s[i..i+1]);
+ i, c);
}
}
false