diff options
| author | Maxime Coste <frrrwww@gmail.com> | 2014-05-21 00:24:58 +0100 |
|---|---|---|
| committer | Maxime Coste <frrrwww@gmail.com> | 2014-05-21 00:24:58 +0100 |
| commit | 55959f2cb151737b882f3aa8fe8d3192d0dca6ea (patch) | |
| tree | 744cf43b79021e6834e7d089d9fc282031f2a754 /src | |
| parent | 2bb2c467b672d00899b799a5501e55660371c7fd (diff) | |
Make expand_unprintable more tolerant to invalid utf8
Diffstat (limited to 'src')
| -rw-r--r-- | src/highlighters.cc | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/src/highlighters.cc b/src/highlighters.cc index a73ba9e4..dff2f9e4 100644 --- a/src/highlighters.cc +++ b/src/highlighters.cc @@ -538,24 +538,25 @@ void expand_unprintable(const Context& context, HighlightFlags flags, DisplayBuf { if (atom_it->type() == DisplayAtom::BufferRange) { - using Utf8It = utf8::utf8_iterator<BufferIterator, utf8::InvalidBytePolicy::Pass>; - for (Utf8It it = buffer.iterator_at(atom_it->begin()), - end = buffer.iterator_at(atom_it->end()); it != end; ++it) + for (auto it = buffer.iterator_at(atom_it->begin()), + end = buffer.iterator_at(atom_it->end()); it < end;) { - Codepoint cp = *it; + Codepoint cp = utf8::codepoint<utf8::InvalidBytePolicy::Pass>(it); + auto next = utf8::next(it); if (cp != '\n' and not iswprint(cp)) { std::ostringstream oss; oss << "U+" << std::hex << cp; String str = oss.str(); - if (it.base().coord() != atom_it->begin()) - atom_it = ++line.split(atom_it, it.base().coord()); - if ((it+1).base().coord() != atom_it->end()) - atom_it = line.split(atom_it, (it+1).base().coord()); + if (it.coord() != atom_it->begin()) + atom_it = ++line.split(atom_it, it.coord()); + if (next.coord() < atom_it->end()) + atom_it = line.split(atom_it, next.coord()); atom_it->replace(str); atom_it->colors = { Colors::Red, Colors::Black }; break; } + it = next; } } } |
