| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /* GATE PROJECT LICENSE: | ||
| 2 | +----------------------------------------------------------------------------+ | ||
| 3 | | Copyright(c) 2018-2025, Stefan Meislinger <sm@opengate.at> | | ||
| 4 | | All rights reserved. | | ||
| 5 | | | | ||
| 6 | | Redistribution and use in source and binary forms, with or without | | ||
| 7 | | modification, are permitted provided that the following conditions are met:| | ||
| 8 | | | | ||
| 9 | | 1. Redistributions of source code must retain the above copyright notice, | | ||
| 10 | | this list of conditions and the following disclaimer. | | ||
| 11 | | 2. Redistributions in binary form must reproduce the above copyright | | ||
| 12 | | notice, this list of conditions and the following disclaimer in the | | ||
| 13 | | documentation and/or other materials provided with the distribution. | | ||
| 14 | | | | ||
| 15 | | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"| | ||
| 16 | | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | | ||
| 17 | | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | | ||
| 18 | | ARE DISCLAIMED.IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE | | ||
| 19 | | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | | ||
| 20 | | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | | ||
| 21 | | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | | ||
| 22 | | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | | ||
| 23 | | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | | ||
| 24 | | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF | | ||
| 25 | | THE POSSIBILITY OF SUCH DAMAGE. | | ||
| 26 | +----------------------------------------------------------------------------+ | ||
| 27 | */ | ||
| 28 | |||
| 29 | #include "gate/strings.hpp" | ||
| 30 | #include "gate/exceptions.hpp" | ||
| 31 | #include "gate/memalloc.hpp" | ||
| 32 | |||
| 33 | namespace gate | ||
| 34 | { | ||
| 35 | |||
| 36 | 1 | int Char::toLower(int chr) | |
| 37 | { | ||
| 38 | 1 | return gate_char_lowercase(chr); | |
| 39 | } | ||
| 40 | 1 | int Char::toUpper(int chr) | |
| 41 | { | ||
| 42 | 1 | return gate_char_uppercase(chr); | |
| 43 | } | ||
| 44 | 2 | bool_t Char::isDigit(int chr) | |
| 45 | { | ||
| 46 | 2 | return gate_char_is_digit(chr); | |
| 47 | } | ||
| 48 | 2 | bool_t Char::isWhitespace(int chr) | |
| 49 | { | ||
| 50 | 2 | return gate_char_is_whitespace(chr); | |
| 51 | } | ||
| 52 | |||
| 53 | 1 | size_t Char::readUtf8(char_8_t const* utf8text, size_t length, char_32_t& chr32) | |
| 54 | { | ||
| 55 | 1 | return gate_char_read_utf8(utf8text, length, &chr32); | |
| 56 | } | ||
| 57 | 1 | size_t Char::readUtf16(char_16_t const* utf16text, size_t length, char_32_t& chr32) | |
| 58 | { | ||
| 59 | 1 | return gate_char_read_utf16(utf16text, length, &chr32); | |
| 60 | } | ||
| 61 | 1 | size_t Char::readUtf32(char_32_t const* utf32text, size_t length, char_32_t& chr32) | |
| 62 | { | ||
| 63 | 1 | return gate_char_read_utf32(utf32text, length, &chr32); | |
| 64 | } | ||
| 65 | |||
| 66 | 1 | size_t Char::writeUtf8(char_32_t chr32, char_8_t* utf8text, size_t length) | |
| 67 | { | ||
| 68 | 1 | return gate_char_write_utf8(chr32, utf8text, length); | |
| 69 | } | ||
| 70 | 1 | size_t Char::writeUtf16(char_32_t chr32, char_16_t* utf16text, size_t length) | |
| 71 | { | ||
| 72 | 1 | return gate_char_write_utf16(chr32, utf16text, length); | |
| 73 | } | ||
| 74 | 1 | size_t Char::writeUtf32(char_32_t chr32, char_32_t* utf32text, size_t length) | |
| 75 | { | ||
| 76 | 1 | return gate_char_write_utf32(chr32, utf32text, length); | |
| 77 | } | ||
| 78 | |||
| 79 | |||
| 80 | size_t const String::npos = GATE_STR_NPOS; | ||
| 81 | size_t const String::NPOS = GATE_STR_NPOS; | ||
| 82 | |||
| 83 | 3062 | String::String() noexcept | |
| 84 | { | ||
| 85 | 3062 | gate_string_create_empty(&this->impl); | |
| 86 | 3062 | } | |
| 87 | 898 | String::String(char_8_t const* str) | |
| 88 | { | ||
| 89 |
1/2✗ Branch 2 not taken.
✓ Branch 3 taken 898 times.
|
898 | if (NULL == gate_string_create(&this->impl, str, gate_str_length(str))) |
| 90 | { | ||
| 91 | ✗ | GATEXX_RAISE_ERROR(results::OutOfMemory); | |
| 92 | } | ||
| 93 | 898 | } | |
| 94 | 212 | String::String(char_8_t const* str, size_t len) | |
| 95 | { | ||
| 96 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 212 times.
|
212 | if (NULL == gate_string_create(&this->impl, str, len)) |
| 97 | { | ||
| 98 | ✗ | GATEXX_RAISE_ERROR(results::OutOfMemory); | |
| 99 | } | ||
| 100 | 212 | } | |
| 101 | 514 | String::String(String const& src) noexcept | |
| 102 | { | ||
| 103 | 514 | gate_string_duplicate(&this->impl, &src.impl); | |
| 104 | 514 | } | |
| 105 | 11 | String::String(gate_string_t const& src) | |
| 106 | { | ||
| 107 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 11 times.
|
11 | if (NULL == gate_string_clone(&this->impl, &src)) |
| 108 | { | ||
| 109 | ✗ | GATEXX_RAISE_ERROR(results::OutOfMemory); | |
| 110 | } | ||
| 111 | 11 | } | |
| 112 | ✗ | String::String(StringBuilder& strbuilder) | |
| 113 | { | ||
| 114 | ✗ | gate_string_create_empty(&this->impl); | |
| 115 | ✗ | String tmp = strbuilder.toString(); | |
| 116 | ✗ | this->swap(tmp); | |
| 117 | ✗ | } | |
| 118 | |||
| 119 | |||
| 120 | |||
| 121 | 15 | String& String::operator=(String const& src) noexcept | |
| 122 | { | ||
| 123 |
1/2✓ Branch 0 taken 15 times.
✗ Branch 1 not taken.
|
15 | if (this != &src) |
| 124 | { | ||
| 125 | 30 | String that(src); | |
| 126 | 15 | this->swap(that); | |
| 127 | } | ||
| 128 | 15 | return *this; | |
| 129 | } | ||
| 130 | |||
| 131 | 9388 | String::~String() noexcept | |
| 132 | { | ||
| 133 | 4694 | gate_string_release(&this->impl); | |
| 134 | 4694 | } | |
| 135 | |||
| 136 | #if defined(GATE_COMPILER_SUPPORTS_CPP_MOVEREFS) | ||
| 137 | 1 | String::String(String&& src) noexcept | |
| 138 | { | ||
| 139 | 1 | gate_string_create_empty(&this->impl); | |
| 140 | 1 | gate::swapRefs(this->impl, src.impl); | |
| 141 | 1 | } | |
| 142 | |||
| 143 | 391 | String& String::operator=(String&& src) noexcept | |
| 144 | { | ||
| 145 | 391 | gate::swapRefs(this->impl, src.impl); | |
| 146 | 391 | return *this; | |
| 147 | } | ||
| 148 | #endif | ||
| 149 | |||
| 150 | 482 | String String::createStatic(char_8_t const* str) noexcept | |
| 151 | { | ||
| 152 | 482 | String tmp; | |
| 153 | 482 | gate_string_create_static(&tmp.impl, str); | |
| 154 | 482 | return tmp; | |
| 155 | } | ||
| 156 | 234 | String String::createStatic(char_8_t const* str, size_t len) noexcept | |
| 157 | { | ||
| 158 | 234 | String tmp; | |
| 159 | 234 | gate_string_create_static_len(&tmp.impl, str, len); | |
| 160 | 234 | return tmp; | |
| 161 | } | ||
| 162 | 354 | String String::createFrom(gate_string_t& str) noexcept | |
| 163 | { | ||
| 164 | 354 | String ret; | |
| 165 | 354 | ret.impl = str; | |
| 166 | 354 | gate_string_create_empty(&str); | |
| 167 | 354 | return ret; | |
| 168 | } | ||
| 169 | 1 | String String::createFilled(size_t count, char_8_t content) | |
| 170 | { | ||
| 171 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 | StringBuilder builder(count); |
| 172 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | builder.appendChars(count, content); |
| 173 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 | return builder.toString(); |
| 174 | } | ||
| 175 | |||
| 176 | |||
| 177 | 1 | String String::createIntNum(int64_t num) | |
| 178 | { | ||
| 179 | char buffer[64]; | ||
| 180 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | size_t len = gate_str_print_int64(buffer, sizeof(buffer), num); |
| 181 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 | return String(buffer, len); |
| 182 | } | ||
| 183 | 1 | String String::createRealNum(real64_t num, int32_t decimalCount) | |
| 184 | { | ||
| 185 | char buffer[64]; | ||
| 186 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | size_t len = gate_str_print_real(buffer, sizeof(buffer), num, 0, decimalCount, 0); |
| 187 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 | return String(buffer, len); |
| 188 | } | ||
| 189 | |||
| 190 | 57 | void String::assign(gate_string_t& dst, gate_string_t const& src) | |
| 191 | { | ||
| 192 | 57 | gate_string_t tmp = GATE_STRING_INIT_EMPTY; | |
| 193 |
2/4✓ Branch 1 taken 57 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 57 times.
|
57 | if (NULL == gate_string_clone(&tmp, &src)) |
| 194 | { | ||
| 195 | ✗ | GATEXX_RAISE_ERROR(results::OutOfMemory); | |
| 196 | } | ||
| 197 |
1/2✓ Branch 1 taken 57 times.
✗ Branch 2 not taken.
|
57 | gate_string_release(&dst); |
| 198 | 57 | dst = tmp; | |
| 199 | 57 | } | |
| 200 | |||
| 201 | 5 | void String::assign(gate_string_t& dst, String const& src) | |
| 202 | { | ||
| 203 | 5 | String::assign(dst, *src.c_impl()); | |
| 204 | 5 | } | |
| 205 | |||
| 206 | |||
| 207 | |||
| 208 | 20 | void String::swap(String& that) noexcept | |
| 209 | { | ||
| 210 | 20 | gate::swapRefsNoExcept(this->impl, that.impl); | |
| 211 | 20 | } | |
| 212 | 5 | void String::swap(gate_string_t& that) noexcept | |
| 213 | { | ||
| 214 | 5 | gate::swapRefsNoExcept(this->impl, that); | |
| 215 | 5 | } | |
| 216 | 1 | void String::swap(gate_string_t& a, gate_string_t& b) noexcept | |
| 217 | { | ||
| 218 | 1 | gate::swapRefsNoExcept(a, b); | |
| 219 | 1 | } | |
| 220 | |||
| 221 | |||
| 222 | |||
| 223 | 1225 | size_t String::size() const noexcept | |
| 224 | { | ||
| 225 | 1225 | return gate_string_length(&this->impl); | |
| 226 | } | ||
| 227 | 3001 | size_t String::length() const noexcept | |
| 228 | { | ||
| 229 | 3001 | return gate_string_length(&this->impl); | |
| 230 | } | ||
| 231 | 195 | bool String::empty() const noexcept | |
| 232 | { | ||
| 233 | 195 | return this->size() == 0; | |
| 234 | } | ||
| 235 | 1587 | char_8_t const* String::c_str() const noexcept | |
| 236 | { | ||
| 237 | 1587 | return gate_string_ptr(&this->impl, 0); | |
| 238 | } | ||
| 239 | |||
| 240 | 1 | char_8_t const& String::at(size_t index) const noexcept | |
| 241 | { | ||
| 242 | 1 | return *gate_string_ptr(&this->impl, index); | |
| 243 | } | ||
| 244 | |||
| 245 | 919 | gate_string_t const* String::c_impl() const noexcept | |
| 246 | { | ||
| 247 | 919 | return &this->impl; | |
| 248 | } | ||
| 249 | |||
| 250 | 1 | String::const_iterator String::cbegin() const noexcept | |
| 251 | { | ||
| 252 | 1 | return gate_string_ptr(&this->impl, 0); | |
| 253 | } | ||
| 254 | 4 | String::const_iterator String::cend() const noexcept | |
| 255 | { | ||
| 256 | 4 | return gate_string_ptr(&this->impl, 0) + gate_string_length(&this->impl); | |
| 257 | } | ||
| 258 | |||
| 259 | 1 | String::const_iterator String::begin() const noexcept | |
| 260 | { | ||
| 261 | 1 | return this->cbegin(); | |
| 262 | } | ||
| 263 | 4 | String::const_iterator String::end() const noexcept | |
| 264 | { | ||
| 265 | 4 | return this->cend(); | |
| 266 | } | ||
| 267 | |||
| 268 | 4 | size_t String::positionOf(String const& text, size_t startAt) const noexcept | |
| 269 | { | ||
| 270 | 4 | return gate_string_pos(&this->impl, text.c_impl(), startAt); | |
| 271 | } | ||
| 272 | 1 | size_t String::positionOf(char const& chr, size_t startAt) const noexcept | |
| 273 | { | ||
| 274 | 1 | return gate_string_char_pos(&this->impl, chr, startAt); | |
| 275 | } | ||
| 276 | |||
| 277 | 2 | size_t String::positionOfLast(String const& text) const noexcept | |
| 278 | { | ||
| 279 | 2 | size_t pos = gate_string_pos_last(&this->impl, text.c_impl()); | |
| 280 | 2 | return pos; | |
| 281 | } | ||
| 282 | 1 | size_t String::positionOfLast(char const& chr) const noexcept | |
| 283 | { | ||
| 284 | 1 | return gate_string_char_pos_last(&this->impl, chr); | |
| 285 | } | ||
| 286 | |||
| 287 | |||
| 288 | 1 | size_t String::findFirstOf(String const& text, size_t startAt) const noexcept | |
| 289 | { | ||
| 290 | 1 | return gate_string_find_first_of(&this->impl, text.c_impl(), startAt); | |
| 291 | } | ||
| 292 | 1 | size_t String::findFirstNotOf(String const& text, size_t startAt) const noexcept | |
| 293 | { | ||
| 294 | 1 | return gate_string_find_first_not_of(&this->impl, text.c_impl(), startAt); | |
| 295 | } | ||
| 296 | 1 | size_t String::findLastOf(String const& text) const noexcept | |
| 297 | { | ||
| 298 | 1 | return gate_string_find_last_of(&this->impl, text.c_impl()); | |
| 299 | } | ||
| 300 | 1 | size_t String::findLastNotOf(String const& text) const noexcept | |
| 301 | { | ||
| 302 | 1 | return gate_string_find_last_not_of(&this->impl, text.c_impl()); | |
| 303 | } | ||
| 304 | |||
| 305 | 4 | String String::substr(size_t offset, size_t len) const | |
| 306 | { | ||
| 307 | 4 | String ret; | |
| 308 |
1/2✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
|
4 | gate_string_substr(&ret.impl, &this->impl, offset, len); |
| 309 | 4 | return ret; | |
| 310 | } | ||
| 311 | 2 | String String::left(size_t len) const | |
| 312 | { | ||
| 313 | 2 | return this->substr(0, len); | |
| 314 | } | ||
| 315 | 2 | String String::right(size_t len) const | |
| 316 | { | ||
| 317 | 2 | size_t sz = this->size(); | |
| 318 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
|
2 | if (len >= sz) |
| 319 | { | ||
| 320 | 1 | return *this; | |
| 321 | } | ||
| 322 | else | ||
| 323 | { | ||
| 324 | 1 | return this->substr(sz - len, len); | |
| 325 | } | ||
| 326 | } | ||
| 327 | 2 | String String::readLine(String& tail) const | |
| 328 | { | ||
| 329 | gate_string_t str_line; | ||
| 330 | gate_string_t str_tail; | ||
| 331 |
2/4✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
|
2 | if (NULL == gate_string_read_line(&str_line, &this->impl, &str_tail)) |
| 332 | { | ||
| 333 | ✗ | GATEXX_RAISE_ERROR(results::OutOfMemory); | |
| 334 | } | ||
| 335 | 2 | tail = String::duplicate(str_tail); | |
| 336 |
1/2✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
|
2 | gate_string_release(&str_tail); |
| 337 | |||
| 338 | 2 | String ret = String::duplicate(str_line); | |
| 339 |
1/2✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
|
2 | gate_string_release(&str_line); |
| 340 | 4 | return ret; | |
| 341 | } | ||
| 342 | 1 | String String::readLine() | |
| 343 | { | ||
| 344 | 2 | String tail; | |
| 345 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | String ret = this->readLine(tail); |
| 346 | 1 | this->swap(tail); | |
| 347 | 2 | return ret; | |
| 348 | } | ||
| 349 | 1 | String String::toLower() const | |
| 350 | { | ||
| 351 | 1 | gate_string_t dst = GATE_STRING_INIT_EMPTY; | |
| 352 |
2/4✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
|
1 | if (NULL == gate_string_to_lower(&dst, &this->impl)) |
| 353 | { | ||
| 354 | ✗ | GATEXX_RAISE_ERROR(results::OutOfMemory); | |
| 355 | } | ||
| 356 | 2 | return String::createFrom(dst); | |
| 357 | } | ||
| 358 | 1 | String String::toUpper() const | |
| 359 | { | ||
| 360 | 1 | gate_string_t dst = GATE_STRING_INIT_EMPTY; | |
| 361 |
2/4✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 1 times.
|
1 | if (NULL == gate_string_to_upper(&dst, &this->impl)) |
| 362 | { | ||
| 363 | ✗ | GATEXX_RAISE_ERROR(results::OutOfMemory); | |
| 364 | } | ||
| 365 | 2 | return String::createFrom(dst); | |
| 366 | } | ||
| 367 | |||
| 368 | |||
| 369 | |||
| 370 | 1 | String String::ltrim() const | |
| 371 | { | ||
| 372 | 1 | String ret; | |
| 373 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | gate_string_ltrim(&ret.impl, &this->impl); |
| 374 | 1 | return ret; | |
| 375 | } | ||
| 376 | 1 | String String::rtrim() const | |
| 377 | { | ||
| 378 | 1 | String ret; | |
| 379 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | gate_string_rtrim(&ret.impl, &this->impl); |
| 380 | 1 | return ret; | |
| 381 | } | ||
| 382 | 1 | String String::trim() const | |
| 383 | { | ||
| 384 | 1 | String ret; | |
| 385 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | gate_string_trim(&ret.impl, &this->impl); |
| 386 | 1 | return ret; | |
| 387 | } | ||
| 388 | |||
| 389 | 8 | String String::copy(gate_string_t const& src) | |
| 390 | { | ||
| 391 | 8 | String ret; | |
| 392 |
2/4✓ Branch 1 taken 8 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 8 times.
|
8 | if (NULL == gate_string_create_copy(&ret.impl, &src)) |
| 393 | { | ||
| 394 | ✗ | GATEXX_RAISE_ERROR(results::OutOfMemory); | |
| 395 | } | ||
| 396 | 8 | return ret; | |
| 397 | } | ||
| 398 | 11 | String String::clone(gate_string_t const& src) | |
| 399 | { | ||
| 400 | 11 | String ret; | |
| 401 |
2/4✓ Branch 1 taken 11 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 11 times.
|
11 | if (NULL == gate_string_clone(&ret.impl, &src)) |
| 402 | { | ||
| 403 | ✗ | GATEXX_RAISE_ERROR(results::OutOfMemory); | |
| 404 | } | ||
| 405 | 11 | return ret; | |
| 406 | |||
| 407 | } | ||
| 408 | 476 | String String::duplicate(gate_string_t const& src) noexcept | |
| 409 | { | ||
| 410 | 476 | String ret; | |
| 411 | 476 | gate_string_duplicate(&ret.impl, &src); | |
| 412 | 476 | return ret; | |
| 413 | } | ||
| 414 | |||
| 415 | |||
| 416 | 1 | String String::copy() const | |
| 417 | { | ||
| 418 | 1 | return String::copy(this->impl); | |
| 419 | } | ||
| 420 | 10 | String String::clone() const | |
| 421 | { | ||
| 422 | 10 | return String::clone(this->impl); | |
| 423 | } | ||
| 424 | 1 | String String::duplicate() const noexcept | |
| 425 | { | ||
| 426 | 1 | return String::duplicate(this->impl); | |
| 427 | } | ||
| 428 | |||
| 429 | |||
| 430 | |||
| 431 | 14 | size_t String::copyTo(char_8_t* buffer, size_t capacity) const | |
| 432 | { | ||
| 433 |
2/4✓ Branch 0 taken 14 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 14 times.
|
14 | if ((buffer == NULL) || (capacity == 0)) |
| 434 | { | ||
| 435 | ✗ | return 0; | |
| 436 | } | ||
| 437 | 14 | size_t sz = this->size(); | |
| 438 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 14 times.
|
14 | if (capacity <= sz) |
| 439 | { | ||
| 440 | ✗ | sz = capacity - 1; | |
| 441 | } | ||
| 442 | 14 | gate_mem_copy(buffer, this->impl.str, sz); | |
| 443 | 14 | buffer[sz] = 0; | |
| 444 | 14 | return sz; | |
| 445 | } | ||
| 446 | |||
| 447 | |||
| 448 | 1528 | int String::compare(String const& str) const noexcept | |
| 449 | { | ||
| 450 | 1528 | return gate_str_compare(this->impl.str, this->impl.length, str.impl.str, str.impl.length); | |
| 451 | } | ||
| 452 | 3 | int String::compareIC(String const& str) const noexcept | |
| 453 | { | ||
| 454 | 3 | return gate_str_compare_ic(this->impl.str, this->impl.length, str.impl.str, str.impl.length); | |
| 455 | } | ||
| 456 | 3 | bool_t String::startsWith(String const& str) const noexcept | |
| 457 | { | ||
| 458 | 3 | return gate_string_starts_with(&this->impl, &str.impl); | |
| 459 | } | ||
| 460 | 2 | bool_t String::startsWith(char const& chr) const noexcept | |
| 461 | { | ||
| 462 | 2 | return gate_string_starts_with_char(&this->impl, chr); | |
| 463 | } | ||
| 464 | 1 | bool_t String::startsWithIC(String const& str) const noexcept | |
| 465 | { | ||
| 466 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | if (this->impl.length < str.impl.length) |
| 467 | { | ||
| 468 | ✗ | return false; | |
| 469 | } | ||
| 470 | else | ||
| 471 | { | ||
| 472 | 1 | return 0 == gate_str_compare_ic(this->impl.str, str.impl.length, str.impl.str, str.impl.length); | |
| 473 | } | ||
| 474 | } | ||
| 475 | 2 | bool_t String::endsWith(String const& str) const noexcept | |
| 476 | { | ||
| 477 | 2 | return gate_string_ends_with(&this->impl, &str.impl); | |
| 478 | } | ||
| 479 | 2 | bool_t String::endsWith(char const& chr) const noexcept | |
| 480 | { | ||
| 481 | 2 | return gate_string_ends_with_char(&this->impl, chr); | |
| 482 | } | ||
| 483 | 1 | bool_t String::endsWithIC(String const& str) const noexcept | |
| 484 | { | ||
| 485 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | if (this->impl.length < str.impl.length) |
| 486 | { | ||
| 487 | ✗ | return false; | |
| 488 | } | ||
| 489 | else | ||
| 490 | { | ||
| 491 | 1 | return 0 == gate_str_compare_ic(&this->impl.str[this->impl.length - str.impl.length], str.impl.length, str.impl.str, str.impl.length); | |
| 492 | } | ||
| 493 | } | ||
| 494 | 2 | bool_t String::equals(String const& str) const noexcept | |
| 495 | { | ||
| 496 | 2 | return gate_string_equals(&this->impl, &str.impl); | |
| 497 | } | ||
| 498 | 2 | bool_t String::equalsIC(String const& str) const noexcept | |
| 499 | { | ||
| 500 | 2 | return gate_string_equals_ic(&this->impl, &str.impl); | |
| 501 | } | ||
| 502 | 3 | bool_t String::like(String const& pattern) const noexcept | |
| 503 | { | ||
| 504 | 3 | return gate_string_like(&this->impl, &pattern.impl); | |
| 505 | } | ||
| 506 | 1 | bool_t String::likeOneOf(String const& pattern, char_8_t separator) const noexcept | |
| 507 | { | ||
| 508 | 1 | return gate_string_like_one_of(&this->impl, &pattern.impl, separator); | |
| 509 | } | ||
| 510 | |||
| 511 | 97 | size_t String::length(char const* str) noexcept | |
| 512 | { | ||
| 513 | 97 | return gate_str_length(str); | |
| 514 | } | ||
| 515 | |||
| 516 | 1 | int String::compare(char_8_t const* str) const noexcept | |
| 517 | { | ||
| 518 | 1 | return this->compare(String::createStatic(str)); | |
| 519 | } | ||
| 520 | 1 | int String::compareIC(char_8_t const* str) const noexcept | |
| 521 | { | ||
| 522 | 1 | return this->compareIC(String::createStatic(str)); | |
| 523 | } | ||
| 524 | 2 | bool_t String::startsWith(char_8_t const* str) const noexcept | |
| 525 | { | ||
| 526 | 2 | return this->startsWith(String::createStatic(str)); | |
| 527 | } | ||
| 528 | 1 | bool_t String::startsWithIC(char_8_t const* str) const noexcept | |
| 529 | { | ||
| 530 | 1 | return this->startsWithIC(String::createStatic(str)); | |
| 531 | } | ||
| 532 | 1 | bool_t String::endsWith(char_8_t const* str) const noexcept | |
| 533 | { | ||
| 534 | 1 | return this->endsWith(String::createStatic(str)); | |
| 535 | } | ||
| 536 | 1 | bool_t String::endsWithIC(char_8_t const* str) const noexcept | |
| 537 | { | ||
| 538 | 1 | return this->endsWithIC(String::createStatic(str)); | |
| 539 | } | ||
| 540 | 1 | bool_t String::equals(char_8_t const* str) const noexcept | |
| 541 | { | ||
| 542 | 1 | return this->equals(String::createStatic(str)); | |
| 543 | } | ||
| 544 | 1 | bool_t String::equalsIC(char_8_t const* str) const noexcept | |
| 545 | { | ||
| 546 | 1 | return this->equalsIC(String::createStatic(str)); | |
| 547 | } | ||
| 548 | |||
| 549 | 1 | size_t String::parseNum(uint64_t& num) const noexcept | |
| 550 | { | ||
| 551 | 1 | return gate_str_parse_uint64(this->impl.str, this->impl.length, &num); | |
| 552 | } | ||
| 553 | 2 | size_t String::parseNum(int64_t& num) const noexcept | |
| 554 | { | ||
| 555 | 2 | return gate_str_parse_int64(this->impl.str, this->impl.length, &num); | |
| 556 | } | ||
| 557 | 2 | size_t String::parseNum(real64_t& num) const noexcept | |
| 558 | { | ||
| 559 | 2 | return gate_str_parse_real(this->impl.str, this->impl.length, &num); | |
| 560 | } | ||
| 561 | 1 | size_t String::parseNum(real32_t& num) const noexcept | |
| 562 | { | ||
| 563 | 1 | real64_t r64 = 0.0; | |
| 564 | 1 | size_t ret = this->parseNum(r64); | |
| 565 | 1 | num = static_cast<real32_t>(r64); | |
| 566 | 1 | return ret; | |
| 567 | } | ||
| 568 | |||
| 569 | 1 | size_t String::parseHex(uint64_t& num) const noexcept | |
| 570 | { | ||
| 571 | 1 | return gate_str_parse_hex_int(this->impl.str, this->impl.length, &num); | |
| 572 | } | ||
| 573 | |||
| 574 | 1 | String String::parseHex() const noexcept | |
| 575 | { | ||
| 576 | 1 | char const* ptr = this->c_str(); | |
| 577 | 1 | size_t len = this->length(); | |
| 578 | 2 | StringBuilder builder(len / 2 + 2); | |
| 579 |
2/2✓ Branch 0 taken 4 times.
✓ Branch 1 taken 1 times.
|
5 | while (len > 1) |
| 580 | { | ||
| 581 | 4 | gate_uint8_t b = 0; | |
| 582 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 4 times.
|
4 | if (!gate_str_parse_hex_byte(ptr, &b)) |
| 583 | { | ||
| 584 | ✗ | break; | |
| 585 | } | ||
| 586 | 4 | builder.appendChars(1, gate_char8_t(b)); | |
| 587 | 4 | ptr += 2; | |
| 588 | 4 | len -= 2; | |
| 589 | } | ||
| 590 | 1 | return builder.toString(); | |
| 591 | } | ||
| 592 | |||
| 593 | 1 | int64_t String::parseInt() const noexcept | |
| 594 | { | ||
| 595 | 1 | int64_t ret = 0; | |
| 596 | 1 | this->parseNum(ret); | |
| 597 | 1 | return ret; | |
| 598 | } | ||
| 599 | |||
| 600 | 1 | real64_t String::parseReal() const noexcept | |
| 601 | { | ||
| 602 | 1 | real64_t ret = 0.0; | |
| 603 | 1 | this->parseNum(ret); | |
| 604 | 1 | return ret; | |
| 605 | } | ||
| 606 | |||
| 607 | 2 | size_t String::parse(String const& find, size_t startAt, String* ptrHead, String* ptrTail, bool_t separatorAsTail) const | |
| 608 | { | ||
| 609 | 2 | gate_string_t head = GATE_STRING_INIT_EMPTY; | |
| 610 | 2 | gate_string_t tail = GATE_STRING_INIT_EMPTY; | |
| 611 | |||
| 612 |
1/2✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
|
2 | size_t ret = gate_string_parse(&this->impl, find.c_impl(), startAt, &head, &tail, separatorAsTail); |
| 613 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | if (ptrHead) |
| 614 | { | ||
| 615 | 2 | *ptrHead = String::duplicate(head); | |
| 616 | } | ||
| 617 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | if (ptrTail) |
| 618 | { | ||
| 619 | 2 | *ptrTail = String::duplicate(tail); | |
| 620 | } | ||
| 621 |
1/2✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
|
2 | gate_string_release(&tail); |
| 622 |
1/2✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
|
2 | gate_string_release(&head); |
| 623 | 2 | return ret; | |
| 624 | } | ||
| 625 | |||
| 626 | 1 | String String::toHex(char_8_t const* str, size_t len, bool_t upperCase) | |
| 627 | { | ||
| 628 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 | StringBuilder builder(len * 2); |
| 629 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | builder.appendHex(str, len, upperCase); |
| 630 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 | return builder.toString(); |
| 631 | } | ||
| 632 | |||
| 633 | 1 | String String::toHex() const | |
| 634 | { | ||
| 635 | 1 | return String::toHex(this->c_str(), this->length()); | |
| 636 | } | ||
| 637 | |||
| 638 | |||
| 639 | |||
| 640 | 428 | bool_t String::operator==(String const& src) const noexcept | |
| 641 | { | ||
| 642 | 428 | return this->compare(src) == 0; | |
| 643 | } | ||
| 644 | 3 | bool_t String::operator!=(String const& src) const noexcept | |
| 645 | { | ||
| 646 | 3 | return this->compare(src) != 0; | |
| 647 | } | ||
| 648 | 1093 | bool_t String::operator< (String const& src) const noexcept | |
| 649 | { | ||
| 650 | 1093 | return this->compare(src) < 0; | |
| 651 | } | ||
| 652 | 1 | bool_t String::operator> (String const& src) const noexcept | |
| 653 | { | ||
| 654 | 1 | return this->compare(src) > 0; | |
| 655 | } | ||
| 656 | 1 | bool_t String::operator<=(String const& src) const noexcept | |
| 657 | { | ||
| 658 | 1 | return this->compare(src) <= 0; | |
| 659 | } | ||
| 660 | 1 | bool_t String::operator>=(String const& src) const noexcept | |
| 661 | { | ||
| 662 | 1 | return this->compare(src) >= 0; | |
| 663 | } | ||
| 664 | ✗ | bool_t String::operator!() const noexcept | |
| 665 | { | ||
| 666 | ✗ | return this->empty(); | |
| 667 | } | ||
| 668 | ✗ | gate_string_t const& String::operator*() const noexcept | |
| 669 | { | ||
| 670 | ✗ | return this->impl; | |
| 671 | } | ||
| 672 | |||
| 673 | 2 | char_8_t const& String::operator[](size_t index) const noexcept | |
| 674 | { | ||
| 675 | static char_8_t empty_char_bytes[2] = GATE_INIT_EMPTY; | ||
| 676 | 2 | char_8_t const* ptr = gate_string_ptr(&this->impl, index); | |
| 677 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | if (ptr) |
| 678 | { | ||
| 679 | 2 | return *ptr; | |
| 680 | } | ||
| 681 | else | ||
| 682 | { | ||
| 683 | ✗ | return empty_char_bytes[0]; | |
| 684 | } | ||
| 685 | } | ||
| 686 | |||
| 687 | 2 | String operator+(String const& str1, String const& str2) | |
| 688 | { | ||
| 689 |
1/2✓ Branch 3 taken 2 times.
✗ Branch 4 not taken.
|
4 | StringBuilder builder(str1.length() + str2.length() + 2); |
| 690 |
2/4✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
|
2 | builder << str1 << str2; |
| 691 |
1/2✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
|
4 | return builder.toString(); |
| 692 | } | ||
| 693 | 19 | String operator+(String const& str1, char const* str2) | |
| 694 | { | ||
| 695 |
1/2✓ Branch 3 taken 19 times.
✗ Branch 4 not taken.
|
38 | StringBuilder builder(str1.length() + String::length(str2)); |
| 696 |
2/4✓ Branch 1 taken 19 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 19 times.
✗ Branch 5 not taken.
|
19 | builder << str1 << str2; |
| 697 |
1/2✓ Branch 1 taken 19 times.
✗ Branch 2 not taken.
|
38 | return builder.toString(); |
| 698 | } | ||
| 699 | 76 | String operator+(char const* str1, String const& str2) | |
| 700 | { | ||
| 701 |
1/2✓ Branch 3 taken 76 times.
✗ Branch 4 not taken.
|
152 | StringBuilder builder(String::length(str1) + str2.length() + 2); |
| 702 |
2/4✓ Branch 1 taken 76 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 76 times.
✗ Branch 5 not taken.
|
76 | builder << str1 << str2; |
| 703 |
1/2✓ Branch 1 taken 76 times.
✗ Branch 2 not taken.
|
152 | return builder.toString(); |
| 704 | } | ||
| 705 | |||
| 706 | |||
| 707 | |||
| 708 | 102 | StaticString::StaticString(char_8_t const* str) noexcept | |
| 709 | 102 | : String(String::createStatic(str)) | |
| 710 | { | ||
| 711 | 102 | } | |
| 712 | 3 | StaticString::StaticString(char_8_t const* str, size_t len) noexcept | |
| 713 | 3 | : String(String::createStatic(str, len)) | |
| 714 | { | ||
| 715 | 3 | } | |
| 716 | ✗ | StaticString::StaticString(StaticString const& src) noexcept | |
| 717 | ✗ | : String(src) | |
| 718 | { | ||
| 719 | ✗ | } | |
| 720 | ✗ | StaticString& StaticString::operator=(StaticString const& src) noexcept | |
| 721 | { | ||
| 722 | ✗ | String::operator=(src); | |
| 723 | ✗ | return *this; | |
| 724 | } | ||
| 725 | 260 | StaticString::~StaticString() noexcept | |
| 726 | { | ||
| 727 | 260 | } | |
| 728 | |||
| 729 | |||
| 730 | |||
| 731 | |||
| 732 | |||
| 733 | 118 | StringBuilder::StringBuilder(size_t capacity) | |
| 734 | { | ||
| 735 | 118 | gate_strbuilder_create(&this->impl, capacity); | |
| 736 | 118 | } | |
| 737 | 1 | StringBuilder::StringBuilder(char* staticBuffer, size_t capacity, size_t alreadyUsed) | |
| 738 | { | ||
| 739 | 1 | gate_strbuilder_create_static(&this->impl, staticBuffer, capacity, alreadyUsed); | |
| 740 | 1 | } | |
| 741 | |||
| 742 | 238 | StringBuilder::~StringBuilder() | |
| 743 | { | ||
| 744 | 119 | gate_strbuilder_release(&this->impl); | |
| 745 | 119 | } | |
| 746 | |||
| 747 | ✗ | gate_strbuilder_t const* StringBuilder::c_impl() const noexcept | |
| 748 | { | ||
| 749 | ✗ | return &this->impl; | |
| 750 | } | ||
| 751 | 14 | gate_strbuilder_t* StringBuilder::c_impl() noexcept | |
| 752 | { | ||
| 753 | 14 | return &this->impl; | |
| 754 | } | ||
| 755 | |||
| 756 | 1 | char_8_t const* StringBuilder::ptr(size_t pos) const noexcept | |
| 757 | { | ||
| 758 | 1 | return gate_strbuilder_ptr(&this->impl, pos); | |
| 759 | } | ||
| 760 | 6 | size_t StringBuilder::length() const noexcept | |
| 761 | { | ||
| 762 | 6 | return gate_strbuilder_length(&this->impl); | |
| 763 | } | ||
| 764 | |||
| 765 | ✗ | size_t StringBuilder::resize(size_t sz) | |
| 766 | { | ||
| 767 | ✗ | return gate_strbuilder_resize(&this->impl, sz); | |
| 768 | } | ||
| 769 | 216 | size_t StringBuilder::append(String const& text) | |
| 770 | { | ||
| 771 | 216 | return gate_strbuilder_append_text(&this->impl, text.c_str(), text.length()); | |
| 772 | } | ||
| 773 | 11 | size_t StringBuilder::append(char const* ptr, size_t len) | |
| 774 | { | ||
| 775 | 11 | return gate_strbuilder_append_text(&this->impl, ptr, len); | |
| 776 | } | ||
| 777 | 1 | size_t StringBuilder::append(char_16_t const* text16, size_t textlen) | |
| 778 | { | ||
| 779 | 1 | return gate_strbuilder_append_text16(&this->impl, text16, textlen); | |
| 780 | } | ||
| 781 | 1 | size_t StringBuilder::append(char_32_t const* text32, size_t textlen) | |
| 782 | { | ||
| 783 | 1 | return gate_strbuilder_append_text32(&this->impl, text32, textlen); | |
| 784 | } | ||
| 785 | |||
| 786 | 1 | size_t StringBuilder::append(int16_t const& num) | |
| 787 | { | ||
| 788 | 1 | return gate_strbuilder_append_int16(&this->impl, num); | |
| 789 | } | ||
| 790 | 1 | size_t StringBuilder::append(uint16_t const& num) | |
| 791 | { | ||
| 792 | 1 | return gate_strbuilder_append_uint16(&this->impl, num); | |
| 793 | } | ||
| 794 | 2 | size_t StringBuilder::append(int32_t const& num) | |
| 795 | { | ||
| 796 | 2 | return gate_strbuilder_append_int32(&this->impl, num); | |
| 797 | } | ||
| 798 | 3 | size_t StringBuilder::append(uint32_t const& num) | |
| 799 | { | ||
| 800 | 3 | return gate_strbuilder_append_uint32(&this->impl, num); | |
| 801 | } | ||
| 802 | 1 | size_t StringBuilder::append(int64_t const& num) | |
| 803 | { | ||
| 804 | 1 | return gate_strbuilder_append_int64(&this->impl, num); | |
| 805 | } | ||
| 806 | 3 | size_t StringBuilder::append(uint64_t const& num) | |
| 807 | { | ||
| 808 | 3 | return gate_strbuilder_append_uint64(&this->impl, num); | |
| 809 | } | ||
| 810 | 1 | size_t StringBuilder::append(real64_t const& num, unsigned intlen, unsigned decimallen, unsigned grouplen) | |
| 811 | { | ||
| 812 | 1 | return gate_strbuilder_append_real(&this->impl, num, intlen, decimallen, grouplen); | |
| 813 | } | ||
| 814 | 4 | size_t StringBuilder::appendHex(uint8_t const& num, bool_t upperCase) | |
| 815 | { | ||
| 816 | char buffer[8]; | ||
| 817 |
1/2✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
|
4 | size_t buffer_used = gate_str_print_hex_byte(buffer, sizeof(buffer), num, upperCase); |
| 818 |
1/2✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
|
8 | return this->append(buffer, buffer_used); |
| 819 | } | ||
| 820 | 2 | size_t StringBuilder::appendHex(uint16_t const& num, bool_t upperCase) | |
| 821 | { | ||
| 822 | char buffer[8]; | ||
| 823 |
1/2✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
|
2 | size_t buffer_used = gate_str_print_hex_num(buffer, sizeof(buffer), num, upperCase); |
| 824 |
1/2✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
|
4 | return this->append(buffer, buffer_used); |
| 825 | } | ||
| 826 | 2 | size_t StringBuilder::appendHex(uint32_t const& num, bool_t upperCase) | |
| 827 | { | ||
| 828 | char buffer[16]; | ||
| 829 |
1/2✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
|
2 | size_t buffer_used = gate_str_print_hex_num(buffer, sizeof(buffer), num, upperCase); |
| 830 |
1/2✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
|
4 | return this->append(buffer, buffer_used); |
| 831 | } | ||
| 832 | ✗ | size_t StringBuilder::appendHex(uint64_t const& num, bool_t upperCase) | |
| 833 | { | ||
| 834 | char buffer[24]; | ||
| 835 | ✗ | size_t buffer_used = gate_str_print_hex_num(buffer, sizeof(buffer), num, upperCase); | |
| 836 | ✗ | return this->append(buffer, buffer_used); | |
| 837 | } | ||
| 838 | 1 | size_t StringBuilder::appendHex(char const* txt, size_t len, bool_t upperCase) | |
| 839 | { | ||
| 840 | 1 | size_t ret = 0; | |
| 841 |
2/2✓ Branch 0 taken 4 times.
✓ Branch 1 taken 1 times.
|
5 | while (len-- > 0) |
| 842 | { | ||
| 843 |
1/2✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
|
4 | ret += this->appendHex(static_cast<uint8_t>(*txt), upperCase); |
| 844 | 4 | ++txt; | |
| 845 | } | ||
| 846 | 1 | return ret; | |
| 847 | } | ||
| 848 | |||
| 849 | |||
| 850 | 5 | size_t StringBuilder::appendChars(size_t count, gate_char8_t chr) | |
| 851 | { | ||
| 852 | 5 | return gate_strbuilder_append_chars(&this->impl, count, chr); | |
| 853 | } | ||
| 854 | |||
| 855 | 5 | size_t StringBuilder::appendNewLine() | |
| 856 | { | ||
| 857 | 5 | return this->append(strings::NewLine); | |
| 858 | } | ||
| 859 | 2 | size_t StringBuilder::discard(size_t charCount) | |
| 860 | { | ||
| 861 | 2 | return gate_strbuilder_discard(&this->impl, charCount); | |
| 862 | } | ||
| 863 | 1 | size_t StringBuilder::discardBack(size_t charCount) | |
| 864 | { | ||
| 865 | 1 | return gate_strbuilder_discard_back(&this->impl, charCount); | |
| 866 | } | ||
| 867 | 119 | String StringBuilder::toString() | |
| 868 | { | ||
| 869 | gate_string_t tmp; | ||
| 870 |
2/4✓ Branch 1 taken 119 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 119 times.
|
119 | if (NULL == gate_strbuilder_to_string(&this->impl, &tmp)) |
| 871 | { | ||
| 872 | ✗ | GATEXX_RAISE_ERROR(results::OutOfMemory); | |
| 873 | } | ||
| 874 | 119 | String ret = String::duplicate(tmp); | |
| 875 |
1/2✓ Branch 1 taken 119 times.
✗ Branch 2 not taken.
|
119 | gate_string_release(&tmp); |
| 876 | 238 | return ret; | |
| 877 | } | ||
| 878 | 4 | String StringBuilder::copyString() const | |
| 879 | { | ||
| 880 | gate_string_t tmp; | ||
| 881 |
2/4✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 4 times.
|
4 | if (NULL == gate_strbuilder_copy_to_string(&this->impl, &tmp)) |
| 882 | { | ||
| 883 | ✗ | GATEXX_RAISE_ERROR(results::OutOfMemory); | |
| 884 | } | ||
| 885 | 4 | String ret = String::duplicate(tmp); | |
| 886 |
1/2✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
|
4 | gate_string_release(&tmp); |
| 887 | 8 | return ret; | |
| 888 | } | ||
| 889 | |||
| 890 | ✗ | String StringBuilder::getView() const | |
| 891 | { | ||
| 892 | return String::createStatic( | ||
| 893 | gate_strbuilder_ptr(&this->impl, 0), | ||
| 894 | gate_strbuilder_length(&this->impl) | ||
| 895 | ✗ | ); | |
| 896 | } | ||
| 897 | |||
| 898 | |||
| 899 | 101 | StringBuilder& StringBuilder::operator<<(String const& text) { this->append(text); return *this; } | |
| 900 |
1/2✓ Branch 2 taken 102 times.
✗ Branch 3 not taken.
|
102 | StringBuilder& StringBuilder::operator<<(char const* text) { this->append(String(text)); return *this; } |
| 901 | 1 | StringBuilder& StringBuilder::operator<<(int16_t const& num) { this->append(num); return *this; } | |
| 902 | 1 | StringBuilder& StringBuilder::operator<<(uint16_t const& num) { this->append(num); return *this; } | |
| 903 | 2 | StringBuilder& StringBuilder::operator<<(int32_t const& num) { this->append(num); return *this; } | |
| 904 | 3 | StringBuilder& StringBuilder::operator<<(uint32_t const& num) { this->append(num); return *this; } | |
| 905 | 1 | StringBuilder& StringBuilder::operator<<(int64_t const& num) { this->append(num); return *this; } | |
| 906 | 3 | StringBuilder& StringBuilder::operator<<(uint64_t const& num) { this->append(num); return *this; } | |
| 907 | 1 | StringBuilder& StringBuilder::operator<<(real64_t const& num) { this->append(num); return *this; } | |
| 908 | |||
| 909 | static char_8_t const empty_dummy = '\0'; | ||
| 910 | ✗ | char_8_t const& StringBuilder::operator[](size_t index) const | |
| 911 | { | ||
| 912 | ✗ | gate_char8_t const* ptr = gate_strbuilder_ptr(&this->impl, index); | |
| 913 | ✗ | if (ptr == NULL) | |
| 914 | { | ||
| 915 | ✗ | return empty_dummy; | |
| 916 | } | ||
| 917 | else | ||
| 918 | { | ||
| 919 | ✗ | return *ptr; | |
| 920 | } | ||
| 921 | } | ||
| 922 | 1 | char_8_t& StringBuilder::operator[](size_t index) | |
| 923 | { | ||
| 924 | 1 | gate_char8_t const* ptr = gate_strbuilder_ptr(&this->impl, index); | |
| 925 | 1 | return *const_cast<gate_char8_t*>(ptr); | |
| 926 | } | ||
| 927 | |||
| 928 | |||
| 929 | 1 | CstrBuffer::CstrBuffer(char const* ptr, size_t length, bool_t copyNeeded) | |
| 930 | { | ||
| 931 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | if (NULL == gate_cstrbuffer_create(&this->impl, ptr, length, copyNeeded)) |
| 932 | { | ||
| 933 | ✗ | GATEXX_RAISE_ERROR(results::OutOfMemory); | |
| 934 | } | ||
| 935 | |||
| 936 | 1 | } | |
| 937 | 1 | CstrBuffer::CstrBuffer(String const& str, bool_t copyNeeded) | |
| 938 | { | ||
| 939 |
1/2✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
|
1 | if (NULL == gate_cstrbuffer_create_string(&this->impl, str.c_impl(), copyNeeded)) |
| 940 | { | ||
| 941 | ✗ | GATEXX_RAISE_ERROR(results::OutOfMemory); | |
| 942 | } | ||
| 943 | 1 | } | |
| 944 | 4 | CstrBuffer::~CstrBuffer() noexcept | |
| 945 | { | ||
| 946 | 2 | gate_cstrbuffer_destroy(&this->impl); | |
| 947 | 2 | } | |
| 948 | |||
| 949 | 1 | char const* CstrBuffer::get() const | |
| 950 | { | ||
| 951 | 1 | return gate_cstrbuffer_get(&this->impl); | |
| 952 | } | ||
| 953 | 1 | size_t CstrBuffer::length() const | |
| 954 | { | ||
| 955 | 1 | return gate_cstrbuffer_length(&this->impl); | |
| 956 | } | ||
| 957 | |||
| 958 | |||
| 959 | namespace strings | ||
| 960 | { | ||
| 961 | String const NewLine = String::createStatic(GATE_STR_NEWLINE, GATE_STR_NEWLINE_LENGTH); | ||
| 962 | String const Cr = String::createStatic(GATE_STR_CR, 1); | ||
| 963 | String const Lf = String::createStatic(GATE_STR_LF, 1); | ||
| 964 | String const CrLf = String::createStatic(GATE_STR_CRLF, 2); | ||
| 965 | String const Empty = String(); | ||
| 966 | |||
| 967 | } // end of namespace strings | ||
| 968 | |||
| 969 | |||
| 970 | |||
| 971 | |||
| 972 | } // end of namespace gate | ||
| 973 |