From a98326eb2954ac1e79f5eac28dbeab3ec15e047f Mon Sep 17 00:00:00 2001 From: Daniel Wilhelm Date: Sat, 30 Jun 2018 12:43:08 +0200 Subject: 10.1 --- zen/utf.h | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) (limited to 'zen/utf.h') diff --git a/zen/utf.h b/zen/utf.h index f8ee91d5..48269416 100755 --- a/zen/utf.h +++ b/zen/utf.h @@ -53,6 +53,8 @@ const CodePoint TRAIL_SURROGATE_MAX = 0xdfff; const CodePoint REPLACEMENT_CHAR = 0xfffd; const CodePoint CODE_POINT_MAX = 0x10ffff; +static_assert(LEAD_SURROGATE + TRAIL_SURROGATE + TRAIL_SURROGATE_MAX + REPLACEMENT_CHAR + CODE_POINT_MAX == 1348603); + template inline void codePointToUtf16(CodePoint cp, Function writeOutput) //"writeOutput" is a unary function taking a Char16 @@ -245,14 +247,14 @@ private: //---------------------------------------------------------------------------------------------------------------- -template inline void codePointToUtf(CodePoint cp, Function writeOutput, Int2Type<1>) { codePointToUtf8 (cp, writeOutput); } //UTF8-char -template inline void codePointToUtf(CodePoint cp, Function writeOutput, Int2Type<2>) { codePointToUtf16(cp, writeOutput); } //Windows: UTF16-wchar_t -template inline void codePointToUtf(CodePoint cp, Function writeOutput, Int2Type<4>) { writeOutput(cp); } //other OS: UTF32-wchar_t +template inline void codePointToUtf(CodePoint cp, Function writeOutput, std::integral_constant) { codePointToUtf8 (cp, writeOutput); } //UTF8-char +template inline void codePointToUtf(CodePoint cp, Function writeOutput, std::integral_constant) { codePointToUtf16(cp, writeOutput); } //Windows: UTF16-wchar_t +template inline void codePointToUtf(CodePoint cp, Function writeOutput, std::integral_constant) { writeOutput(cp); } //other OS: UTF32-wchar_t template inline void codePointToUtf(CodePoint cp, Function writeOutput) //"writeOutput" is a unary function taking a CharType { - return codePointToUtf(cp, writeOutput, Int2Type()); + return codePointToUtf(cp, writeOutput, std::integral_constant()); } //---------------------------------------------------------------------------------------------------------------- @@ -311,7 +313,7 @@ bool isValidUtf(const UtfString& str) { using namespace impl; - UtfDecoder::Type> decoder(strBegin(str), strLength(str)); + UtfDecoder> decoder(strBegin(str), strLength(str)); while (Opt cp = decoder.getNext()) if (*cp == REPLACEMENT_CHAR) return false; @@ -324,7 +326,7 @@ template inline size_t unicodeLength(const UtfString& str) //return number of code points (+ correctly handle broken UTF encoding) { size_t uniLen = 0; - impl::UtfDecoder::Type> decoder(strBegin(str), strLength(str)); + impl::UtfDecoder> decoder(strBegin(str), strLength(str)); while (decoder.getNext()) ++uniLen; return uniLen; @@ -336,7 +338,7 @@ UtfString getUnicodeSubstring(const UtfString& str, size_t uniPosFirst, size_t u { assert(uniPosFirst <= uniPosLast && uniPosLast <= unicodeLength(str)); using namespace impl; - using CharType = typename GetCharType::Type; + using CharType = GetCharTypeT; UtfString output; if (uniPosFirst >= uniPosLast) //optimize for empty range return output; @@ -357,11 +359,11 @@ UtfString getUnicodeSubstring(const UtfString& str, size_t uniPosFirst, size_t u namespace impl { template inline -TargetString utfTo(const SourceString& str, FalseType) +TargetString utfTo(const SourceString& str, std::false_type) { - using CharSrc = typename GetCharType::Type; - using CharTrg = typename GetCharType::Type; - static_assert(sizeof(CharSrc) != sizeof(CharTrg), "no UTF-conversion needed"); + using CharSrc = GetCharTypeT; + using CharTrg = GetCharTypeT; + static_assert(sizeof(CharSrc) != sizeof(CharTrg)); TargetString output; @@ -374,14 +376,14 @@ TargetString utfTo(const SourceString& str, FalseType) template inline -TargetString utfTo(const SourceString& str, TrueType) { return copyStringTo(str); } +TargetString utfTo(const SourceString& str, std::true_type) { return copyStringTo(str); } } template inline TargetString utfTo(const SourceString& str) { - return impl::utfTo(str, StaticBool::Type) == sizeof(typename GetCharType::Type)>()); + return impl::utfTo(str, std::bool_constant) == sizeof(GetCharTypeT)>()); } } -- cgit