7 #ifndef __UTFSTRING_H__
8 #define __UTFSTRING_H__
12 #if U_SHOW_CPLUSPLUS_API || U_SHOW_CPLUSPLUS_HEADER_API || !defined(UTYPES_H)
21 #ifndef U_HIDE_DRAFT_API
23 namespace U_HEADER_ONLY_NAMESPACE {
34 template<
typename StringClass,
bool val
idate>
35 inline StringClass &appendCodePoint(StringClass &s, uint32_t c) {
36 using Unit =
typename StringClass::value_type;
37 if constexpr (
sizeof(Unit) == 1) {
40 s.push_back(
static_cast<Unit
>(c));
46 buf[2] = (c >> 6) | 0xc0;
50 (c < 0xe000 || c > 0x10ffff ? (c = 0xfffd,
true) : c <= 0xffff) :
53 buf[1] = (c >> 12) | 0xe0;
56 buf[0] = (c >> 18) | 0xf0;
57 buf[1] = ((c >> 12) & 0x3f) | 0x80;
59 buf[2] = ((c >> 6) & 0x3f) | 0x80;
61 buf[3] = (c & 0x3f) | 0x80;
62 s.append(buf + 4 - len, len);
64 }
else if constexpr (
sizeof(Unit) == 2) {
67 c < 0xd800 || (c < 0xe000 || c > 0x10ffff ? (c = 0xfffd,
true) : c <= 0xffff) :
69 s.push_back(
static_cast<Unit
>(c));
82 #endif // U_IN_DOXYGEN
84 #ifndef U_HIDE_DRAFT_API
97 template<
typename StringClass>
99 return prv::appendCodePoint<StringClass, true>(s, c);
114 template<
typename StringClass>
116 return prv::appendCodePoint<StringClass, false>(s, c);
130 template<
typename StringClass>
133 prv::appendCodePoint<StringClass, true>(s, c);
148 template<
typename StringClass>
151 prv::appendCodePoint<StringClass, false>(s, c);
154 #endif // U_HIDE_DRAFT_API
159 #endif // U_HIDE_DRAFT_API
160 #endif // U_SHOW_CPLUSPLUS_API || U_SHOW_CPLUSPLUS_HEADER_API
161 #endif // __UTFSTRING_H__