2 // Copyright (c) 2019 Vinnie Falco (vinnie.falco@gmail.com)
4 // Distributed under the Boost Software License, Version 1.0. (See accompanying
5 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
7 // Official repository: https://github.com/boostorg/json
10 #ifndef BOOST_JSON_DETAIL_BUFFER_HPP
11 #define BOOST_JSON_DETAIL_BUFFER_HPP
13 #include <boost/json/detail/config.hpp>
14 #include <boost/json/string_view.hpp>
20 // A simple string-like temporary static buffer
21 template<std::size_t N>
25 using size_type = std::size_t;
30 empty() const noexcept
41 operator string_view() const noexcept
59 capacity() const noexcept
65 max_size() const noexcept
77 push_back(char ch) noexcept
79 BOOST_ASSERT(capacity() > 0);
83 // append an unescaped string
89 BOOST_ASSERT(n <= N - size_);
90 std::memcpy(buf_ + size_, s, n);
94 // append valid 32-bit code point as utf8
97 unsigned long cp) noexcept
99 auto dest = buf_ + size_;
102 BOOST_ASSERT(size_ <= N - 1);
103 dest[0] = static_cast<char>(cp);
110 BOOST_ASSERT(size_ <= N - 2);
111 dest[0] = static_cast<char>( (cp >> 6) | 0xc0);
112 dest[1] = static_cast<char>( (cp & 0x3f) | 0x80);
119 BOOST_ASSERT(size_ <= N - 3);
120 dest[0] = static_cast<char>( (cp >> 12) | 0xe0);
121 dest[1] = static_cast<char>(((cp >> 6) & 0x3f) | 0x80);
122 dest[2] = static_cast<char>( (cp & 0x3f) | 0x80);
128 BOOST_ASSERT(size_ <= N - 4);
129 dest[0] = static_cast<char>( (cp >> 18) | 0xf0);
130 dest[1] = static_cast<char>(((cp >> 12) & 0x3f) | 0x80);
131 dest[2] = static_cast<char>(((cp >> 6) & 0x3f) | 0x80);
132 dest[3] = static_cast<char>( (cp & 0x3f) | 0x80);