Make expand_unprintable more tolerant to invalid utf8
This commit is contained in:
parent
2bb2c467b6
commit
55959f2cb1
|
@ -538,24 +538,25 @@ void expand_unprintable(const Context& context, HighlightFlags flags, DisplayBuf
|
||||||
{
|
{
|
||||||
if (atom_it->type() == DisplayAtom::BufferRange)
|
if (atom_it->type() == DisplayAtom::BufferRange)
|
||||||
{
|
{
|
||||||
using Utf8It = utf8::utf8_iterator<BufferIterator, utf8::InvalidBytePolicy::Pass>;
|
for (auto it = buffer.iterator_at(atom_it->begin()),
|
||||||
for (Utf8It it = buffer.iterator_at(atom_it->begin()),
|
end = buffer.iterator_at(atom_it->end()); it < end;)
|
||||||
end = buffer.iterator_at(atom_it->end()); it != end; ++it)
|
|
||||||
{
|
{
|
||||||
Codepoint cp = *it;
|
Codepoint cp = utf8::codepoint<utf8::InvalidBytePolicy::Pass>(it);
|
||||||
|
auto next = utf8::next(it);
|
||||||
if (cp != '\n' and not iswprint(cp))
|
if (cp != '\n' and not iswprint(cp))
|
||||||
{
|
{
|
||||||
std::ostringstream oss;
|
std::ostringstream oss;
|
||||||
oss << "U+" << std::hex << cp;
|
oss << "U+" << std::hex << cp;
|
||||||
String str = oss.str();
|
String str = oss.str();
|
||||||
if (it.base().coord() != atom_it->begin())
|
if (it.coord() != atom_it->begin())
|
||||||
atom_it = ++line.split(atom_it, it.base().coord());
|
atom_it = ++line.split(atom_it, it.coord());
|
||||||
if ((it+1).base().coord() != atom_it->end())
|
if (next.coord() < atom_it->end())
|
||||||
atom_it = line.split(atom_it, (it+1).base().coord());
|
atom_it = line.split(atom_it, next.coord());
|
||||||
atom_it->replace(str);
|
atom_it->replace(str);
|
||||||
atom_it->colors = { Colors::Red, Colors::Black };
|
atom_it->colors = { Colors::Red, Colors::Black };
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
it = next;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user