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));
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);
int32_t UChar32
Define UChar32 as a type for single Unicode code points.
C API: 16-bit Unicode handling macros.
#define U16_TRAIL(supplementary)
Get the trail surrogate (0xdc00..0xdfff) for a supplementary code point (0x10000.....
#define U16_LEAD(supplementary)
Get the lead surrogate (0xd800..0xdbff) for a supplementary code point (0x10000..0x10ffff).
#define U_IS_SCALAR_VALUE(c)
Is c a Unicode scalar value, that is, a non-surrogate code point? Only scalar values can be represent...
StringClass encodeUnsafe(UChar32 c)
Returns the code point as a string of code units.
StringClass & appendOrFFFD(StringClass &s, UChar32 c)
Appends the code point to the string.
StringClass & appendUnsafe(StringClass &s, UChar32 c)
Appends the code point to the string.
StringClass encodeOrFFFD(UChar32 c)
Returns the code point as a string of code units.
Basic definitions for ICU, for both C and C++ APIs.