summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNeal H. Walfield <neal@pep.foundation>2019-05-17 11:06:48 +0200
committerNeal H. Walfield <neal@pep.foundation>2019-05-17 11:14:03 +0200
commit3ffbc7318288ab65850c13b35e5bd0785e9528d5 (patch)
treeb9fedd379aaf11381ce752fd8bf79392f6f06a9c
parentb2c8db84f798b422cf93959031e9c234f8595d78 (diff)
rfc2822: Fix debug output to work with multi-byte characters
- Change the error handler for the tests to work with multi-byte characters.
-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