summaryrefslogtreecommitdiff
path: root/src/utf8.hh
diff options
context:
space:
mode:
authorMaxime Coste <mawww@kakoune.org>2019-01-13 18:29:20 +1100
committerMaxime Coste <mawww@kakoune.org>2019-01-13 18:29:20 +1100
commit445da8d7bf578c681293f495d3d916daf21966ec (patch)
tree76f1c9d5e241f3ba45556f137bb3e133d7453015 /src/utf8.hh
parent7dbd9bc1e252aa5943b96c42cb285e0ac73ef02a (diff)
Use an InvalidPolicy in utf8::dump and utf8::codepoint_size
Do not throw on invalid codepoints by default, ignore them. Fixes #2686
Diffstat (limited to 'src/utf8.hh')
-rw-r--r--src/utf8.hh15
1 files changed, 9 insertions, 6 deletions
diff --git a/src/utf8.hh b/src/utf8.hh
index 9089d655..928b98d3 100644
--- a/src/utf8.hh
+++ b/src/utf8.hh
@@ -109,9 +109,9 @@ ByteCount codepoint_size(char byte)
}
}
-struct invalid_codepoint{};
-
-inline ByteCount codepoint_size(Codepoint cp)
+template<typename InvalidPolicy = utf8::InvalidPolicy::Pass>
+ByteCount codepoint_size(Codepoint cp)
+ noexcept(noexcept(InvalidPolicy{}(0)))
{
if (cp <= 0x7F)
return 1;
@@ -122,7 +122,10 @@ inline ByteCount codepoint_size(Codepoint cp)
else if (cp <= 0x10FFFF)
return 4;
else
- throw invalid_codepoint{};
+ {
+ InvalidPolicy{}(cp);
+ return 0;
+ }
}
template<typename Iterator, typename Sentinel>
@@ -255,7 +258,7 @@ Iterator character_start(Iterator it, const Sentinel& begin) noexcept
return it;
}
-template<typename OutputIterator>
+template<typename OutputIterator, typename InvalidPolicy = utf8::InvalidPolicy::Pass>
void dump(OutputIterator&& it, Codepoint cp)
{
if (cp <= 0x7F)
@@ -279,7 +282,7 @@ void dump(OutputIterator&& it, Codepoint cp)
*it++ = 0x80 | (cp & 0x3F);
}
else
- throw invalid_codepoint{};
+ InvalidPolicy{}(cp);
}
}