summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMaxime Coste <frrrwww@gmail.com>2015-09-24 23:00:47 +0100
committerMaxime Coste <frrrwww@gmail.com>2015-09-24 23:00:47 +0100
commitaa4b98af7c40ead3eeb5c8548c2dd6263f2c387b (patch)
tree1131cbc9d3587528331c46191ae4349cb2a3ab8a /src
parent12ef466f3a5dc97f9358e35eb4cfa5e16458afa9 (diff)
Add utf8::read_codepoint that both gets the codepoint and advance iterator
Diffstat (limited to 'src')
-rw-r--r--src/highlighters.cc13
-rw-r--r--src/utf8.hh15
2 files changed, 17 insertions, 11 deletions
diff --git a/src/highlighters.cc b/src/highlighters.cc
index 052ff657..9c818a89 100644
--- a/src/highlighters.cc
+++ b/src/highlighters.cc
@@ -861,20 +861,19 @@ void expand_unprintable(const Context& context, HighlightFlags flags, DisplayBuf
for (auto it = buffer.iterator_at(atom_it->begin()),
end = buffer.iterator_at(atom_it->end()); it < end;)
{
- Codepoint cp = utf8::codepoint<utf8::InvalidPolicy::Pass>(it, end);
- auto next = utf8::next(it, end);
+ auto coord = it.coord();
+ Codepoint cp = utf8::read_codepoint<utf8::InvalidPolicy::Pass>(it, end);
if (cp != '\n' and not iswprint(cp))
{
- 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());
+ 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(format("U+{}", hex(cp)));
atom_it->face = { Color::Red, Color::Black };
break;
}
- it = next;
}
}
}
diff --git a/src/utf8.hh b/src/utf8.hh
index 545255fd..09d66b99 100644
--- a/src/utf8.hh
+++ b/src/utf8.hh
@@ -110,7 +110,7 @@ struct Pass
// is pointed by it
template<typename InvalidPolicy = utf8::InvalidPolicy::Pass,
typename Iterator>
-Codepoint codepoint(Iterator it, const Iterator& end)
+Codepoint read_codepoint(Iterator& it, const Iterator& end)
{
if (it == end)
return InvalidPolicy{}(-1);
@@ -124,14 +124,14 @@ Codepoint codepoint(Iterator it, const Iterator& end)
return InvalidPolicy{}(byte);
if ((byte & 0xE0) == 0xC0) // 110xxxxx
- return ((byte & 0x1F) << 6) | (*it & 0x3F);
+ return ((byte & 0x1F) << 6) | (*it++ & 0x3F);
if ((byte & 0xF0) == 0xE0) // 1110xxxx
{
Codepoint cp = ((byte & 0x0F) << 12) | ((*it++ & 0x3F) << 6);
if (it == end)
return InvalidPolicy{}(cp);
- return cp | (*it & 0x3F);
+ return cp | (*it++ & 0x3F);
}
if ((byte & 0xF8) == 0xF0) // 11110xxx
@@ -142,11 +142,18 @@ Codepoint codepoint(Iterator it, const Iterator& end)
cp |= (*it++ & 0x3F) << 6;
if (it == end)
return InvalidPolicy{}(cp);
- return cp | (*it & 0x3F);
+ return cp | (*it++ & 0x3F);
}
return InvalidPolicy{}(byte);
}
+template<typename InvalidPolicy = utf8::InvalidPolicy::Pass,
+ typename Iterator>
+Codepoint codepoint(Iterator it, const Iterator& end)
+{
+ return read_codepoint(it, end);
+}
+
template<typename InvalidPolicy = utf8::InvalidPolicy::Pass>
ByteCount codepoint_size(char byte)
{