100.00% Lines (25/25)
100.00% Functions (7/7)
| TLA | Baseline | Branch | ||||||
|---|---|---|---|---|---|---|---|---|
| Line | Hits | Code | Line | Hits | Code | |||
| 1 | // | 1 | // | |||||
| 2 | // Copyright (c) 2025 Vinnie Falco (vinnie.falco@gmail.com) | 2 | // Copyright (c) 2025 Vinnie Falco (vinnie.falco@gmail.com) | |||||
| 3 | // | 3 | // | |||||
| 4 | // Distributed under the Boost Software License, Version 1.0. (See accompanying | 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) | 5 | // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) | |||||
| 6 | // | 6 | // | |||||
| 7 | // Official repository: https://github.com/cppalliance/http | 7 | // Official repository: https://github.com/cppalliance/http | |||||
| 8 | // | 8 | // | |||||
| 9 | 9 | |||||||
| 10 | #ifndef BOOST_HTTP_SERVER_DETAIL_STABLE_STRING_HPP | 10 | #ifndef BOOST_HTTP_SERVER_DETAIL_STABLE_STRING_HPP | |||||
| 11 | #define BOOST_HTTP_SERVER_DETAIL_STABLE_STRING_HPP | 11 | #define BOOST_HTTP_SERVER_DETAIL_STABLE_STRING_HPP | |||||
| 12 | 12 | |||||||
| 13 | #include <boost/http/detail/config.hpp> | 13 | #include <boost/http/detail/config.hpp> | |||||
| 14 | #include <cstdint> | 14 | #include <cstdint> | |||||
| 15 | #include <cstdlib> | 15 | #include <cstdlib> | |||||
| 16 | 16 | |||||||
| 17 | namespace boost { | 17 | namespace boost { | |||||
| 18 | namespace http { | 18 | namespace http { | |||||
| 19 | namespace detail { | 19 | namespace detail { | |||||
| 20 | 20 | |||||||
| 21 | // avoids SBO | 21 | // avoids SBO | |||||
| 22 | class stable_string | 22 | class stable_string | |||||
| 23 | { | 23 | { | |||||
| 24 | char const* p_ = 0; | 24 | char const* p_ = 0; | |||||
| 25 | std::size_t n_ = 0; | 25 | std::size_t n_ = 0; | |||||
| 26 | 26 | |||||||
| 27 | public: | 27 | public: | |||||
| HITCBC | 28 | 832 | ~stable_string() | 28 | 832 | ~stable_string() | ||
| 29 | { | 29 | { | |||||
| HITCBC | 30 | 832 | if(p_) | 30 | 832 | if(p_) | ||
| HITCBC | 31 | 192 | delete[] p_; | 31 | 192 | delete[] p_; | ||
| HITCBC | 32 | 832 | } | 32 | 832 | } | ||
| 33 | 33 | |||||||
| 34 | stable_string() = default; | 34 | stable_string() = default; | |||||
| 35 | 35 | |||||||
| HITCBC | 36 | 640 | stable_string( | 36 | 640 | stable_string( | ||
| 37 | stable_string&& other) noexcept | 37 | stable_string&& other) noexcept | |||||
| HITCBC | 38 | 640 | : p_(other.p_) | 38 | 640 | : p_(other.p_) | ||
| HITCBC | 39 | 640 | , n_(other.n_) | 39 | 640 | , n_(other.n_) | ||
| 40 | { | 40 | { | |||||
| HITCBC | 41 | 640 | other.p_ = nullptr; | 41 | 640 | other.p_ = nullptr; | ||
| HITCBC | 42 | 640 | other.n_ = 0; | 42 | 640 | other.n_ = 0; | ||
| HITCBC | 43 | 640 | } | 43 | 640 | } | ||
| 44 | 44 | |||||||
| 45 | stable_string& operator=( | 45 | stable_string& operator=( | |||||
| 46 | stable_string&& other) noexcept | 46 | stable_string&& other) noexcept | |||||
| 47 | { | 47 | { | |||||
| 48 | auto p = p_; | 48 | auto p = p_; | |||||
| 49 | auto n = n_; | 49 | auto n = n_; | |||||
| 50 | p_ = other.p_; | 50 | p_ = other.p_; | |||||
| 51 | n_ = other.n_; | 51 | n_ = other.n_; | |||||
| 52 | other.p_ = p; | 52 | other.p_ = p; | |||||
| 53 | other.n_ = n; | 53 | other.n_ = n; | |||||
| 54 | return *this; | 54 | return *this; | |||||
| 55 | } | 55 | } | |||||
| 56 | 56 | |||||||
| 57 | explicit | 57 | explicit | |||||
| HITCBC | 58 | 192 | stable_string( | 58 | 192 | stable_string( | ||
| 59 | std::string_view s) | 59 | std::string_view s) | |||||
| HITCBC | 60 | 384 | : p_( | 60 | 384 | : p_( | ||
| HITCBC | 61 | 576 | [&] | 61 | 576 | [&] | ||
| 62 | { | 62 | { | |||||
| HITCBC | 63 | 192 | auto p =new char[s.size()]; | 63 | 192 | auto p =new char[s.size()]; | ||
| HITCBC | 64 | 192 | std::memcpy(p, s.data(), s.size()); | 64 | 192 | std::memcpy(p, s.data(), s.size()); | ||
| HITCBC | 65 | 192 | return p; | 65 | 192 | return p; | ||
| HITCBC | 66 | 192 | }()) | 66 | 192 | }()) | ||
| HITCBC | 67 | 192 | , n_(s.size()) | 67 | 192 | , n_(s.size()) | ||
| 68 | { | 68 | { | |||||
| HITCBC | 69 | 192 | } | 69 | 192 | } | ||
| 70 | 70 | |||||||
| 71 | stable_string( | 71 | stable_string( | |||||
| 72 | char const* it, char const* end) | 72 | char const* it, char const* end) | |||||
| 73 | : stable_string(std::string_view(it, end)) | 73 | : stable_string(std::string_view(it, end)) | |||||
| 74 | { | 74 | { | |||||
| 75 | } | 75 | } | |||||
| 76 | 76 | |||||||
| HITCBC | 77 | 136 | char const* data() const noexcept | 77 | 136 | char const* data() const noexcept | ||
| 78 | { | 78 | { | |||||
| HITCBC | 79 | 136 | return p_; | 79 | 136 | return p_; | ||
| 80 | } | 80 | } | |||||
| 81 | 81 | |||||||
| HITCBC | 82 | 136 | std::size_t size() const noexcept | 82 | 136 | std::size_t size() const noexcept | ||
| 83 | { | 83 | { | |||||
| HITCBC | 84 | 136 | return n_; | 84 | 136 | return n_; | ||
| 85 | } | 85 | } | |||||
| 86 | 86 | |||||||
| HITCBC | 87 | 136 | operator core::string_view() const noexcept | 87 | 136 | operator core::string_view() const noexcept | ||
| 88 | { | 88 | { | |||||
| HITCBC | 89 | 136 | return { data(), size() }; | 89 | 136 | return { data(), size() }; | ||
| 90 | } | 90 | } | |||||
| 91 | 91 | |||||||
| 92 | operator std::string_view() const noexcept | 92 | operator std::string_view() const noexcept | |||||
| 93 | { | 93 | { | |||||
| 94 | return { data(), size() }; | 94 | return { data(), size() }; | |||||
| 95 | } | 95 | } | |||||
| 96 | }; | 96 | }; | |||||
| 97 | 97 | |||||||
| 98 | } // detail | 98 | } // detail | |||||
| 99 | } // http | 99 | } // http | |||||
| 100 | } // boost | 100 | } // boost | |||||
| 101 | 101 | |||||||
| 102 | #endif | 102 | #endif | |||||