summaryrefslogtreecommitdiff
path: root/src/utf8.hh
diff options
context:
space:
mode:
authorMaxime Coste <frrrwww@gmail.com>2016-02-05 09:13:07 +0000
committerMaxime Coste <frrrwww@gmail.com>2016-02-05 09:13:07 +0000
commit94cbd5a837edfdcf87b754f3a943c57fbd9c9c32 (patch)
tree0b0f51cd571ec2a5ead868013757ddcd15790276 /src/utf8.hh
parentff6eacffa3f5bb10e0bf0d31b3eabc7ac10fcd51 (diff)
More string usage cleanup
Diffstat (limited to 'src/utf8.hh')
-rw-r--r--src/utf8.hh14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/utf8.hh b/src/utf8.hh
index f38327eb..648c6011 100644
--- a/src/utf8.hh
+++ b/src/utf8.hh
@@ -178,6 +178,20 @@ ByteCount codepoint_size(char byte)
struct invalid_codepoint{};
+inline ByteCount codepoint_size(Codepoint cp)
+{
+ if (cp <= 0x7F)
+ return 1;
+ else if (cp <= 0x7FF)
+ return 2;
+ else if (cp <= 0xFFFF)
+ return 3;
+ else if (cp <= 0x10FFFF)
+ return 4;
+ else
+ throw invalid_codepoint{};
+}
+
template<typename OutputIterator>
void dump(OutputIterator&& it, Codepoint cp)
{