From 445da8d7bf578c681293f495d3d916daf21966ec Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Sun, 13 Jan 2019 18:29:20 +1100 Subject: [PATCH] Use an InvalidPolicy in utf8::dump and utf8::codepoint_size Do not throw on invalid codepoints by default, ignore them. Fixes #2686 --- src/utf8.hh | 15 +++++++++------ 1 file 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 +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 @@ -255,7 +258,7 @@ Iterator character_start(Iterator it, const Sentinel& begin) noexcept return it; } -template +template 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); } }