MCPcopy Create free account
hub / github.com/boostorg/json / append_utf8

Method append_utf8

include/boost/json/detail/buffer.hpp:96–136  ·  view source on GitHub ↗

append valid 32-bit code point as utf8

Source from the content-addressed store, hash-verified

94
95 // append valid 32-bit code point as utf8
96 void
97 append_utf8(
98 unsigned long cp) noexcept
99 {
100 auto dest = buf_ + size_;
101 if(cp < 0x80)
102 {
103 BOOST_ASSERT(size_ <= N - 1);
104 dest[0] = static_cast<char>(cp);
105 size_ += 1;
106 return;
107 }
108
109 if(cp < 0x800)
110 {
111 BOOST_ASSERT(size_ <= N - 2);
112 dest[0] = static_cast<char>( (cp >> 6) | 0xc0);
113 dest[1] = static_cast<char>( (cp & 0x3f) | 0x80);
114 size_ += 2;
115 return;
116 }
117
118 if(cp < 0x10000)
119 {
120 BOOST_ASSERT(size_ <= N - 3);
121 dest[0] = static_cast<char>( (cp >> 12) | 0xe0);
122 dest[1] = static_cast<char>(((cp >> 6) & 0x3f) | 0x80);
123 dest[2] = static_cast<char>( (cp & 0x3f) | 0x80);
124 size_ += 3;
125 return;
126 }
127
128 {
129 BOOST_ASSERT(size_ <= N - 4);
130 dest[0] = static_cast<char>( (cp >> 18) | 0xf0);
131 dest[1] = static_cast<char>(((cp >> 12) & 0x3f) | 0x80);
132 dest[2] = static_cast<char>(((cp >> 6) & 0x3f) | 0x80);
133 dest[3] = static_cast<char>( (cp & 0x3f) | 0x80);
134 size_ += 4;
135 }
136 }
137private:
138 char buf_[N];
139 size_type size_ = 0;

Callers 1

parse_escapedMethod · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected