100.00% Lines (177/177)
100.00% Functions (36/36)
| TLA | Baseline | Branch | ||||||
|---|---|---|---|---|---|---|---|---|
| Line | Hits | Code | Line | Hits | Code | |||
| 1 | // | 1 | // | |||||
| 2 | // Copyright (c) 2019 Vinnie Falco (vinnie.falco@gmail.com) | 2 | // Copyright (c) 2019 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/boostorg/json | 7 | // Official repository: https://github.com/boostorg/json | |||||
| 8 | // | 8 | // | |||||
| 9 | 9 | |||||||
| 10 | #ifndef BOOST_JSON_IMPL_STRING_IPP | 10 | #ifndef BOOST_JSON_IMPL_STRING_IPP | |||||
| 11 | #define BOOST_JSON_IMPL_STRING_IPP | 11 | #define BOOST_JSON_IMPL_STRING_IPP | |||||
| 12 | 12 | |||||||
| 13 | #include <boost/json/detail/except.hpp> | 13 | #include <boost/json/detail/except.hpp> | |||||
| 14 | #include <algorithm> | 14 | #include <algorithm> | |||||
| 15 | #include <new> | 15 | #include <new> | |||||
| 16 | #include <ostream> | 16 | #include <ostream> | |||||
| 17 | #include <stdexcept> | 17 | #include <stdexcept> | |||||
| 18 | #include <string> | 18 | #include <string> | |||||
| 19 | #include <utility> | 19 | #include <utility> | |||||
| 20 | 20 | |||||||
| 21 | namespace boost { | 21 | namespace boost { | |||||
| 22 | namespace json { | 22 | namespace json { | |||||
| 23 | 23 | |||||||
| 24 | //---------------------------------------------------------- | 24 | //---------------------------------------------------------- | |||||
| 25 | // | 25 | // | |||||
| 26 | // Construction | 26 | // Construction | |||||
| 27 | // | 27 | // | |||||
| 28 | //---------------------------------------------------------- | 28 | //---------------------------------------------------------- | |||||
| 29 | 29 | |||||||
| HITCBC | 30 | 78 | string:: | 30 | 78 | string:: | ||
| 31 | string( | 31 | string( | |||||
| 32 | std::size_t count, | 32 | std::size_t count, | |||||
| 33 | char ch, | 33 | char ch, | |||||
| HITCBC | 34 | 78 | storage_ptr sp) | 34 | 78 | storage_ptr sp) | ||
| HITCBC | 35 | 78 | : sp_(std::move(sp)) | 35 | 78 | : sp_(std::move(sp)) | ||
| 36 | { | 36 | { | |||||
| HITCBC | 37 | 78 | assign(count, ch); | 37 | 78 | assign(count, ch); | ||
| HITCBC | 38 | 78 | } | 38 | 78 | } | ||
| 39 | 39 | |||||||
| HITCBC | 40 | 177 | string:: | 40 | 177 | string:: | ||
| 41 | string( | 41 | string( | |||||
| 42 | char const* s, | 42 | char const* s, | |||||
| HITCBC | 43 | 177 | storage_ptr sp) | 43 | 177 | storage_ptr sp) | ||
| HITCBC | 44 | 177 | : sp_(std::move(sp)) | 44 | 177 | : sp_(std::move(sp)) | ||
| 45 | { | 45 | { | |||||
| HITCBC | 46 | 177 | assign(s); | 46 | 177 | assign(s); | ||
| HITCBC | 47 | 177 | } | 47 | 177 | } | ||
| 48 | 48 | |||||||
| HITCBC | 49 | 4 | string:: | 49 | 4 | string:: | ||
| 50 | string( | 50 | string( | |||||
| 51 | char const* s, | 51 | char const* s, | |||||
| 52 | std::size_t count, | 52 | std::size_t count, | |||||
| HITCBC | 53 | 4 | storage_ptr sp) | 53 | 4 | storage_ptr sp) | ||
| HITCBC | 54 | 4 | : sp_(std::move(sp)) | 54 | 4 | : sp_(std::move(sp)) | ||
| 55 | { | 55 | { | |||||
| HITCBC | 56 | 4 | assign(s, count); | 56 | 4 | assign(s, count); | ||
| HITCBC | 57 | 4 | } | 57 | 4 | } | ||
| 58 | 58 | |||||||
| HITCBC | 59 | 8 | string:: | 59 | 8 | string:: | ||
| HITCBC | 60 | 8 | string(string const& other) | 60 | 8 | string(string const& other) | ||
| HITCBC | 61 | 8 | : sp_(other.sp_) | 61 | 8 | : sp_(other.sp_) | ||
| 62 | { | 62 | { | |||||
| HITCBC | 63 | 8 | assign(other); | 63 | 8 | assign(other); | ||
| HITCBC | 64 | 8 | } | 64 | 8 | } | ||
| 65 | 65 | |||||||
| HITCBC | 66 | 158 | string:: | 66 | 158 | string:: | ||
| 67 | string( | 67 | string( | |||||
| 68 | string const& other, | 68 | string const& other, | |||||
| HITCBC | 69 | 158 | storage_ptr sp) | 69 | 158 | storage_ptr sp) | ||
| HITCBC | 70 | 158 | : sp_(std::move(sp)) | 70 | 158 | : sp_(std::move(sp)) | ||
| 71 | { | 71 | { | |||||
| HITCBC | 72 | 158 | assign(other); | 72 | 158 | assign(other); | ||
| HITCBC | 73 | 158 | } | 73 | 158 | } | ||
| 74 | 74 | |||||||
| HITCBC | 75 | 355 | string:: | 75 | 355 | string:: | ||
| 76 | string( | 76 | string( | |||||
| 77 | string&& other, | 77 | string&& other, | |||||
| HITCBC | 78 | 355 | storage_ptr sp) | 78 | 355 | storage_ptr sp) | ||
| HITCBC | 79 | 355 | : sp_(std::move(sp)) | 79 | 355 | : sp_(std::move(sp)) | ||
| 80 | { | 80 | { | |||||
| HITCBC | 81 | 355 | assign(std::move(other)); | 81 | 355 | assign(std::move(other)); | ||
| HITCBC | 82 | 355 | } | 82 | 355 | } | ||
| 83 | 83 | |||||||
| HITCBC | 84 | 17893 | string:: | 84 | 17893 | string:: | ||
| 85 | string( | 85 | string( | |||||
| 86 | string_view s, | 86 | string_view s, | |||||
| HITCBC | 87 | 17893 | storage_ptr sp) | 87 | 17893 | storage_ptr sp) | ||
| HITCBC | 88 | 17893 | : sp_(std::move(sp)) | 88 | 17893 | : sp_(std::move(sp)) | ||
| 89 | { | 89 | { | |||||
| HITCBC | 90 | 17893 | assign(s); | 90 | 17893 | assign(s); | ||
| HITCBC | 91 | 17893 | } | 91 | 17893 | } | ||
| 92 | 92 | |||||||
| 93 | //---------------------------------------------------------- | 93 | //---------------------------------------------------------- | |||||
| 94 | // | 94 | // | |||||
| 95 | // Assignment | 95 | // Assignment | |||||
| 96 | // | 96 | // | |||||
| 97 | //---------------------------------------------------------- | 97 | //---------------------------------------------------------- | |||||
| 98 | 98 | |||||||
| 99 | string& | 99 | string& | |||||
| HITCBC | 100 | 6 | string:: | 100 | 6 | string:: | ||
| 101 | operator=(string const& other) | 101 | operator=(string const& other) | |||||
| 102 | { | 102 | { | |||||
| HITCBC | 103 | 6 | return assign(other); | 103 | 6 | return assign(other); | ||
| 104 | } | 104 | } | |||||
| 105 | 105 | |||||||
| 106 | string& | 106 | string& | |||||
| HITCBC | 107 | 10 | string:: | 107 | 10 | string:: | ||
| 108 | operator=(string&& other) | 108 | operator=(string&& other) | |||||
| 109 | { | 109 | { | |||||
| HITCBC | 110 | 10 | return assign(std::move(other)); | 110 | 10 | return assign(std::move(other)); | ||
| 111 | } | 111 | } | |||||
| 112 | 112 | |||||||
| 113 | string& | 113 | string& | |||||
| HITCBC | 114 | 9 | string:: | 114 | 9 | string:: | ||
| 115 | operator=(char const* s) | 115 | operator=(char const* s) | |||||
| 116 | { | 116 | { | |||||
| HITCBC | 117 | 9 | return assign(s); | 117 | 9 | return assign(s); | ||
| 118 | } | 118 | } | |||||
| 119 | 119 | |||||||
| 120 | string& | 120 | string& | |||||
| HITCBC | 121 | 8 | string:: | 121 | 8 | string:: | ||
| 122 | operator=(string_view s) | 122 | operator=(string_view s) | |||||
| 123 | { | 123 | { | |||||
| HITCBC | 124 | 8 | return assign(s); | 124 | 8 | return assign(s); | ||
| 125 | } | 125 | } | |||||
| 126 | 126 | |||||||
| 127 | 127 | |||||||
| 128 | 128 | |||||||
| 129 | string& | 129 | string& | |||||
| HITCBC | 130 | 83 | string:: | 130 | 83 | string:: | ||
| 131 | assign( | 131 | assign( | |||||
| 132 | size_type count, | 132 | size_type count, | |||||
| 133 | char ch) | 133 | char ch) | |||||
| 134 | { | 134 | { | |||||
| HITCBC | 135 | 64 | std::char_traits<char>::assign( | 135 | 64 | std::char_traits<char>::assign( | ||
| HITCBC | 136 | 83 | impl_.assign(count, sp_), | 136 | 83 | impl_.assign(count, sp_), | ||
| 137 | count, | 137 | count, | |||||
| 138 | ch); | 138 | ch); | |||||
| HITCBC | 139 | 64 | return *this; | 139 | 64 | return *this; | ||
| 140 | } | 140 | } | |||||
| 141 | 141 | |||||||
| 142 | string& | 142 | string& | |||||
| HITCBC | 143 | 210 | string:: | 143 | 210 | string:: | ||
| 144 | assign( | 144 | assign( | |||||
| 145 | string const& other) | 145 | string const& other) | |||||
| 146 | { | 146 | { | |||||
| HITCBC | 147 | 210 | if(this == &other) | 147 | 210 | if(this == &other) | ||
| HITCBC | 148 | 1 | return *this; | 148 | 1 | return *this; | ||
| HITCBC | 149 | 209 | return assign( | 149 | 209 | return assign( | ||
| 150 | other.data(), | 150 | other.data(), | |||||
| HITCBC | 151 | 179 | other.size()); | 151 | 179 | other.size()); | ||
| 152 | } | 152 | } | |||||
| 153 | 153 | |||||||
| 154 | string& | 154 | string& | |||||
| HITCBC | 155 | 379 | string:: | 155 | 379 | string:: | ||
| 156 | assign(string&& other) | 156 | assign(string&& other) | |||||
| 157 | { | 157 | { | |||||
| HITCBC | 158 | 379 | if( &other == this ) | 158 | 379 | if( &other == this ) | ||
| HITCBC | 159 | 1 | return *this; | 159 | 1 | return *this; | ||
| 160 | 160 | |||||||
| HITCBC | 161 | 378 | if(*sp_ == *other.sp_) | 161 | 378 | if(*sp_ == *other.sp_) | ||
| 162 | { | 162 | { | |||||
| HITCBC | 163 | 340 | impl_.destroy(sp_); | 163 | 340 | impl_.destroy(sp_); | ||
| HITCBC | 164 | 340 | impl_ = other.impl_; | 164 | 340 | impl_ = other.impl_; | ||
| HITCBC | 165 | 340 | ::new(&other.impl_) detail::string_impl(); | 165 | 340 | ::new(&other.impl_) detail::string_impl(); | ||
| HITCBC | 166 | 340 | return *this; | 166 | 340 | return *this; | ||
| 167 | } | 167 | } | |||||
| 168 | 168 | |||||||
| 169 | // copy | 169 | // copy | |||||
| HITCBC | 170 | 38 | return assign(other); | 170 | 38 | return assign(other); | ||
| 171 | } | 171 | } | |||||
| 172 | 172 | |||||||
| 173 | string& | 173 | string& | |||||
| HITCBC | 174 | 18390 | string:: | 174 | 18390 | string:: | ||
| 175 | assign( | 175 | assign( | |||||
| 176 | char const* s, | 176 | char const* s, | |||||
| 177 | size_type count) | 177 | size_type count) | |||||
| 178 | { | 178 | { | |||||
| HITCBC | 179 | 18390 | auto const p = impl_.data(); | 179 | 18390 | auto const p = impl_.data(); | ||
| HITCBC | 180 | 18390 | if(detail::ptr_in_range(p, p + impl_.size(), s)) | 180 | 18390 | if(detail::ptr_in_range(p, p + impl_.size(), s)) | ||
| 181 | { | 181 | { | |||||
| HITCBC | 182 | 1 | std::char_traits<char>::move(p, s, count); | 182 | 1 | std::char_traits<char>::move(p, s, count); | ||
| HITCBC | 183 | 1 | impl_.term(count); | 183 | 1 | impl_.term(count); | ||
| 184 | } | 184 | } | |||||
| 185 | else | 185 | else | |||||
| 186 | { | 186 | { | |||||
| HITCBC | 187 | 18262 | std::char_traits<char>::copy( | 187 | 18262 | std::char_traits<char>::copy( | ||
| HITCBC | 188 | 18389 | impl_.assign(count, sp_), | 188 | 18389 | impl_.assign(count, sp_), | ||
| 189 | s, count); | 189 | s, count); | |||||
| 190 | } | 190 | } | |||||
| HITCBC | 191 | 18263 | return *this; | 191 | 18263 | return *this; | ||
| 192 | } | 192 | } | |||||
| 193 | 193 | |||||||
| 194 | string& | 194 | string& | |||||
| HITCBC | 195 | 191 | string:: | 195 | 191 | string:: | ||
| 196 | assign( | 196 | assign( | |||||
| 197 | char const* s) | 197 | char const* s) | |||||
| 198 | { | 198 | { | |||||
| HITCBC | 199 | 191 | return assign(s, std::char_traits< | 199 | 191 | return assign(s, std::char_traits< | ||
| HITCBC | 200 | 187 | char>::length(s)); | 200 | 187 | char>::length(s)); | ||
| 201 | } | 201 | } | |||||
| 202 | 202 | |||||||
| 203 | //---------------------------------------------------------- | 203 | //---------------------------------------------------------- | |||||
| 204 | // | 204 | // | |||||
| 205 | // Capacity | 205 | // Capacity | |||||
| 206 | // | 206 | // | |||||
| 207 | //---------------------------------------------------------- | 207 | //---------------------------------------------------------- | |||||
| 208 | 208 | |||||||
| 209 | void | 209 | void | |||||
| HITCBC | 210 | 9 | string:: | 210 | 9 | string:: | ||
| 211 | shrink_to_fit() | 211 | shrink_to_fit() | |||||
| 212 | { | 212 | { | |||||
| HITCBC | 213 | 9 | impl_.shrink_to_fit(sp_); | 213 | 9 | impl_.shrink_to_fit(sp_); | ||
| HITCBC | 214 | 9 | } | 214 | 9 | } | ||
| 215 | 215 | |||||||
| 216 | //---------------------------------------------------------- | 216 | //---------------------------------------------------------- | |||||
| 217 | // | 217 | // | |||||
| 218 | // Access | 218 | // Access | |||||
| 219 | // | 219 | // | |||||
| 220 | //---------------------------------------------------------- | 220 | //---------------------------------------------------------- | |||||
| 221 | 221 | |||||||
| 222 | system::result<char&> | 222 | system::result<char&> | |||||
| HITCBC | 223 | 12 | string::try_at(std::size_t pos) noexcept | 223 | 12 | string::try_at(std::size_t pos) noexcept | ||
| 224 | { | 224 | { | |||||
| HITCBC | 225 | 12 | if( pos < size() ) | 225 | 12 | if( pos < size() ) | ||
| HITCBC | 226 | 10 | return impl_.data()[pos]; | 226 | 10 | return impl_.data()[pos]; | ||
| 227 | 227 | |||||||
| HITCBC | 228 | 2 | system::error_code ec; | 228 | 2 | system::error_code ec; | ||
| HITCBC | 229 | 2 | BOOST_JSON_FAIL(ec, error::out_of_range); | 229 | 2 | BOOST_JSON_FAIL(ec, error::out_of_range); | ||
| HITCBC | 230 | 2 | return ec; | 230 | 2 | return ec; | ||
| 231 | } | 231 | } | |||||
| 232 | 232 | |||||||
| 233 | system::result<char const&> | 233 | system::result<char const&> | |||||
| HITCBC | 234 | 20 | string::try_at(std::size_t pos) const noexcept | 234 | 20 | string::try_at(std::size_t pos) const noexcept | ||
| 235 | { | 235 | { | |||||
| HITCBC | 236 | 20 | if( pos < size() ) | 236 | 20 | if( pos < size() ) | ||
| HITCBC | 237 | 18 | return impl_.data()[pos]; | 237 | 18 | return impl_.data()[pos]; | ||
| 238 | 238 | |||||||
| HITCBC | 239 | 2 | system::error_code ec; | 239 | 2 | system::error_code ec; | ||
| HITCBC | 240 | 2 | BOOST_JSON_FAIL(ec, error::out_of_range); | 240 | 2 | BOOST_JSON_FAIL(ec, error::out_of_range); | ||
| HITCBC | 241 | 2 | return ec; | 241 | 2 | return ec; | ||
| 242 | } | 242 | } | |||||
| 243 | 243 | |||||||
| 244 | char const& | 244 | char const& | |||||
| HITCBC | 245 | 18 | string::at(std::size_t pos, source_location const& loc) const | 245 | 18 | string::at(std::size_t pos, source_location const& loc) const | ||
| 246 | { | 246 | { | |||||
| HITCBC | 247 | 18 | return try_at(pos).value(loc); | 247 | 18 | return try_at(pos).value(loc); | ||
| 248 | } | 248 | } | |||||
| 249 | 249 | |||||||
| 250 | //---------------------------------------------------------- | 250 | //---------------------------------------------------------- | |||||
| 251 | // | 251 | // | |||||
| 252 | // Operations | 252 | // Operations | |||||
| 253 | // | 253 | // | |||||
| 254 | //---------------------------------------------------------- | 254 | //---------------------------------------------------------- | |||||
| 255 | 255 | |||||||
| 256 | void | 256 | void | |||||
| HITCBC | 257 | 2 | string:: | 257 | 2 | string:: | ||
| 258 | clear() noexcept | 258 | clear() noexcept | |||||
| 259 | { | 259 | { | |||||
| HITCBC | 260 | 2 | impl_.term(0); | 260 | 2 | impl_.term(0); | ||
| HITCBC | 261 | 2 | } | 261 | 2 | } | ||
| 262 | 262 | |||||||
| 263 | //---------------------------------------------------------- | 263 | //---------------------------------------------------------- | |||||
| 264 | 264 | |||||||
| 265 | void | 265 | void | |||||
| HITCBC | 266 | 178 | string:: | 266 | 178 | string:: | ||
| 267 | push_back(char ch) | 267 | push_back(char ch) | |||||
| 268 | { | 268 | { | |||||
| HITCBC | 269 | 178 | *impl_.append(1, sp_) = ch; | 269 | 178 | *impl_.append(1, sp_) = ch; | ||
| HITCBC | 270 | 176 | } | 270 | 176 | } | ||
| 271 | 271 | |||||||
| 272 | void | 272 | void | |||||
| HITCBC | 273 | 29 | string:: | 273 | 29 | string:: | ||
| 274 | pop_back() | 274 | pop_back() | |||||
| 275 | { | 275 | { | |||||
| HITCBC | 276 | 29 | back() = 0; | 276 | 29 | back() = 0; | ||
| HITCBC | 277 | 29 | impl_.size(impl_.size() - 1); | 277 | 29 | impl_.size(impl_.size() - 1); | ||
| HITCBC | 278 | 29 | } | 278 | 29 | } | ||
| 279 | 279 | |||||||
| 280 | //---------------------------------------------------------- | 280 | //---------------------------------------------------------- | |||||
| 281 | 281 | |||||||
| 282 | string& | 282 | string& | |||||
| HITCBC | 283 | 4 | string:: | 283 | 4 | string:: | ||
| 284 | append(size_type count, char ch) | 284 | append(size_type count, char ch) | |||||
| 285 | { | 285 | { | |||||
| HITCBC | 286 | 2 | std::char_traits<char>::assign( | 286 | 2 | std::char_traits<char>::assign( | ||
| HITCBC | 287 | 4 | impl_.append(count, sp_), | 287 | 4 | impl_.append(count, sp_), | ||
| 288 | count, ch); | 288 | count, ch); | |||||
| HITCBC | 289 | 2 | return *this; | 289 | 2 | return *this; | ||
| 290 | } | 290 | } | |||||
| 291 | 291 | |||||||
| 292 | string& | 292 | string& | |||||
| HITCBC | 293 | 58 | string:: | 293 | 58 | string:: | ||
| 294 | append(string_view sv) | 294 | append(string_view sv) | |||||
| 295 | { | 295 | { | |||||
| HITCBC | 296 | 58 | auto const p = impl_.data(); | 296 | 58 | auto const p = impl_.data(); | ||
| HITCBC | 297 | 58 | if(detail::ptr_in_range(p, p + impl_.size(), sv.data())) | 297 | 58 | if(detail::ptr_in_range(p, p + impl_.size(), sv.data())) | ||
| 298 | { | 298 | { | |||||
| 299 | // sv aliases our own storage; appending may reallocate and free the | 299 | // sv aliases our own storage; appending may reallocate and free the | |||||
| 300 | // buffer sv points into, so copy from the relocated offset afterwards | 300 | // buffer sv points into, so copy from the relocated offset afterwards | |||||
| HITCBC | 301 | 10 | auto const offset = sv.data() - p; | 301 | 10 | auto const offset = sv.data() - p; | ||
| HITCBC | 302 | 10 | auto const dest = impl_.append(sv.size(), sp_); | 302 | 10 | auto const dest = impl_.append(sv.size(), sp_); | ||
| HITCBC | 303 | 8 | std::char_traits<char>::copy( | 303 | 8 | std::char_traits<char>::copy( | ||
| HITCBC | 304 | 8 | dest, impl_.data() + offset, sv.size()); | 304 | 8 | dest, impl_.data() + offset, sv.size()); | ||
| 305 | } | 305 | } | |||||
| 306 | else | 306 | else | |||||
| 307 | { | 307 | { | |||||
| HITCBC | 308 | 96 | std::char_traits<char>::copy( | 308 | 96 | std::char_traits<char>::copy( | ||
| HITCBC | 309 | 48 | impl_.append(sv.size(), sp_), | 309 | 48 | impl_.append(sv.size(), sp_), | ||
| 310 | sv.data(), sv.size()); | 310 | sv.data(), sv.size()); | |||||
| 311 | } | 311 | } | |||||
| HITCBC | 312 | 42 | return *this; | 312 | 42 | return *this; | ||
| 313 | } | 313 | } | |||||
| 314 | 314 | |||||||
| 315 | //---------------------------------------------------------- | 315 | //---------------------------------------------------------- | |||||
| 316 | 316 | |||||||
| 317 | string& | 317 | string& | |||||
| HITCBC | 318 | 27 | string:: | 318 | 27 | string:: | ||
| 319 | insert( | 319 | insert( | |||||
| 320 | size_type pos, | 320 | size_type pos, | |||||
| 321 | string_view sv) | 321 | string_view sv) | |||||
| 322 | { | 322 | { | |||||
| HITCBC | 323 | 27 | impl_.insert(pos, sv.data(), sv.size(), sp_); | 323 | 27 | impl_.insert(pos, sv.data(), sv.size(), sp_); | ||
| HITCBC | 324 | 17 | return *this; | 324 | 17 | return *this; | ||
| 325 | } | 325 | } | |||||
| 326 | 326 | |||||||
| 327 | string& | 327 | string& | |||||
| HITCBC | 328 | 11 | string:: | 328 | 11 | string:: | ||
| 329 | insert( | 329 | insert( | |||||
| 330 | std::size_t pos, | 330 | std::size_t pos, | |||||
| 331 | std::size_t count, | 331 | std::size_t count, | |||||
| 332 | char ch) | 332 | char ch) | |||||
| 333 | { | 333 | { | |||||
| HITCBC | 334 | 6 | std::char_traits<char>::assign( | 334 | 6 | std::char_traits<char>::assign( | ||
| HITCBC | 335 | 11 | impl_.insert_unchecked(pos, count, sp_), | 335 | 11 | impl_.insert_unchecked(pos, count, sp_), | ||
| 336 | count, ch); | 336 | count, ch); | |||||
| HITCBC | 337 | 6 | return *this; | 337 | 6 | return *this; | ||
| 338 | } | 338 | } | |||||
| 339 | 339 | |||||||
| 340 | //---------------------------------------------------------- | 340 | //---------------------------------------------------------- | |||||
| 341 | 341 | |||||||
| 342 | string& | 342 | string& | |||||
| HITCBC | 343 | 19 | string:: | 343 | 19 | string:: | ||
| 344 | replace( | 344 | replace( | |||||
| 345 | std::size_t pos, | 345 | std::size_t pos, | |||||
| 346 | std::size_t count, | 346 | std::size_t count, | |||||
| 347 | string_view sv) | 347 | string_view sv) | |||||
| 348 | { | 348 | { | |||||
| HITCBC | 349 | 19 | impl_.replace(pos, count, sv.data(), sv.size(), sp_); | 349 | 19 | impl_.replace(pos, count, sv.data(), sv.size(), sp_); | ||
| HITCBC | 350 | 15 | return *this; | 350 | 15 | return *this; | ||
| 351 | } | 351 | } | |||||
| 352 | 352 | |||||||
| 353 | string& | 353 | string& | |||||
| HITCBC | 354 | 11 | string:: | 354 | 11 | string:: | ||
| 355 | replace( | 355 | replace( | |||||
| 356 | std::size_t pos, | 356 | std::size_t pos, | |||||
| 357 | std::size_t count, | 357 | std::size_t count, | |||||
| 358 | std::size_t count2, | 358 | std::size_t count2, | |||||
| 359 | char ch) | 359 | char ch) | |||||
| 360 | { | 360 | { | |||||
| HITCBC | 361 | 7 | std::char_traits<char>::assign( | 361 | 7 | std::char_traits<char>::assign( | ||
| HITCBC | 362 | 11 | impl_.replace_unchecked(pos, count, count2, sp_), | 362 | 11 | impl_.replace_unchecked(pos, count, count2, sp_), | ||
| 363 | count2, ch); | 363 | count2, ch); | |||||
| HITCBC | 364 | 7 | return *this; | 364 | 7 | return *this; | ||
| 365 | } | 365 | } | |||||
| 366 | 366 | |||||||
| 367 | //---------------------------------------------------------- | 367 | //---------------------------------------------------------- | |||||
| 368 | 368 | |||||||
| 369 | string& | 369 | string& | |||||
| HITCBC | 370 | 10 | string:: | 370 | 10 | string:: | ||
| 371 | erase( | 371 | erase( | |||||
| 372 | size_type pos, | 372 | size_type pos, | |||||
| 373 | size_type count) | 373 | size_type count) | |||||
| 374 | { | 374 | { | |||||
| HITCBC | 375 | 10 | if(pos > impl_.size()) | 375 | 10 | if(pos > impl_.size()) | ||
| 376 | { | 376 | { | |||||
| 377 | BOOST_STATIC_CONSTEXPR source_location loc = BOOST_CURRENT_LOCATION; | 377 | BOOST_STATIC_CONSTEXPR source_location loc = BOOST_CURRENT_LOCATION; | |||||
| HITCBC | 378 | 1 | detail::throw_system_error( error::out_of_range, &loc ); | 378 | 1 | detail::throw_system_error( error::out_of_range, &loc ); | ||
| 379 | } | 379 | } | |||||
| HITCBC | 380 | 9 | if( count > impl_.size() - pos) | 380 | 9 | if( count > impl_.size() - pos) | ||
| HITCBC | 381 | 4 | count = impl_.size() - pos; | 381 | 4 | count = impl_.size() - pos; | ||
| HITCBC | 382 | 9 | std::char_traits<char>::move( | 382 | 9 | std::char_traits<char>::move( | ||
| HITCBC | 383 | 9 | impl_.data() + pos, | 383 | 9 | impl_.data() + pos, | ||
| HITCBC | 384 | 9 | impl_.data() + pos + count, | 384 | 9 | impl_.data() + pos + count, | ||
| HITCBC | 385 | 9 | impl_.size() - pos - count + 1); | 385 | 9 | impl_.size() - pos - count + 1); | ||
| HITCBC | 386 | 9 | impl_.term(impl_.size() - count); | 386 | 9 | impl_.term(impl_.size() - count); | ||
| HITCBC | 387 | 9 | return *this; | 387 | 9 | return *this; | ||
| 388 | } | 388 | } | |||||
| 389 | 389 | |||||||
| 390 | auto | 390 | auto | |||||
| HITCBC | 391 | 2 | string:: | 391 | 2 | string:: | ||
| 392 | erase(const_iterator pos) -> | 392 | erase(const_iterator pos) -> | |||||
| 393 | iterator | 393 | iterator | |||||
| 394 | { | 394 | { | |||||
| HITCBC | 395 | 2 | return erase(pos, pos+1); | 395 | 2 | return erase(pos, pos+1); | ||
| 396 | } | 396 | } | |||||
| 397 | 397 | |||||||
| 398 | auto | 398 | auto | |||||
| HITCBC | 399 | 3 | string:: | 399 | 3 | string:: | ||
| 400 | erase( | 400 | erase( | |||||
| 401 | const_iterator first, | 401 | const_iterator first, | |||||
| 402 | const_iterator last) -> | 402 | const_iterator last) -> | |||||
| 403 | iterator | 403 | iterator | |||||
| 404 | { | 404 | { | |||||
| HITCBC | 405 | 3 | auto const pos = first - begin(); | 405 | 3 | auto const pos = first - begin(); | ||
| HITCBC | 406 | 3 | auto const count = last - first; | 406 | 3 | auto const count = last - first; | ||
| HITCBC | 407 | 3 | erase(pos, count); | 407 | 3 | erase(pos, count); | ||
| HITCBC | 408 | 3 | return data() + pos; | 408 | 3 | return data() + pos; | ||
| 409 | } | 409 | } | |||||
| 410 | 410 | |||||||
| 411 | //---------------------------------------------------------- | 411 | //---------------------------------------------------------- | |||||
| 412 | 412 | |||||||
| 413 | void | 413 | void | |||||
| HITCBC | 414 | 68 | string:: | 414 | 68 | string:: | ||
| 415 | resize(size_type count, char ch) | 415 | resize(size_type count, char ch) | |||||
| 416 | { | 416 | { | |||||
| HITCBC | 417 | 68 | if(count <= impl_.size()) | 417 | 68 | if(count <= impl_.size()) | ||
| 418 | { | 418 | { | |||||
| HITCBC | 419 | 27 | impl_.term(count); | 419 | 27 | impl_.term(count); | ||
| HITCBC | 420 | 27 | return; | 420 | 27 | return; | ||
| 421 | } | 421 | } | |||||
| 422 | 422 | |||||||
| HITCBC | 423 | 41 | reserve(count); | 423 | 41 | reserve(count); | ||
| HITCBC | 424 | 35 | std::char_traits<char>::assign( | 424 | 35 | std::char_traits<char>::assign( | ||
| 425 | impl_.end(), | 425 | impl_.end(), | |||||
| HITCBC | 426 | 35 | count - impl_.size(), | 426 | 35 | count - impl_.size(), | ||
| 427 | ch); | 427 | ch); | |||||
| HITCBC | 428 | 35 | grow(count - size()); | 428 | 35 | grow(count - size()); | ||
| 429 | } | 429 | } | |||||
| 430 | 430 | |||||||
| 431 | //---------------------------------------------------------- | 431 | //---------------------------------------------------------- | |||||
| 432 | 432 | |||||||
| 433 | void | 433 | void | |||||
| HITCBC | 434 | 4 | string:: | 434 | 4 | string:: | ||
| 435 | swap(string& other) | 435 | swap(string& other) | |||||
| 436 | { | 436 | { | |||||
| HITCBC | 437 | 4 | if(*sp_ == *other.sp_) | 437 | 4 | if(*sp_ == *other.sp_) | ||
| 438 | { | 438 | { | |||||
| HITCBC | 439 | 3 | std::swap(impl_, other.impl_); | 439 | 3 | std::swap(impl_, other.impl_); | ||
| HITCBC | 440 | 3 | return; | 440 | 3 | return; | ||
| 441 | } | 441 | } | |||||
| 442 | string temp1( | 442 | string temp1( | |||||
| HITCBC | 443 | 1 | std::move(*this), other.sp_); | 443 | 1 | std::move(*this), other.sp_); | ||
| 444 | string temp2( | 444 | string temp2( | |||||
| HITCBC | 445 | 1 | std::move(other), sp_); | 445 | 1 | std::move(other), sp_); | ||
| HITCBC | 446 | 1 | this->~string(); | 446 | 1 | this->~string(); | ||
| HITCBC | 447 | 1 | ::new(this) string(pilfer(temp2)); | 447 | 1 | ::new(this) string(pilfer(temp2)); | ||
| HITCBC | 448 | 1 | other.~string(); | 448 | 1 | other.~string(); | ||
| HITCBC | 449 | 1 | ::new(&other) string(pilfer(temp1)); | 449 | 1 | ::new(&other) string(pilfer(temp1)); | ||
| HITCBC | 450 | 1 | } | 450 | 1 | } | ||
| 451 | 451 | |||||||
| 452 | //---------------------------------------------------------- | 452 | //---------------------------------------------------------- | |||||
| 453 | 453 | |||||||
| 454 | void | 454 | void | |||||
| HITCBC | 455 | 9686 | string:: | 455 | 9686 | string:: | ||
| 456 | reserve_impl(size_type new_cap) | 456 | reserve_impl(size_type new_cap) | |||||
| 457 | { | 457 | { | |||||
| HITCBC | 458 | 9686 | BOOST_ASSERT( | 458 | 9686 | BOOST_ASSERT( | ||
| 459 | new_cap >= impl_.capacity()); | 459 | new_cap >= impl_.capacity()); | |||||
| HITCBC | 460 | 9686 | if(new_cap > impl_.capacity()) | 460 | 9686 | if(new_cap > impl_.capacity()) | ||
| 461 | { | 461 | { | |||||
| 462 | // grow | 462 | // grow | |||||
| HITCBC | 463 | 9686 | new_cap = detail::string_impl::growth( | 463 | 9686 | new_cap = detail::string_impl::growth( | ||
| 464 | new_cap, impl_.capacity()); | 464 | new_cap, impl_.capacity()); | |||||
| HITCBC | 465 | 9685 | detail::string_impl tmp(new_cap, sp_); | 465 | 9685 | detail::string_impl tmp(new_cap, sp_); | ||
| HITCBC | 466 | 9675 | std::char_traits<char>::copy(tmp.data(), | 466 | 9675 | std::char_traits<char>::copy(tmp.data(), | ||
| HITCBC | 467 | 9675 | impl_.data(), impl_.size() + 1); | 467 | 9675 | impl_.data(), impl_.size() + 1); | ||
| HITCBC | 468 | 9675 | tmp.size(impl_.size()); | 468 | 9675 | tmp.size(impl_.size()); | ||
| HITCBC | 469 | 9675 | impl_.destroy(sp_); | 469 | 9675 | impl_.destroy(sp_); | ||
| HITCBC | 470 | 9675 | impl_ = tmp; | 470 | 9675 | impl_ = tmp; | ||
| HITCBC | 471 | 9675 | return; | 471 | 9675 | return; | ||
| 472 | } | 472 | } | |||||
| 473 | } | 473 | } | |||||
| 474 | 474 | |||||||
| 475 | } // namespace json | 475 | } // namespace json | |||||
| 476 | } // namespace boost | 476 | } // namespace boost | |||||
| 477 | 477 | |||||||
| 478 | //---------------------------------------------------------- | 478 | //---------------------------------------------------------- | |||||
| 479 | 479 | |||||||
| 480 | std::size_t | 480 | std::size_t | |||||
| HITCBC | 481 | 3 | std::hash< ::boost::json::string >::operator()( | 481 | 3 | std::hash< ::boost::json::string >::operator()( | ||
| 482 | ::boost::json::string const& js ) const noexcept | 482 | ::boost::json::string const& js ) const noexcept | |||||
| 483 | { | 483 | { | |||||
| HITCBC | 484 | 3 | return ::boost::hash< ::boost::json::string >()( js ); | 484 | 3 | return ::boost::hash< ::boost::json::string >()( js ); | ||
| 485 | } | 485 | } | |||||
| 486 | 486 | |||||||
| 487 | #endif | 487 | #endif | |||||