From a52bb9146e5673ceaf6081833cf7183fc3f7ff9d Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Tue, 6 Dec 2022 17:55:20 +1100 Subject: [PATCH] Cleanup expand_unprintable and avoid calling iswprint on base ascii --- src/highlighters.cc | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/src/highlighters.cc b/src/highlighters.cc index ed3426e8..8f7a97f3 100644 --- a/src/highlighters.cc +++ b/src/highlighters.cc @@ -1329,24 +1329,24 @@ void expand_unprintable(HighlightContext context, DisplayBuffer& display_buffer, { for (auto atom_it = line.begin(); atom_it != line.end(); ++atom_it) { - if (atom_it->type() == DisplayAtom::Range) - { - for (auto it = get_iterator(buffer, atom_it->begin()), - end = get_iterator(buffer, atom_it->end()); it < end;) - { - auto coord = it.coord(); - Codepoint cp = utf8::read_codepoint(it, end); - if (cp != '\n' and not iswprint((wchar_t)cp)) - { - if (coord != atom_it->begin()) - atom_it = ++line.split(atom_it, coord); - if (it.coord() < atom_it->end()) - atom_it = line.split(atom_it, it.coord()); + if (atom_it->type() != DisplayAtom::Range) + continue; - atom_it->replace("�"); - atom_it->face = error; - break; - } + for (auto it = get_iterator(buffer, atom_it->begin()), + end = get_iterator(buffer, atom_it->end()); it < end;) + { + auto coord = it.coord(); + Codepoint cp = utf8::read_codepoint(it, end); + if (cp != '\n' and (cp < ' ' or cp > '~') and not iswprint((wchar_t)cp)) + { + if (coord != atom_it->begin()) + atom_it = ++line.split(atom_it, coord); + if (it.coord() < atom_it->end()) + atom_it = line.split(atom_it, it.coord()); + + atom_it->replace("�"); + atom_it->face = error; + break; } } }