| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /* GATE PROJECT LICENSE: | ||
| 2 | +----------------------------------------------------------------------------+ | ||
| 3 | | Copyright (c) 2018-2026, 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 | #include "gate/localbuffer.hpp" | ||
| 33 | |||
| 34 | namespace gate | ||
| 35 | { | ||
| 36 | |||
| 37 | 1 | int Char::toLower(int chr) | |
| 38 | { | ||
| 39 | 1 | return gate_char_lowercase(chr); | |
| 40 | } | ||
| 41 | 1 | int Char::toUpper(int chr) | |
| 42 | { | ||
| 43 | 1 | return gate_char_uppercase(chr); | |
| 44 | } | ||
| 45 | 2 | bool_t Char::isDigit(int chr) | |
| 46 | { | ||
| 47 | 2 | return gate_char_is_digit(chr); | |
| 48 | } | ||
| 49 | 2 | bool_t Char::isWhitespace(int chr) | |
| 50 | { | ||
| 51 | 2 | return gate_char_is_whitespace(chr); | |
| 52 | } | ||
| 53 | |||
| 54 | 5 | size_t Char::readUtf8(char_8_t const* utf8text, size_t length, char_32_t& chr32) | |
| 55 | { | ||
| 56 | 5 | return gate_char_read_utf8(utf8text, length, &chr32); | |
| 57 | } | ||
| 58 | 5 | size_t Char::readUtf16(char_16_t const* utf16text, size_t length, char_32_t& chr32) | |
| 59 | { | ||
| 60 | 5 | return gate_char_read_utf16(utf16text, length, &chr32); | |
| 61 | } | ||
| 62 | 1 | size_t Char::readUtf32(char_32_t const* utf32text, size_t length, char_32_t& chr32) | |
| 63 | { | ||
| 64 | 1 | return gate_char_read_utf32(utf32text, length, &chr32); | |
| 65 | } | ||
| 66 | |||
| 67 | 5 | size_t Char::writeUtf8(char_32_t chr32, char_8_t* utf8text, size_t length) | |
| 68 | { | ||
| 69 | 5 | return gate_char_write_utf8(chr32, utf8text, length); | |
| 70 | } | ||
| 71 | 5 | size_t Char::writeUtf16(char_32_t chr32, char_16_t* utf16text, size_t length) | |
| 72 | { | ||
| 73 | 5 | return gate_char_write_utf16(chr32, utf16text, length); | |
| 74 | } | ||
| 75 | 1 | size_t Char::writeUtf32(char_32_t chr32, char_32_t* utf32text, size_t length) | |
| 76 | { | ||
| 77 | 1 | return gate_char_write_utf32(chr32, utf32text, length); | |
| 78 | } | ||
| 79 | |||
| 80 | 1 | size_t Char::utf8ToUtf16(char_8_t const* src, size_t srclen, char_16_t* dst, size_t dstlen) | |
| 81 | { | ||
| 82 | 1 | return gate_str_utf8_2_utf16(src, srclen, dst, dstlen); | |
| 83 | } | ||
| 84 | 1 | size_t Char::utf8ToUtf32(char_8_t const* src, size_t srclen, char_32_t* dst, size_t dstlen) | |
| 85 | { | ||
| 86 | 1 | return gate_str_utf8_2_utf32(src, srclen, dst, dstlen); | |
| 87 | } | ||
| 88 | 1 | size_t Char::utf16ToUtf8(char_16_t const* src, size_t srclen, char_8_t* dst, size_t dstlen) | |
| 89 | { | ||
| 90 | 1 | return gate_str_utf16_2_utf8(src, srclen, dst, dstlen); | |
| 91 | } | ||
| 92 | 1 | size_t Char::utf16ToUtf32(char_16_t const* src, size_t srclen, char_32_t* dst, size_t dstlen) | |
| 93 | { | ||
| 94 | 1 | return gate_str_utf16_2_utf32(src, srclen, dst, dstlen); | |
| 95 | } | ||
| 96 | 1 | size_t Char::utf32ToUtf8(char_32_t const* src, size_t srclen, char_8_t* dst, size_t dstlen) | |
| 97 | { | ||
| 98 | 1 | return gate_str_utf32_2_utf8(src, srclen, dst, dstlen); | |
| 99 | } | ||
| 100 | 1 | size_t Char::utf32ToUtf16(char_32_t const* src, size_t srclen, char_16_t* dst, size_t dstlen) | |
| 101 | { | ||
| 102 | 1 | return gate_str_utf32_2_utf16(src, srclen, dst, dstlen); | |
| 103 | } | ||
| 104 | |||
| 105 | |||
| 106 | size_t const String::npos = GATE_STR_NPOS; | ||
| 107 | size_t const String::NPOS = GATE_STR_NPOS; | ||
| 108 | |||
| 109 | 3492 | String::String() noexcept | |
| 110 | { | ||
| 111 | 3492 | gate_string_create_empty(&this->impl); | |
| 112 | 3492 | } | |
| 113 | 1163 | String::String(char_8_t const* str) | |
| 114 | { | ||
| 115 |
1/2✗ Branch 2 not taken.
✓ Branch 3 taken 1163 times.
|
1163 | if (NULL == gate_string_create(&this->impl, str, gate_str_length(str))) |
| 116 | { | ||
| 117 | ✗ | GATEXX_RAISE_ERROR(results::OutOfMemory); | |
| 118 | } | ||
| 119 | 1163 | } | |
| 120 | 215 | String::String(char_8_t const* str, size_t len) | |
| 121 | { | ||
| 122 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 215 times.
|
215 | if (NULL == gate_string_create(&this->impl, str, len)) |
| 123 | { | ||
| 124 | ✗ | GATEXX_RAISE_ERROR(results::OutOfMemory); | |
| 125 | } | ||
| 126 | 215 | } | |
| 127 | 922 | String::String(String const& src) noexcept | |
| 128 | { | ||
| 129 | 922 | gate_string_duplicate(&this->impl, &src.impl); | |
| 130 | 922 | } | |
| 131 | 49 | String::String(gate_string_t const& src) | |
| 132 | { | ||
| 133 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 49 times.
|
49 | if (NULL == gate_string_clone(&this->impl, &src)) |
| 134 | { | ||
| 135 | ✗ | GATEXX_RAISE_ERROR(results::OutOfMemory); | |
| 136 | } | ||
| 137 | 49 | } | |
| 138 | 1 | String::String(StringBuilder& strbuilder) | |
| 139 | { | ||
| 140 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | gate_string_create_empty(&this->impl); |
| 141 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 | String tmp = strbuilder.toString(); |
| 142 | 1 | this->swap(tmp); | |
| 143 | 1 | } | |
| 144 | |||
| 145 | |||
| 146 | |||
| 147 | 17 | String& String::operator=(String const& src) noexcept | |
| 148 | { | ||
| 149 |
1/2✓ Branch 0 taken 17 times.
✗ Branch 1 not taken.
|
17 | if (this != &src) |
| 150 | { | ||
| 151 | 34 | String that(src); | |
| 152 | 17 | this->swap(that); | |
| 153 | } | ||
| 154 | 17 | return *this; | |
| 155 | } | ||
| 156 | |||
| 157 | 11678 | String::~String() noexcept | |
| 158 | { | ||
| 159 | 5839 | gate_string_release(&this->impl); | |
| 160 | 5839 | } | |
| 161 | |||
| 162 | #if defined(GATE_COMPILER_SUPPORTS_CPP_MOVEREFS) | ||
| 163 | 1 | String::String(String&& src) noexcept | |
| 164 | { | ||
| 165 | 1 | gate_string_create_empty(&this->impl); | |
| 166 | 1 | gate::swapRefs(this->impl, src.impl); | |
| 167 | 1 | } | |
| 168 | |||
| 169 | 474 | String& String::operator=(String&& src) noexcept | |
| 170 | { | ||
| 171 | 474 | gate::swapRefs(this->impl, src.impl); | |
| 172 | 474 | return *this; | |
| 173 | } | ||
| 174 | #endif | ||
| 175 | |||
| 176 | 572 | String String::createStatic(char_8_t const* str) noexcept | |
| 177 | { | ||
| 178 | 572 | String tmp; | |
| 179 | 572 | gate_string_create_static(&tmp.impl, str); | |
| 180 | 572 | return tmp; | |
| 181 | } | ||
| 182 | 317 | String String::createStatic(char_8_t const* str, size_t len) noexcept | |
| 183 | { | ||
| 184 | 317 | String tmp; | |
| 185 | 317 | gate_string_create_static_len(&tmp.impl, str, len); | |
| 186 | 317 | return tmp; | |
| 187 | } | ||
| 188 | 453 | String String::createFrom(gate_string_t& str) noexcept | |
| 189 | { | ||
| 190 | 453 | String ret; | |
| 191 | 453 | ret.impl = str; | |
| 192 | 453 | gate_string_create_empty(&str); | |
| 193 | 453 | return ret; | |
| 194 | } | ||
| 195 | 1 | String String::createFrom(char_16_t const* utf16, size_t len) | |
| 196 | { | ||
| 197 | 1 | String ret; | |
| 198 |
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_create_utf16(&ret.impl, utf16, len)) |
| 199 | { | ||
| 200 | ✗ | GATEXX_RAISE_ERROR(results::OutOfMemory); | |
| 201 | } | ||
| 202 | 1 | return ret; | |
| 203 | } | ||
| 204 | 1 | String String::createFrom(char_32_t const* utf32, size_t len) | |
| 205 | { | ||
| 206 | 1 | String ret; | |
| 207 |
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_create_utf32(&ret.impl, utf32, len)) |
| 208 | { | ||
| 209 | ✗ | GATEXX_RAISE_ERROR(results::OutOfMemory); | |
| 210 | } | ||
| 211 | 1 | return ret; | |
| 212 | } | ||
| 213 | |||
| 214 | 1 | String String::createFilled(size_t count, char_8_t content) | |
| 215 | { | ||
| 216 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 | StringBuilder builder(count); |
| 217 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | builder.appendChars(count, content); |
| 218 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 | return builder.toString(); |
| 219 | } | ||
| 220 | |||
| 221 | |||
| 222 | 1 | String String::createIntNum(int64_t num) | |
| 223 | { | ||
| 224 | char buffer[64]; | ||
| 225 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | size_t len = gate_str_print_int64(buffer, sizeof(buffer), num); |
| 226 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 | return String(buffer, len); |
| 227 | } | ||
| 228 | 1 | String String::createRealNum(real64_t num, int32_t decimalCount) | |
| 229 | { | ||
| 230 | char buffer[64]; | ||
| 231 |
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); |
| 232 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 | return String(buffer, len); |
| 233 | } | ||
| 234 | |||
| 235 | 73 | void String::assign(gate_string_t& dst, gate_string_t const& src) | |
| 236 | { | ||
| 237 | 73 | gate_string_t tmp = GATE_STRING_INIT_EMPTY; | |
| 238 |
2/4✓ Branch 1 taken 73 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 73 times.
|
73 | if (NULL == gate_string_clone(&tmp, &src)) |
| 239 | { | ||
| 240 | ✗ | GATEXX_RAISE_ERROR(results::OutOfMemory); | |
| 241 | } | ||
| 242 |
1/2✓ Branch 1 taken 73 times.
✗ Branch 2 not taken.
|
73 | gate_string_release(&dst); |
| 243 | 73 | dst = tmp; | |
| 244 | 73 | } | |
| 245 | |||
| 246 | 21 | void String::assign(gate_string_t& dst, String const& src) | |
| 247 | { | ||
| 248 | 21 | String::assign(dst, *src.c_impl()); | |
| 249 | 21 | } | |
| 250 | |||
| 251 | |||
| 252 | |||
| 253 | 25 | void String::swap(String& that) noexcept | |
| 254 | { | ||
| 255 | 25 | gate::swapRefsNoExcept(this->impl, that.impl); | |
| 256 | 25 | } | |
| 257 | 5 | void String::swap(gate_string_t& that) noexcept | |
| 258 | { | ||
| 259 | 5 | gate::swapRefsNoExcept(this->impl, that); | |
| 260 | 5 | } | |
| 261 | 1 | void String::swap(gate_string_t& a, gate_string_t& b) noexcept | |
| 262 | { | ||
| 263 | 1 | gate::swapRefsNoExcept(a, b); | |
| 264 | 1 | } | |
| 265 | |||
| 266 | |||
| 267 | |||
| 268 | 1292 | size_t String::size() const noexcept | |
| 269 | { | ||
| 270 | 1292 | return gate_string_length(&this->impl); | |
| 271 | } | ||
| 272 | 3126 | size_t String::length() const noexcept | |
| 273 | { | ||
| 274 | 3126 | return gate_string_length(&this->impl); | |
| 275 | } | ||
| 276 | 257 | bool String::empty() const noexcept | |
| 277 | { | ||
| 278 | 257 | return this->size() == 0; | |
| 279 | } | ||
| 280 | 1846 | char_8_t const* String::c_str() const noexcept | |
| 281 | { | ||
| 282 | 1846 | return gate_string_ptr(&this->impl, 0); | |
| 283 | } | ||
| 284 | |||
| 285 | 1 | char_8_t const& String::at(size_t index) const noexcept | |
| 286 | { | ||
| 287 | 1 | return *gate_string_ptr(&this->impl, index); | |
| 288 | } | ||
| 289 | |||
| 290 | 1138 | gate_string_t const* String::c_impl() const noexcept | |
| 291 | { | ||
| 292 | 1138 | return &this->impl; | |
| 293 | } | ||
| 294 | |||
| 295 | 1 | String::const_iterator String::cbegin() const noexcept | |
| 296 | { | ||
| 297 | 1 | return gate_string_ptr(&this->impl, 0); | |
| 298 | } | ||
| 299 | 4 | String::const_iterator String::cend() const noexcept | |
| 300 | { | ||
| 301 | 4 | return gate_string_ptr(&this->impl, 0) + gate_string_length(&this->impl); | |
| 302 | } | ||
| 303 | |||
| 304 | 1 | String::const_iterator String::begin() const noexcept | |
| 305 | { | ||
| 306 | 1 | return this->cbegin(); | |
| 307 | } | ||
| 308 | 4 | String::const_iterator String::end() const noexcept | |
| 309 | { | ||
| 310 | 4 | return this->cend(); | |
| 311 | } | ||
| 312 | |||
| 313 | 4 | size_t String::positionOf(String const& text, size_t startAt) const noexcept | |
| 314 | { | ||
| 315 | 4 | return gate_string_pos(&this->impl, text.c_impl(), startAt); | |
| 316 | } | ||
| 317 | 4 | size_t String::positionOf(char const& chr, size_t startAt) const noexcept | |
| 318 | { | ||
| 319 | 4 | return gate_string_char_pos(&this->impl, chr, startAt); | |
| 320 | } | ||
| 321 | |||
| 322 | 2 | size_t String::positionOfLast(String const& text) const noexcept | |
| 323 | { | ||
| 324 | 2 | size_t pos = gate_string_pos_last(&this->impl, text.c_impl()); | |
| 325 | 2 | return pos; | |
| 326 | } | ||
| 327 | 1 | size_t String::positionOfLast(char const& chr) const noexcept | |
| 328 | { | ||
| 329 | 1 | return gate_string_char_pos_last(&this->impl, chr); | |
| 330 | } | ||
| 331 | |||
| 332 | |||
| 333 | 1 | size_t String::findFirstOf(String const& text, size_t startAt) const noexcept | |
| 334 | { | ||
| 335 | 1 | return gate_string_find_first_of(&this->impl, text.c_impl(), startAt); | |
| 336 | } | ||
| 337 | 1 | size_t String::findFirstNotOf(String const& text, size_t startAt) const noexcept | |
| 338 | { | ||
| 339 | 1 | return gate_string_find_first_not_of(&this->impl, text.c_impl(), startAt); | |
| 340 | } | ||
| 341 | 1 | size_t String::findLastOf(String const& text) const noexcept | |
| 342 | { | ||
| 343 | 1 | return gate_string_find_last_of(&this->impl, text.c_impl()); | |
| 344 | } | ||
| 345 | 1 | size_t String::findLastNotOf(String const& text) const noexcept | |
| 346 | { | ||
| 347 | 1 | return gate_string_find_last_not_of(&this->impl, text.c_impl()); | |
| 348 | } | ||
| 349 | |||
| 350 | 5 | String String::substr(size_t offset, size_t len) const | |
| 351 | { | ||
| 352 | 5 | String ret; | |
| 353 |
1/2✓ Branch 1 taken 5 times.
✗ Branch 2 not taken.
|
5 | gate_string_substr(&ret.impl, &this->impl, offset, len); |
| 354 | 5 | return ret; | |
| 355 | } | ||
| 356 | 2 | String String::left(size_t len) const | |
| 357 | { | ||
| 358 | 2 | return this->substr(0, len); | |
| 359 | } | ||
| 360 | 2 | String String::right(size_t len) const | |
| 361 | { | ||
| 362 | 2 | size_t sz = this->size(); | |
| 363 |
2/2✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
|
2 | if (len >= sz) |
| 364 | { | ||
| 365 | 1 | return *this; | |
| 366 | } | ||
| 367 | else | ||
| 368 | { | ||
| 369 | 1 | return this->substr(sz - len, len); | |
| 370 | } | ||
| 371 | } | ||
| 372 | 2 | String String::readLine(String& tail) const | |
| 373 | { | ||
| 374 | gate_string_t str_line; | ||
| 375 | gate_string_t str_tail; | ||
| 376 |
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)) |
| 377 | { | ||
| 378 | ✗ | GATEXX_RAISE_ERROR(results::OutOfMemory); | |
| 379 | } | ||
| 380 | 2 | tail = String::duplicate(str_tail); | |
| 381 |
1/2✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
|
2 | gate_string_release(&str_tail); |
| 382 | |||
| 383 | 2 | String ret = String::duplicate(str_line); | |
| 384 |
1/2✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
|
2 | gate_string_release(&str_line); |
| 385 | 4 | return ret; | |
| 386 | } | ||
| 387 | 1 | String String::readLine() | |
| 388 | { | ||
| 389 | 2 | String tail; | |
| 390 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | String ret = this->readLine(tail); |
| 391 | 1 | this->swap(tail); | |
| 392 | 2 | return ret; | |
| 393 | } | ||
| 394 | ✗ | bool_t String::readToken(String& token, String& tail) const | |
| 395 | { | ||
| 396 | gate_string_t strToken; | ||
| 397 | gate_string_t strTail; | ||
| 398 | ✗ | if (NULL == gate_string_read_token(&strToken, &this->impl, &strTail)) | |
| 399 | { | ||
| 400 | ✗ | return false; | |
| 401 | } | ||
| 402 | else | ||
| 403 | { | ||
| 404 | ✗ | token = String::createFrom(strToken); | |
| 405 | ✗ | tail = String::createFrom(strTail); | |
| 406 | ✗ | return true; | |
| 407 | } | ||
| 408 | } | ||
| 409 | |||
| 410 | ✗ | String String::readToken() | |
| 411 | { | ||
| 412 | gate_string_t strToken; | ||
| 413 | gate_string_t strTail; | ||
| 414 | ✗ | if (NULL == gate_string_read_token(&strToken, &this->impl, &strTail)) | |
| 415 | { | ||
| 416 | ✗ | GATEXX_RAISE_EXCEPTION(results::OutOfMemory, NULL, 0); | |
| 417 | } | ||
| 418 | ✗ | gate_string_release(&this->impl); | |
| 419 | ✗ | gate_mem_copy(&this->impl, &strTail, sizeof(gate_string_t)); | |
| 420 | ✗ | return String::createFrom(strToken); | |
| 421 | } | ||
| 422 | |||
| 423 | |||
| 424 | 1 | String String::toLower() const | |
| 425 | { | ||
| 426 | 1 | gate_string_t dst = GATE_STRING_INIT_EMPTY; | |
| 427 |
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)) |
| 428 | { | ||
| 429 | ✗ | GATEXX_RAISE_ERROR(results::OutOfMemory); | |
| 430 | } | ||
| 431 | 2 | return String::createFrom(dst); | |
| 432 | } | ||
| 433 | 1 | String String::toUpper() const | |
| 434 | { | ||
| 435 | 1 | gate_string_t dst = GATE_STRING_INIT_EMPTY; | |
| 436 |
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)) |
| 437 | { | ||
| 438 | ✗ | GATEXX_RAISE_ERROR(results::OutOfMemory); | |
| 439 | } | ||
| 440 | 2 | return String::createFrom(dst); | |
| 441 | } | ||
| 442 | |||
| 443 | |||
| 444 | |||
| 445 | 1 | String String::ltrim() const | |
| 446 | { | ||
| 447 | 1 | String ret; | |
| 448 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | gate_string_ltrim(&ret.impl, &this->impl); |
| 449 | 1 | return ret; | |
| 450 | } | ||
| 451 | 1 | String String::rtrim() const | |
| 452 | { | ||
| 453 | 1 | String ret; | |
| 454 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | gate_string_rtrim(&ret.impl, &this->impl); |
| 455 | 1 | return ret; | |
| 456 | } | ||
| 457 | 1 | String String::trim() const | |
| 458 | { | ||
| 459 | 1 | String ret; | |
| 460 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | gate_string_trim(&ret.impl, &this->impl); |
| 461 | 1 | return ret; | |
| 462 | } | ||
| 463 | |||
| 464 | 9 | String String::copy(gate_string_t const& src) | |
| 465 | { | ||
| 466 | 9 | String ret; | |
| 467 |
2/4✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 9 times.
|
9 | if (NULL == gate_string_create_copy(&ret.impl, &src)) |
| 468 | { | ||
| 469 | ✗ | GATEXX_RAISE_ERROR(results::OutOfMemory); | |
| 470 | } | ||
| 471 | 9 | return ret; | |
| 472 | } | ||
| 473 | 10 | String String::clone(gate_string_t const& src) | |
| 474 | { | ||
| 475 | 10 | String ret; | |
| 476 |
2/4✓ Branch 1 taken 10 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 10 times.
|
10 | if (NULL == gate_string_clone(&ret.impl, &src)) |
| 477 | { | ||
| 478 | ✗ | GATEXX_RAISE_ERROR(results::OutOfMemory); | |
| 479 | } | ||
| 480 | 10 | return ret; | |
| 481 | |||
| 482 | } | ||
| 483 | 525 | String String::duplicate(gate_string_t const& src) noexcept | |
| 484 | { | ||
| 485 | 525 | String ret; | |
| 486 | 525 | gate_string_duplicate(&ret.impl, &src); | |
| 487 | 525 | return ret; | |
| 488 | } | ||
| 489 | |||
| 490 | |||
| 491 | 2 | String String::copy() const | |
| 492 | { | ||
| 493 | 2 | return String::copy(this->impl); | |
| 494 | } | ||
| 495 | 9 | String String::clone() const | |
| 496 | { | ||
| 497 | 9 | return String::clone(this->impl); | |
| 498 | } | ||
| 499 | 1 | String String::duplicate() const noexcept | |
| 500 | { | ||
| 501 | 1 | return String::duplicate(this->impl); | |
| 502 | } | ||
| 503 | |||
| 504 | |||
| 505 | |||
| 506 | 17 | size_t String::copyTo(char_8_t* buffer, size_t capacity) const | |
| 507 | { | ||
| 508 |
2/4✓ Branch 0 taken 17 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 17 times.
|
17 | if ((buffer == NULL) || (capacity == 0)) |
| 509 | { | ||
| 510 | ✗ | return 0; | |
| 511 | } | ||
| 512 | 17 | size_t sz = this->size(); | |
| 513 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 17 times.
|
17 | if (capacity <= sz) |
| 514 | { | ||
| 515 | ✗ | sz = capacity - 1; | |
| 516 | } | ||
| 517 | |||
| 518 |
2/2✓ Branch 0 taken 14 times.
✓ Branch 1 taken 3 times.
|
17 | if (sz > 0) |
| 519 | { | ||
| 520 | 14 | gate_mem_copy(buffer, this->impl.str, sz); | |
| 521 | } | ||
| 522 | 17 | buffer[sz] = 0; | |
| 523 | 17 | return sz; | |
| 524 | } | ||
| 525 | |||
| 526 | |||
| 527 | 1710 | int String::compare(String const& str) const noexcept | |
| 528 | { | ||
| 529 | 1710 | return gate_str_compare(this->impl.str, this->impl.length, str.impl.str, str.impl.length); | |
| 530 | } | ||
| 531 | 3 | int String::compareIC(String const& str) const noexcept | |
| 532 | { | ||
| 533 | 3 | return gate_str_compare_ic(this->impl.str, this->impl.length, str.impl.str, str.impl.length); | |
| 534 | } | ||
| 535 | 1 | bool_t String::startsWith(String const& str) const noexcept | |
| 536 | { | ||
| 537 | 1 | return gate_string_starts_with(&this->impl, &str.impl); | |
| 538 | } | ||
| 539 | 2 | bool_t String::startsWith(char const& chr) const noexcept | |
| 540 | { | ||
| 541 | 2 | return gate_string_starts_with_char(&this->impl, chr); | |
| 542 | } | ||
| 543 | ✗ | bool_t String::startsWithIC(String const& str) const noexcept | |
| 544 | { | ||
| 545 | ✗ | return gate_string_starts_with_ic(&this->impl, str.c_impl()); | |
| 546 | } | ||
| 547 | 1 | bool_t String::endsWith(String const& str) const noexcept | |
| 548 | { | ||
| 549 | 1 | return gate_string_ends_with(&this->impl, &str.impl); | |
| 550 | } | ||
| 551 | 2 | bool_t String::endsWith(char const& chr) const noexcept | |
| 552 | { | ||
| 553 | 2 | return gate_string_ends_with_char(&this->impl, chr); | |
| 554 | } | ||
| 555 | ✗ | bool_t String::endsWithIC(String const& str) const noexcept | |
| 556 | { | ||
| 557 | ✗ | return gate_string_ends_with_ic(&this->impl, str.c_impl()); | |
| 558 | } | ||
| 559 | 2 | bool_t String::equals(String const& str) const noexcept | |
| 560 | { | ||
| 561 | 2 | return gate_string_equals(&this->impl, &str.impl); | |
| 562 | } | ||
| 563 | 2 | bool_t String::equalsIC(String const& str) const noexcept | |
| 564 | { | ||
| 565 | 2 | return gate_string_equals_ic(&this->impl, &str.impl); | |
| 566 | } | ||
| 567 | 3 | bool_t String::like(String const& pattern) const noexcept | |
| 568 | { | ||
| 569 | 3 | return gate_string_like(&this->impl, &pattern.impl); | |
| 570 | } | ||
| 571 | 1 | bool_t String::likeOneOf(String const& pattern, char_8_t separator) const noexcept | |
| 572 | { | ||
| 573 | 1 | return gate_string_like_one_of(&this->impl, &pattern.impl, separator); | |
| 574 | } | ||
| 575 | |||
| 576 | 119 | size_t String::length(char const* str) noexcept | |
| 577 | { | ||
| 578 | 119 | return gate_str_length(str); | |
| 579 | } | ||
| 580 | |||
| 581 | 1 | int String::compare(char_8_t const* str) const noexcept | |
| 582 | { | ||
| 583 | 1 | return this->compare(String::createStatic(str)); | |
| 584 | } | ||
| 585 | 1 | int String::compareIC(char_8_t const* str) const noexcept | |
| 586 | { | ||
| 587 | 1 | return this->compareIC(String::createStatic(str)); | |
| 588 | } | ||
| 589 | 2 | bool_t String::startsWith(char_8_t const* str) const noexcept | |
| 590 | { | ||
| 591 | 2 | return gate_string_starts_with_str(&this->impl, str); | |
| 592 | } | ||
| 593 | 1 | bool_t String::startsWithIC(char_8_t const* str) const noexcept | |
| 594 | { | ||
| 595 | 1 | return gate_string_starts_with_str_ic(&this->impl, str); | |
| 596 | } | ||
| 597 | 1 | bool_t String::endsWith(char_8_t const* str) const noexcept | |
| 598 | { | ||
| 599 | 1 | return gate_string_ends_with_str(&this->impl, str); | |
| 600 | } | ||
| 601 | 1 | bool_t String::endsWithIC(char_8_t const* str) const noexcept | |
| 602 | { | ||
| 603 | 1 | return gate_string_ends_with_str_ic(&this->impl, str); | |
| 604 | } | ||
| 605 | 1 | bool_t String::equals(char_8_t const* str) const noexcept | |
| 606 | { | ||
| 607 | 1 | return this->equals(String::createStatic(str)); | |
| 608 | } | ||
| 609 | 1 | bool_t String::equalsIC(char_8_t const* str) const noexcept | |
| 610 | { | ||
| 611 | 1 | return this->equalsIC(String::createStatic(str)); | |
| 612 | } | ||
| 613 | |||
| 614 | 1 | size_t String::parseNum(uint64_t& num) const noexcept | |
| 615 | { | ||
| 616 | 1 | return gate_string_parse_uint(&this->impl, &num); | |
| 617 | } | ||
| 618 | 3 | size_t String::parseNum(int64_t& num) const noexcept | |
| 619 | { | ||
| 620 | 3 | return gate_string_parse_int(&this->impl, &num); | |
| 621 | } | ||
| 622 | 3 | size_t String::parseNum(real64_t& num) const noexcept | |
| 623 | { | ||
| 624 | 3 | return gate_string_parse_real(&this->impl, &num); | |
| 625 | } | ||
| 626 | 1 | size_t String::parseNum(real32_t& num) const noexcept | |
| 627 | { | ||
| 628 | 1 | real64_t r64 = 0.0; | |
| 629 | 1 | size_t ret = this->parseNum(r64); | |
| 630 | 1 | num = static_cast<real32_t>(r64); | |
| 631 | 1 | return ret; | |
| 632 | } | ||
| 633 | |||
| 634 | 1 | size_t String::parseHex(uint64_t& num) const noexcept | |
| 635 | { | ||
| 636 | 1 | return gate_string_parse_hex(&this->impl, &num); | |
| 637 | } | ||
| 638 | |||
| 639 | 1 | String String::parseHex() const noexcept | |
| 640 | { | ||
| 641 | 1 | char const* const ptr = this->c_str(); | |
| 642 | 1 | size_t const len = this->length(); | |
| 643 | |||
| 644 | gate_size_t bufferused; | ||
| 645 | gate_string_t str; | ||
| 646 | bool_t str_created; | ||
| 647 | |||
| 648 | 2 | LocalBuffer<char> buffer(len / 2); | |
| 649 | 1 | char* const ptr_buffer = buffer.get(); | |
| 650 | 1 | size_t const bufferlen = buffer.length(); | |
| 651 | |||
| 652 | |||
| 653 | 1 | bufferused = gate_str_parse_hex_buffer(ptr, len, ptr_buffer, bufferlen); | |
| 654 | 1 | str_created = (NULL != gate_string_create(&str, ptr_buffer, bufferused)); | |
| 655 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | if (!str_created) |
| 656 | { | ||
| 657 | ✗ | GATEXX_RAISE_ERROR(results::OutOfMemory); | |
| 658 | } | ||
| 659 | 1 | return String::createFrom(str); | |
| 660 | } | ||
| 661 | |||
| 662 | ✗ | uint8_t String::parseOctByte() const noexcept | |
| 663 | { | ||
| 664 | ✗ | uint8_t ret = 0; | |
| 665 | ✗ | size_t const len = this->length(); | |
| 666 | ✗ | if (len >= 3) | |
| 667 | { | ||
| 668 | ✗ | gate_str_parse_oct_byte(this->c_str(), &ret); | |
| 669 | } | ||
| 670 | ✗ | return ret; | |
| 671 | } | ||
| 672 | |||
| 673 | 1 | int64_t String::parseInt() const noexcept | |
| 674 | { | ||
| 675 | 1 | int64_t ret = 0; | |
| 676 | 1 | this->parseNum(ret); | |
| 677 | 1 | return ret; | |
| 678 | } | ||
| 679 | |||
| 680 | 1 | real64_t String::parseReal() const noexcept | |
| 681 | { | ||
| 682 | 1 | real64_t ret = 0.0; | |
| 683 | 1 | this->parseNum(ret); | |
| 684 | 1 | return ret; | |
| 685 | } | ||
| 686 | |||
| 687 | 9 | bool_t String::parseBool() const noexcept | |
| 688 | { | ||
| 689 | 9 | gate_bool_t ret = false; | |
| 690 | 9 | gate_str_parse_bool(this->c_str(), this->length(), &ret); | |
| 691 | 9 | return ret; | |
| 692 | } | ||
| 693 | |||
| 694 | 3 | size_t String::parseLine(String& line) const noexcept | |
| 695 | { | ||
| 696 | 3 | size_t length = this->positionOf('\n'); | |
| 697 |
2/2✓ Branch 0 taken 2 times.
✓ Branch 1 taken 1 times.
|
3 | if (length == String::npos) |
| 698 | { | ||
| 699 | 2 | length = this->length(); | |
| 700 | } | ||
| 701 | else | ||
| 702 | { | ||
| 703 | 1 | ++length; | |
| 704 | } | ||
| 705 | 3 | gate_size_t bufferlen = length + 2; | |
| 706 | 3 | char* buffer = static_cast<char*>(Mem::alloc(bufferlen)); | |
| 707 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
|
3 | if (buffer == NULL) |
| 708 | { | ||
| 709 | ✗ | return 0; | |
| 710 | } | ||
| 711 | 3 | gate_str_parse_line(this->c_str(), length, buffer, &bufferlen); | |
| 712 |
1/2✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
|
3 | GATEXX_TRY_IGNORE(line = String(buffer, bufferlen)); |
| 713 | 3 | Mem::dealloc(buffer); | |
| 714 | 3 | return length; | |
| 715 | } | ||
| 716 | |||
| 717 | 30 | size_t String::printValue(char* buffer, size_t bufferlen, int printType, void const* ptrValue) | |
| 718 | { | ||
| 719 | gate_print_value_t pv; | ||
| 720 | 30 | pv.value_type = printType; | |
| 721 | 30 | pv.value_ptr = ptrValue; | |
| 722 |
1/2✓ Branch 1 taken 30 times.
✗ Branch 2 not taken.
|
60 | return gate_str_print_values(buffer, bufferlen, &pv, 1); |
| 723 | } | ||
| 724 | |||
| 725 | |||
| 726 | |||
| 727 | 2 | size_t String::parse(String const& find, size_t startAt, String* ptrHead, String* ptrTail, bool_t separatorAsTail) const | |
| 728 | { | ||
| 729 | 2 | gate_string_t head = GATE_STRING_INIT_EMPTY; | |
| 730 | 2 | gate_string_t tail = GATE_STRING_INIT_EMPTY; | |
| 731 | |||
| 732 |
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); |
| 733 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | if (ptrHead) |
| 734 | { | ||
| 735 | 2 | *ptrHead = String::duplicate(head); | |
| 736 | } | ||
| 737 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | if (ptrTail) |
| 738 | { | ||
| 739 | 2 | *ptrTail = String::duplicate(tail); | |
| 740 | } | ||
| 741 |
1/2✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
|
2 | gate_string_release(&tail); |
| 742 |
1/2✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
|
2 | gate_string_release(&head); |
| 743 | 2 | return ret; | |
| 744 | } | ||
| 745 | |||
| 746 | 1 | String String::toHex(char_8_t const* str, size_t len, bool_t upperCase) | |
| 747 | { | ||
| 748 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 | StringBuilder builder(len * 2); |
| 749 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | builder.appendHex(str, len, upperCase); |
| 750 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 | return builder.toString(); |
| 751 | } | ||
| 752 | |||
| 753 | 1 | String String::toHex() const | |
| 754 | { | ||
| 755 | 1 | return String::toHex(this->c_str(), this->length()); | |
| 756 | } | ||
| 757 | |||
| 758 | |||
| 759 | |||
| 760 | 480 | bool_t String::operator==(String const& src) const noexcept | |
| 761 | { | ||
| 762 | 480 | return this->compare(src) == 0; | |
| 763 | } | ||
| 764 | 3 | bool_t String::operator!=(String const& src) const noexcept | |
| 765 | { | ||
| 766 | 3 | return this->compare(src) != 0; | |
| 767 | } | ||
| 768 | 1223 | bool_t String::operator< (String const& src) const noexcept | |
| 769 | { | ||
| 770 | 1223 | return this->compare(src) < 0; | |
| 771 | } | ||
| 772 | 1 | bool_t String::operator> (String const& src) const noexcept | |
| 773 | { | ||
| 774 | 1 | return this->compare(src) > 0; | |
| 775 | } | ||
| 776 | 1 | bool_t String::operator<=(String const& src) const noexcept | |
| 777 | { | ||
| 778 | 1 | return this->compare(src) <= 0; | |
| 779 | } | ||
| 780 | 1 | bool_t String::operator>=(String const& src) const noexcept | |
| 781 | { | ||
| 782 | 1 | return this->compare(src) >= 0; | |
| 783 | } | ||
| 784 | 2 | bool_t String::operator!() const noexcept | |
| 785 | { | ||
| 786 | 2 | return this->empty(); | |
| 787 | } | ||
| 788 | 1 | gate_string_t const& String::operator*() const noexcept | |
| 789 | { | ||
| 790 | 1 | return this->impl; | |
| 791 | } | ||
| 792 | |||
| 793 | 2 | char_8_t const& String::operator[](size_t index) const noexcept | |
| 794 | { | ||
| 795 | static char_8_t empty_char_bytes[2] = GATE_INIT_EMPTY; | ||
| 796 | 2 | char_8_t const* ptr = gate_string_ptr(&this->impl, index); | |
| 797 |
1/2✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
|
2 | if (ptr) |
| 798 | { | ||
| 799 | 2 | return *ptr; | |
| 800 | } | ||
| 801 | else | ||
| 802 | { | ||
| 803 | ✗ | return empty_char_bytes[0]; | |
| 804 | } | ||
| 805 | } | ||
| 806 | |||
| 807 | 2 | String operator+(String const& str1, String const& str2) | |
| 808 | { | ||
| 809 |
1/2✓ Branch 3 taken 2 times.
✗ Branch 4 not taken.
|
4 | StringBuilder builder(str1.length() + str2.length() + 2); |
| 810 |
2/4✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
|
2 | builder << str1 << str2; |
| 811 |
1/2✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
|
4 | return builder.toString(); |
| 812 | } | ||
| 813 | 20 | String operator+(String const& str1, char const* str2) | |
| 814 | { | ||
| 815 |
1/2✓ Branch 3 taken 20 times.
✗ Branch 4 not taken.
|
40 | StringBuilder builder(str1.length() + String::length(str2)); |
| 816 |
2/4✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 20 times.
✗ Branch 5 not taken.
|
20 | builder << str1 << str2; |
| 817 |
1/2✓ Branch 1 taken 20 times.
✗ Branch 2 not taken.
|
40 | return builder.toString(); |
| 818 | } | ||
| 819 | 76 | String operator+(char const* str1, String const& str2) | |
| 820 | { | ||
| 821 |
1/2✓ Branch 3 taken 76 times.
✗ Branch 4 not taken.
|
152 | StringBuilder builder(String::length(str1) + str2.length() + 2); |
| 822 |
2/4✓ Branch 1 taken 76 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 76 times.
✗ Branch 5 not taken.
|
76 | builder << str1 << str2; |
| 823 |
1/2✓ Branch 1 taken 76 times.
✗ Branch 2 not taken.
|
152 | return builder.toString(); |
| 824 | } | ||
| 825 | |||
| 826 | |||
| 827 | |||
| 828 | 122 | StaticString::StaticString(char_8_t const* str) noexcept | |
| 829 | 122 | : String(String::createStatic(str)) | |
| 830 | { | ||
| 831 | 122 | } | |
| 832 | 4 | StaticString::StaticString(char_8_t const* str, size_t len) noexcept | |
| 833 | 4 | : String(String::createStatic(str, len)) | |
| 834 | { | ||
| 835 | 4 | } | |
| 836 | 1 | StaticString::StaticString(StaticString const& src) noexcept | |
| 837 | 1 | : String(src) | |
| 838 | { | ||
| 839 | 1 | } | |
| 840 | 1 | StaticString& StaticString::operator=(StaticString const& src) noexcept | |
| 841 | { | ||
| 842 | 1 | String::operator=(src); | |
| 843 | 1 | return *this; | |
| 844 | } | ||
| 845 | 336 | StaticString::~StaticString() noexcept | |
| 846 | { | ||
| 847 | 336 | } | |
| 848 | |||
| 849 | |||
| 850 | |||
| 851 | |||
| 852 | |||
| 853 | 126 | StringBuilder::StringBuilder(size_t capacity) | |
| 854 | { | ||
| 855 | 126 | gate_strbuilder_create(&this->impl, capacity); | |
| 856 | 126 | } | |
| 857 | 1 | StringBuilder::StringBuilder(char* staticBuffer, size_t capacity, size_t alreadyUsed) | |
| 858 | { | ||
| 859 | 1 | gate_strbuilder_create_static(&this->impl, staticBuffer, capacity, alreadyUsed); | |
| 860 | 1 | } | |
| 861 | |||
| 862 | 254 | StringBuilder::~StringBuilder() | |
| 863 | { | ||
| 864 | 127 | gate_strbuilder_release(&this->impl); | |
| 865 | 127 | } | |
| 866 | |||
| 867 | 1 | gate_strbuilder_t const* StringBuilder::c_impl() const noexcept | |
| 868 | { | ||
| 869 | 1 | return &this->impl; | |
| 870 | } | ||
| 871 | 18 | gate_strbuilder_t* StringBuilder::c_impl() noexcept | |
| 872 | { | ||
| 873 | 18 | return &this->impl; | |
| 874 | } | ||
| 875 | |||
| 876 | 1 | char_8_t const* StringBuilder::ptr(size_t pos) const noexcept | |
| 877 | { | ||
| 878 | 1 | return gate_strbuilder_ptr(&this->impl, pos); | |
| 879 | } | ||
| 880 | 6 | size_t StringBuilder::length() const noexcept | |
| 881 | { | ||
| 882 | 6 | return gate_strbuilder_length(&this->impl); | |
| 883 | } | ||
| 884 | |||
| 885 | 1 | size_t StringBuilder::resize(size_t sz) | |
| 886 | { | ||
| 887 | 1 | return gate_strbuilder_resize(&this->impl, sz); | |
| 888 | } | ||
| 889 | 220 | size_t StringBuilder::append(String const& text) | |
| 890 | { | ||
| 891 | 220 | return gate_strbuilder_append_text(&this->impl, text.c_str(), text.length()); | |
| 892 | } | ||
| 893 | 16 | size_t StringBuilder::append(char const* ptr, size_t len) | |
| 894 | { | ||
| 895 | 16 | return gate_strbuilder_append_text(&this->impl, ptr, len); | |
| 896 | } | ||
| 897 | 1 | size_t StringBuilder::append(char_16_t const* text16, size_t textlen) | |
| 898 | { | ||
| 899 | 1 | return gate_strbuilder_append_text16(&this->impl, text16, textlen); | |
| 900 | } | ||
| 901 | 1 | size_t StringBuilder::append(char_32_t const* text32, size_t textlen) | |
| 902 | { | ||
| 903 | 1 | return gate_strbuilder_append_text32(&this->impl, text32, textlen); | |
| 904 | } | ||
| 905 | 2 | size_t StringBuilder::appendBool(bool const& b) | |
| 906 | { | ||
| 907 | 2 | return gate_strbuilder_append(&this->impl, GATE_PRINT_BOOL, b); | |
| 908 | } | ||
| 909 | |||
| 910 | 2 | size_t StringBuilder::append(int16_t const& num) | |
| 911 | { | ||
| 912 | 2 | return gate_strbuilder_append_int16(&this->impl, num); | |
| 913 | } | ||
| 914 | 2 | size_t StringBuilder::append(uint16_t const& num) | |
| 915 | { | ||
| 916 | 2 | return gate_strbuilder_append_uint16(&this->impl, num); | |
| 917 | } | ||
| 918 | 3 | size_t StringBuilder::append(int32_t const& num) | |
| 919 | { | ||
| 920 | 3 | return gate_strbuilder_append_int32(&this->impl, num); | |
| 921 | } | ||
| 922 | 4 | size_t StringBuilder::append(uint32_t const& num) | |
| 923 | { | ||
| 924 | 4 | return gate_strbuilder_append_uint32(&this->impl, num); | |
| 925 | } | ||
| 926 | 2 | size_t StringBuilder::append(int64_t const& num) | |
| 927 | { | ||
| 928 | 2 | return gate_strbuilder_append_int64(&this->impl, num); | |
| 929 | } | ||
| 930 | 4 | size_t StringBuilder::append(uint64_t const& num) | |
| 931 | { | ||
| 932 | 4 | return gate_strbuilder_append_uint64(&this->impl, num); | |
| 933 | } | ||
| 934 | 3 | size_t StringBuilder::append(real64_t const& num, unsigned intlen, unsigned decimallen, unsigned grouplen) | |
| 935 | { | ||
| 936 | 3 | return gate_strbuilder_append_real(&this->impl, num, intlen, decimallen, grouplen); | |
| 937 | } | ||
| 938 | 5 | size_t StringBuilder::appendHex(uint8_t const& num, bool_t upperCase) | |
| 939 | { | ||
| 940 | char buffer[8]; | ||
| 941 |
1/2✓ Branch 1 taken 5 times.
✗ Branch 2 not taken.
|
5 | size_t buffer_used = gate_str_print_hex_byte(buffer, sizeof(buffer), num, upperCase); |
| 942 |
1/2✓ Branch 1 taken 5 times.
✗ Branch 2 not taken.
|
10 | return this->append(buffer, buffer_used); |
| 943 | } | ||
| 944 | 3 | size_t StringBuilder::appendHex(uint16_t const& num, bool_t upperCase) | |
| 945 | { | ||
| 946 | char buffer[8]; | ||
| 947 |
1/2✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
|
3 | size_t buffer_used = gate_str_print_hex_num(buffer, sizeof(buffer), num, upperCase); |
| 948 |
1/2✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
|
6 | return this->append(buffer, buffer_used); |
| 949 | } | ||
| 950 | 3 | size_t StringBuilder::appendHex(uint32_t const& num, bool_t upperCase) | |
| 951 | { | ||
| 952 | char buffer[16]; | ||
| 953 |
1/2✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
|
3 | size_t buffer_used = gate_str_print_hex_num(buffer, sizeof(buffer), num, upperCase); |
| 954 |
1/2✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
|
6 | return this->append(buffer, buffer_used); |
| 955 | } | ||
| 956 | 2 | size_t StringBuilder::appendHex(uint64_t const& num, bool_t upperCase) | |
| 957 | { | ||
| 958 | char buffer[24]; | ||
| 959 |
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); |
| 960 |
1/2✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
|
4 | return this->append(buffer, buffer_used); |
| 961 | } | ||
| 962 | 1 | size_t StringBuilder::appendHex(char const* txt, size_t len, bool_t upperCase) | |
| 963 | { | ||
| 964 | 1 | size_t ret = 0; | |
| 965 |
2/2✓ Branch 0 taken 4 times.
✓ Branch 1 taken 1 times.
|
5 | while (len-- > 0) |
| 966 | { | ||
| 967 |
1/2✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
|
4 | ret += this->appendHex(static_cast<uint8_t>(*txt), upperCase); |
| 968 | 4 | ++txt; | |
| 969 | } | ||
| 970 | 1 | return ret; | |
| 971 | } | ||
| 972 | |||
| 973 | |||
| 974 | 1 | size_t StringBuilder::appendChars(size_t count, gate_char8_t chr) | |
| 975 | { | ||
| 976 | 1 | return gate_strbuilder_append_chars(&this->impl, count, chr); | |
| 977 | } | ||
| 978 | |||
| 979 | 5 | size_t StringBuilder::appendNewLine() | |
| 980 | { | ||
| 981 | 5 | return gate_strbuilder_append(&this->impl, GATE_PRINT_NEWLINE, GATE_PRINT_END); | |
| 982 | } | ||
| 983 | 1 | size_t StringBuilder::appendCR() | |
| 984 | { | ||
| 985 | 1 | return gate_strbuilder_append(&this->impl, GATE_PRINT_CR, GATE_PRINT_END); | |
| 986 | } | ||
| 987 | 1 | size_t StringBuilder::appendLF() | |
| 988 | { | ||
| 989 | 1 | return gate_strbuilder_append(&this->impl, GATE_PRINT_LF, GATE_PRINT_END); | |
| 990 | } | ||
| 991 | 1 | size_t StringBuilder::appendCRLF() | |
| 992 | { | ||
| 993 | 1 | return gate_strbuilder_append(&this->impl, GATE_PRINT_CRLF, GATE_PRINT_END); | |
| 994 | } | ||
| 995 | |||
| 996 | 6 | size_t StringBuilder::discard(size_t charCount) | |
| 997 | { | ||
| 998 | 6 | return gate_strbuilder_discard(&this->impl, charCount); | |
| 999 | } | ||
| 1000 | 1 | size_t StringBuilder::discardBack(size_t charCount) | |
| 1001 | { | ||
| 1002 | 1 | return gate_strbuilder_discard_back(&this->impl, charCount); | |
| 1003 | } | ||
| 1004 | 126 | String StringBuilder::toString() | |
| 1005 | { | ||
| 1006 | gate_string_t tmp; | ||
| 1007 |
2/4✓ Branch 1 taken 126 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✓ Branch 4 taken 126 times.
|
126 | if (NULL == gate_strbuilder_to_string(&this->impl, &tmp)) |
| 1008 | { | ||
| 1009 | ✗ | GATEXX_RAISE_ERROR(results::OutOfMemory); | |
| 1010 | } | ||
| 1011 | 126 | String ret = String::duplicate(tmp); | |
| 1012 |
1/2✓ Branch 1 taken 126 times.
✗ Branch 2 not taken.
|
126 | gate_string_release(&tmp); |
| 1013 | 252 | return ret; | |
| 1014 | } | ||
| 1015 | 4 | String StringBuilder::copyString() const | |
| 1016 | { | ||
| 1017 | gate_string_t tmp; | ||
| 1018 |
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)) |
| 1019 | { | ||
| 1020 | ✗ | GATEXX_RAISE_ERROR(results::OutOfMemory); | |
| 1021 | } | ||
| 1022 | 4 | String ret = String::duplicate(tmp); | |
| 1023 |
1/2✓ Branch 1 taken 4 times.
✗ Branch 2 not taken.
|
4 | gate_string_release(&tmp); |
| 1024 | 8 | return ret; | |
| 1025 | } | ||
| 1026 | |||
| 1027 | 8 | String StringBuilder::getView() const | |
| 1028 | { | ||
| 1029 | return String::createStatic( | ||
| 1030 | gate_strbuilder_ptr(&this->impl, 0), | ||
| 1031 | gate_strbuilder_length(&this->impl) | ||
| 1032 | 8 | ); | |
| 1033 | } | ||
| 1034 | |||
| 1035 | 1 | size_t StringBuilder::insert(size_t pos, String const& text) | |
| 1036 | { | ||
| 1037 | 1 | return gate_strbuilder_insert(&this->impl, pos, text.c_str(), text.length()); | |
| 1038 | } | ||
| 1039 | |||
| 1040 | |||
| 1041 | 1 | size_t StringBuilder::positionOf(String const& token, size_t startAt) | |
| 1042 | { | ||
| 1043 | 1 | return gate_strbuilder_pos(&this->impl, token.c_impl(), startAt); | |
| 1044 | } | ||
| 1045 | |||
| 1046 | 1 | size_t StringBuilder::positionOf(char const& chr, size_t startAt) | |
| 1047 | { | ||
| 1048 | 1 | return gate_strbuilder_char_pos(&this->impl, chr, startAt); | |
| 1049 | } | ||
| 1050 | |||
| 1051 | 1 | size_t StringBuilder::replace(String const& find, String const& replaceWith, size_t startAt, size_t maxReplace) | |
| 1052 | { | ||
| 1053 | 1 | return gate_strbuilder_replace_string(&this->impl, find.c_impl(), replaceWith.c_impl(), startAt, maxReplace); | |
| 1054 | } | ||
| 1055 | |||
| 1056 | 1 | size_t StringBuilder::remove(size_t fromPos, size_t length) | |
| 1057 | { | ||
| 1058 | 1 | return gate_strbuilder_remove(&this->impl, fromPos, length); | |
| 1059 | } | ||
| 1060 | |||
| 1061 | 106 | StringBuilder& StringBuilder::operator<<(String const& text) { this->append(text); return *this; } | |
| 1062 |
1/2✓ Branch 2 taken 106 times.
✗ Branch 3 not taken.
|
106 | StringBuilder& StringBuilder::operator<<(char const* text) { this->append(String(text)); return *this; } |
| 1063 | 1 | StringBuilder& StringBuilder::operator<<(int16_t const& num) { this->append(num); return *this; } | |
| 1064 | 1 | StringBuilder& StringBuilder::operator<<(uint16_t const& num) { this->append(num); return *this; } | |
| 1065 | 2 | StringBuilder& StringBuilder::operator<<(int32_t const& num) { this->append(num); return *this; } | |
| 1066 | 3 | StringBuilder& StringBuilder::operator<<(uint32_t const& num) { this->append(num); return *this; } | |
| 1067 | 1 | StringBuilder& StringBuilder::operator<<(int64_t const& num) { this->append(num); return *this; } | |
| 1068 | 3 | StringBuilder& StringBuilder::operator<<(uint64_t const& num) { this->append(num); return *this; } | |
| 1069 | 1 | StringBuilder& StringBuilder::operator<<(real64_t const& num) { this->append(num); return *this; } | |
| 1070 | |||
| 1071 | static char_8_t const empty_dummy = '\0'; | ||
| 1072 | ✗ | char_8_t const& StringBuilder::operator[](size_t index) const | |
| 1073 | { | ||
| 1074 | ✗ | gate_char8_t const* ptr = gate_strbuilder_ptr(&this->impl, index); | |
| 1075 | ✗ | if (ptr == NULL) | |
| 1076 | { | ||
| 1077 | ✗ | return empty_dummy; | |
| 1078 | } | ||
| 1079 | else | ||
| 1080 | { | ||
| 1081 | ✗ | return *ptr; | |
| 1082 | } | ||
| 1083 | } | ||
| 1084 | 1 | char_8_t& StringBuilder::operator[](size_t index) | |
| 1085 | { | ||
| 1086 | 1 | gate_char8_t const* ptr = gate_strbuilder_ptr(&this->impl, index); | |
| 1087 | 1 | return *const_cast<gate_char8_t*>(ptr); | |
| 1088 | } | ||
| 1089 | |||
| 1090 | |||
| 1091 | 1 | CstrBuffer::CstrBuffer(char const* ptr, size_t length, bool_t copyNeeded) | |
| 1092 | { | ||
| 1093 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | if (NULL == gate_cstrbuffer_create(&this->impl, ptr, length, copyNeeded)) |
| 1094 | { | ||
| 1095 | ✗ | GATEXX_RAISE_ERROR(results::OutOfMemory); | |
| 1096 | } | ||
| 1097 | 1 | } | |
| 1098 | 1 | CstrBuffer::CstrBuffer(wchar_t const* ptr, gate_size_t length) | |
| 1099 | { | ||
| 1100 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | if (NULL == gate_cstrbuffer_create_wstr(&this->impl, ptr, length)) |
| 1101 | { | ||
| 1102 | ✗ | GATEXX_RAISE_ERROR(results::OutOfMemory); | |
| 1103 | } | ||
| 1104 | 1 | } | |
| 1105 | |||
| 1106 | 1 | CstrBuffer::CstrBuffer(String const& str, bool_t copyNeeded) | |
| 1107 | { | ||
| 1108 |
1/2✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
|
1 | if (NULL == gate_cstrbuffer_create_string(&this->impl, str.c_impl(), copyNeeded)) |
| 1109 | { | ||
| 1110 | ✗ | GATEXX_RAISE_ERROR(results::OutOfMemory); | |
| 1111 | } | ||
| 1112 | 1 | } | |
| 1113 | 6 | CstrBuffer::~CstrBuffer() noexcept | |
| 1114 | { | ||
| 1115 | 3 | gate_cstrbuffer_destroy(&this->impl); | |
| 1116 | 3 | } | |
| 1117 | 1 | gate_cstrbuffer_t const* CstrBuffer::c_impl() const | |
| 1118 | { | ||
| 1119 | 1 | return &this->impl; | |
| 1120 | } | ||
| 1121 | 2 | char const* CstrBuffer::get() const | |
| 1122 | { | ||
| 1123 | 2 | return gate_cstrbuffer_get(&this->impl); | |
| 1124 | } | ||
| 1125 | 1 | size_t CstrBuffer::length() const | |
| 1126 | { | ||
| 1127 | 1 | return gate_cstrbuffer_length(&this->impl); | |
| 1128 | } | ||
| 1129 | |||
| 1130 | |||
| 1131 | 1 | CstrBuffer16::CstrBuffer16(char_16_t const* ptr, size_t length, bool_t copyNeeded) | |
| 1132 | { | ||
| 1133 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | if (NULL == gate_cstrbuffer16_create(&this->impl, ptr, length, copyNeeded)) |
| 1134 | { | ||
| 1135 | ✗ | GATEXX_RAISE_ERROR(results::OutOfMemory); | |
| 1136 | } | ||
| 1137 | 1 | } | |
| 1138 | 1 | CstrBuffer16::CstrBuffer16(String const& str) | |
| 1139 | { | ||
| 1140 |
1/2✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
|
1 | if (NULL == gate_cstrbuffer16_create_string(&this->impl, str.c_impl())) |
| 1141 | { | ||
| 1142 | ✗ | GATEXX_RAISE_ERROR(results::OutOfMemory); | |
| 1143 | } | ||
| 1144 | 1 | } | |
| 1145 | 4 | CstrBuffer16::~CstrBuffer16() noexcept | |
| 1146 | { | ||
| 1147 | 2 | gate_cstrbuffer16_destroy(&this->impl); | |
| 1148 | 2 | } | |
| 1149 | 1 | gate_cstrbuffer16_t const* CstrBuffer16::c_impl() const | |
| 1150 | { | ||
| 1151 | 1 | return &this->impl; | |
| 1152 | } | ||
| 1153 | 1 | char_16_t const* CstrBuffer16::get() const | |
| 1154 | { | ||
| 1155 | 1 | return gate_cstrbuffer16_get(&this->impl); | |
| 1156 | } | ||
| 1157 | 1 | size_t CstrBuffer16::length() const | |
| 1158 | { | ||
| 1159 | 1 | return gate_cstrbuffer16_length(&this->impl); | |
| 1160 | } | ||
| 1161 | |||
| 1162 | |||
| 1163 | 1 | CstrBuffer32::CstrBuffer32(char_32_t const* ptr, size_t length, bool_t copyNeeded) | |
| 1164 | { | ||
| 1165 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
|
1 | if (NULL == gate_cstrbuffer32_create(&this->impl, ptr, length, copyNeeded)) |
| 1166 | { | ||
| 1167 | ✗ | GATEXX_RAISE_ERROR(results::OutOfMemory); | |
| 1168 | } | ||
| 1169 | 1 | } | |
| 1170 | 1 | CstrBuffer32::CstrBuffer32(String const& str) | |
| 1171 | { | ||
| 1172 |
1/2✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
|
1 | if (NULL == gate_cstrbuffer32_create_string(&this->impl, str.c_impl())) |
| 1173 | { | ||
| 1174 | ✗ | GATEXX_RAISE_ERROR(results::OutOfMemory); | |
| 1175 | } | ||
| 1176 | 1 | } | |
| 1177 | 4 | CstrBuffer32::~CstrBuffer32() noexcept | |
| 1178 | { | ||
| 1179 | 2 | gate_cstrbuffer32_destroy(&this->impl); | |
| 1180 | 2 | } | |
| 1181 | 1 | gate_cstrbuffer32_t const* CstrBuffer32::c_impl() const | |
| 1182 | { | ||
| 1183 | 1 | return &this->impl; | |
| 1184 | } | ||
| 1185 | 1 | char_32_t const* CstrBuffer32::get() const | |
| 1186 | { | ||
| 1187 | 1 | return gate_cstrbuffer32_get(&this->impl); | |
| 1188 | } | ||
| 1189 | 1 | size_t CstrBuffer32::length() const | |
| 1190 | { | ||
| 1191 | 1 | return gate_cstrbuffer32_length(&this->impl); | |
| 1192 | } | ||
| 1193 | |||
| 1194 | |||
| 1195 | |||
| 1196 | |||
| 1197 | namespace strings | ||
| 1198 | { | ||
| 1199 | String const NewLine = String::createStatic(GATE_STR_NEWLINE, GATE_STR_NEWLINE_LENGTH); | ||
| 1200 | String const Cr = String::createStatic(GATE_STR_CR, 1); | ||
| 1201 | String const Lf = String::createStatic(GATE_STR_LF, 1); | ||
| 1202 | String const CrLf = String::createStatic(GATE_STR_CRLF, 2); | ||
| 1203 | String const Empty = String(); | ||
| 1204 | |||
| 1205 | } // end of namespace strings | ||
| 1206 | |||
| 1207 | |||
| 1208 | |||
| 1209 | |||
| 1210 | } // end of namespace gate | ||
| 1211 |