6C4_SUPPRESS_WARNING_GCC_CLANG_WITH_PUSH(
"-Wold-style-cast")
11 C4_ASSERT(buflen >= 4);
13 if (code <= UINT32_C(0x7f))
15 buf[0] = (uint8_t)code;
18 else if(code <= UINT32_C(0x7ff))
20 buf[0] = (uint8_t)(UINT32_C(0xc0) | (code >> 6u));
21 buf[1] = (uint8_t)(UINT32_C(0x80) | (code & UINT32_C(0x3f)));
24 else if(code <= UINT32_C(0xffff))
26 buf[0] = (uint8_t)(UINT32_C(0xe0) | ((code >> 12u)));
27 buf[1] = (uint8_t)(UINT32_C(0x80) | ((code >> 6u) & UINT32_C(0x3f)));
28 buf[2] = (uint8_t)(UINT32_C(0x80) | ((code ) & UINT32_C(0x3f)));
31 else if(code <= UINT32_C(0x10ffff))
33 buf[0] = (uint8_t)(UINT32_C(0xf0) | ((code >> 18u)));
34 buf[1] = (uint8_t)(UINT32_C(0x80) | ((code >> 12u) & UINT32_C(0x3f)));
35 buf[2] = (uint8_t)(UINT32_C(0x80) | ((code >> 6u) & UINT32_C(0x3f)));
36 buf[3] = (uint8_t)(UINT32_C(0x80) | ((code ) & UINT32_C(0x3f)));
44 C4_ASSERT(out.
len >= 4);
50 C4_ASSERT(code_point.
len <= 8);
51 C4_ASSERT(code_point.
len > 0);
52 uint32_t code_point_val;
53 C4_CHECK(
read_hex(code_point, &code_point_val));
56 return out.
first(ret);
61 #define c4check2_(s, c0, c1) ((s).len >= 2) && (((s).str[0] == (c0)) && ((s).str[1] == (c1)))
62 #define c4check3_(s, c0, c1, c2) ((s).len >= 3) && (((s).str[0] == (c0)) && ((s).str[1] == (c1)) && ((s).str[2] == (c2)))
63 #define c4check4_(s, c0, c1, c2, c3) ((s).len >= 4) && (((s).str[0] == (c0)) && ((s).str[1] == (c1)) && ((s).str[2] == (c2)) && ((s).str[3] == (c3)))
67 else if(
c4check3_(s,
'\xef',
'\xbb',
'\xbf'))
69 else if(
c4check4_(s,
'\x00',
'\x00',
'\xfe',
'\xff'))
71 else if(
c4check4_(s,
'\xff',
'\xfe',
'\x00',
'\x00'))
77 else if(
c4check3_(s,
'\x2b',
'\x2f',
'\x76'))
79 else if(
c4check3_(s,
'\xf7',
'\x64',
'\x4c'))
81 else if(
c4check4_(s,
'\xdd',
'\x73',
'\x66',
'\x73'))
83 else if(
c4check3_(s,
'\x0e',
'\xfe',
'\xff'))
85 else if(
c4check3_(s,
'\xfb',
'\xee',
'\x28'))
87 else if(
c4check4_(s,
'\x84',
'\x31',
'\x95',
'\x33'))
112C4_SUPPRESS_WARNING_GCC_CLANG_POP
Lightweight generic type-safe wrappers for converting individual values to/from strings.
bool read_hex(csubstr s, I *v) noexcept
read an hexadecimal integer from a string.
basic_substring< char > substr
a mutable string view
basic_substring< const char > csubstr
an immutable string view
substr skip_bom(substr s)
skip the Byte Order Mark, or get the full string if there is Byte Order Mark.
substr get_bom(substr s)
get the Byte Order Mark, or an empty string if there is no Byte Order Mark
size_t first_non_bom(csubstr s)
return the position of the first character not belonging to the Byte Order Mark, or 0 if there is no ...
substr decode_code_point(substr out, csubstr code_point)
decode the given code_point, writing into the output string in out.
bool begins_with(const C c) const noexcept
true if the first character of the string is c
size_t len
the length of the substring
basic_substring first(size_t num) const noexcept
return the first num elements: [0,num[
basic_substring sub(size_t first) const noexcept
return [first,len[
C * str
a restricted pointer to the first character of the substring
#define c4check3_(s, c0, c1, c2)
#define c4check2_(s, c0, c1)
#define c4check4_(s, c0, c1, c2, c3)
utilities for UTF and Byte Order Mark