| 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 | #include "gate/encode/texts.hpp" | ||
| 29 | #include "gate/exceptions.hpp" | ||
| 30 | #include "gate/encode/texts.h" | ||
| 31 | |||
| 32 | |||
| 33 | namespace gate | ||
| 34 | { | ||
| 35 | namespace enc | ||
| 36 | { | ||
| 37 | |||
| 38 | 6 | size_t Text::detectBomType(char const* data, size_t datalen, BomTypeEnum& bomtype) | |
| 39 | { | ||
| 40 | 6 | unsigned int tp = 0; | |
| 41 |
1/2✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
|
6 | gate_size_t ret = gate_text_detect_bom(data, datalen, &tp); |
| 42 | 6 | bomtype = (BomTypeEnum)tp; | |
| 43 | 6 | return ret; | |
| 44 | } | ||
| 45 | |||
| 46 | 1 | void Text::loadUtf8(Stream& src, StringBuilder& dst) | |
| 47 | { | ||
| 48 | 1 | result_t res = gate_text_load_utf8(src.c_impl(), dst.c_impl()); | |
| 49 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | GATEXX_CHECK_EXCEPTION(res); |
| 50 | 1 | } | |
| 51 | 1 | void Text::loadAnsi(Stream& src, StringBuilder& dst) | |
| 52 | { | ||
| 53 | 1 | result_t res = gate_text_load_ansi(src.c_impl(), dst.c_impl()); | |
| 54 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | GATEXX_CHECK_EXCEPTION(res); |
| 55 | 1 | } | |
| 56 | 1 | void Text::loadUtf16LE(Stream& src, StringBuilder& dst) | |
| 57 | { | ||
| 58 | 1 | result_t res = gate_text_load_utf16le(src.c_impl(), dst.c_impl()); | |
| 59 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | GATEXX_CHECK_EXCEPTION(res); |
| 60 | 1 | } | |
| 61 | 1 | void Text::loadUtf16BE(Stream& src, StringBuilder& dst) | |
| 62 | { | ||
| 63 | 1 | result_t res = gate_text_load_utf16be(src.c_impl(), dst.c_impl()); | |
| 64 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | GATEXX_CHECK_EXCEPTION(res); |
| 65 | 1 | } | |
| 66 | 1 | void Text::loadUtf32LE(Stream& src, StringBuilder& dst) | |
| 67 | { | ||
| 68 | 1 | result_t res = gate_text_load_utf32le(src.c_impl(), dst.c_impl()); | |
| 69 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | GATEXX_CHECK_EXCEPTION(res); |
| 70 | 1 | } | |
| 71 | 1 | void Text::loadUtf32BE(Stream& src, StringBuilder& dst) | |
| 72 | { | ||
| 73 | 1 | result_t res = gate_text_load_utf32be(src.c_impl(), dst.c_impl()); | |
| 74 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | GATEXX_CHECK_EXCEPTION(res); |
| 75 | 1 | } | |
| 76 | |||
| 77 | |||
| 78 | 1 | void Text::saveUtf8(String const& src, Stream& dst, bool addbom) | |
| 79 | { | ||
| 80 | 1 | result_t res = gate_text_save_utf8(src.c_impl(), dst.c_impl(), addbom); | |
| 81 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | GATEXX_CHECK_EXCEPTION(res); |
| 82 | 1 | } | |
| 83 | 1 | void Text::saveAnsi(String const& src, Stream& dst) | |
| 84 | { | ||
| 85 | 1 | result_t res = gate_text_save_ansi(src.c_impl(), dst.c_impl()); | |
| 86 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | GATEXX_CHECK_EXCEPTION(res); |
| 87 | 1 | } | |
| 88 | 1 | void Text::saveUtf16LE(String const& src, Stream& dst, bool addbom) | |
| 89 | { | ||
| 90 | 1 | result_t res = gate_text_save_utf16le(src.c_impl(), dst.c_impl(), addbom); | |
| 91 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | GATEXX_CHECK_EXCEPTION(res); |
| 92 | 1 | } | |
| 93 | 1 | void Text::saveUtf16BE(String const& src, Stream& dst, bool addbom) | |
| 94 | { | ||
| 95 | 1 | result_t res = gate_text_save_utf16be(src.c_impl(), dst.c_impl(), addbom); | |
| 96 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | GATEXX_CHECK_EXCEPTION(res); |
| 97 | 1 | } | |
| 98 | 1 | void Text::saveUtf32LE(String const& src, Stream& dst, bool addbom) | |
| 99 | { | ||
| 100 | 1 | result_t res = gate_text_save_utf32le(src.c_impl(), dst.c_impl(), addbom); | |
| 101 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | GATEXX_CHECK_EXCEPTION(res); |
| 102 | 1 | } | |
| 103 | 1 | void Text::saveUtf32BE(String const& src, Stream& dst, bool addbom) | |
| 104 | { | ||
| 105 | 1 | result_t res = gate_text_save_utf32be(src.c_impl(), dst.c_impl(), addbom); | |
| 106 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | GATEXX_CHECK_EXCEPTION(res); |
| 107 | 1 | } | |
| 108 | |||
| 109 | 1 | void Text::escapeC(String const& src, StringBuilder& dst) | |
| 110 | { | ||
| 111 | 1 | result_t res = gate_text_c_escape(src.c_impl(), dst.c_impl()); | |
| 112 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | GATEXX_CHECK_EXCEPTION(res); |
| 113 | 1 | } | |
| 114 | 1 | String Text::escapeC(String const& src) | |
| 115 | { | ||
| 116 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 | StringBuilder builder; |
| 117 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | escapeC(src, builder); |
| 118 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 | return builder.toString(); |
| 119 | } | ||
| 120 | 1 | size_t Text::escapeC(char const* src, size_t srclen, char* dst, size_t dstcapacity) | |
| 121 | { | ||
| 122 | 1 | return gate_text_c_escape_str(src, srclen, dst, dstcapacity); | |
| 123 | } | ||
| 124 | |||
| 125 | 1 | void Text::unescapeC(String const& src, StringBuilder& dst) | |
| 126 | { | ||
| 127 | 1 | result_t res = gate_text_c_unescape(src.c_impl(), dst.c_impl()); | |
| 128 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | GATEXX_CHECK_EXCEPTION(res); |
| 129 | 1 | } | |
| 130 | 1 | String Text::unescapeC(String const& src) | |
| 131 | { | ||
| 132 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 | StringBuilder builder; |
| 133 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | unescapeC(src, builder); |
| 134 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 | return builder.toString(); |
| 135 | } | ||
| 136 | 1 | size_t Text::unescapeC(char const* src, size_t srclen, char* dst, size_t dstcapacity) | |
| 137 | { | ||
| 138 | 1 | return gate_text_c_unescape_str(src, srclen, dst, dstcapacity); | |
| 139 | } | ||
| 140 | |||
| 141 | |||
| 142 | 1 | void Text::printVarToken(StringBuilder& builder, String const& varName) | |
| 143 | { | ||
| 144 | 1 | result_t res = gate_text_print_vartoken(builder.c_impl(), varName.c_impl()); | |
| 145 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | GATEXX_CHECK_EXCEPTION(res); |
| 146 | 1 | } | |
| 147 | 1 | String Text::printVarToken(String const& varName) | |
| 148 | { | ||
| 149 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 | StringBuilder sb; |
| 150 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | Text::printVarToken(sb, varName); |
| 151 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 | return sb.toString(); |
| 152 | } | ||
| 153 | |||
| 154 | 1 | void Text::printVars(StringBuilder& builder, String const& format, Map<String, String> const& varMap) | |
| 155 | { | ||
| 156 | 1 | result_t res = gate_text_print_vars(builder.c_impl(), format.c_impl(), varMap.c_impl()); | |
| 157 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
|
1 | GATEXX_CHECK_EXCEPTION(res); |
| 158 | 1 | } | |
| 159 | 1 | String Text::printVars(String const& format, Map<String, String> const& varMap) | |
| 160 | { | ||
| 161 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 | StringBuilder sb; |
| 162 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
1 | Text::printVars(sb, format, varMap); |
| 163 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 | return sb.toString(); |
| 164 | } | ||
| 165 | |||
| 166 | |||
| 167 | |||
| 168 | |||
| 169 | ✗ | TextFormat::TextFormat(String const& format) | |
| 170 | { | ||
| 171 | ✗ | result_t res = gate_text_format_create(&this->impl, format.c_impl()); | |
| 172 | ✗ | GATEXX_CHECK_ERROR(res); | |
| 173 | ✗ | } | |
| 174 | 3 | TextFormat::TextFormat(char const* format) | |
| 175 | { | ||
| 176 | 3 | result_t res = gate_text_format_create_str(&this->impl, format); | |
| 177 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
|
3 | GATEXX_CHECK_ERROR(res); |
| 178 | 3 | } | |
| 179 | |||
| 180 | 6 | TextFormat::~TextFormat() | |
| 181 | { | ||
| 182 | 3 | gate_text_format_destroy(&this->impl); | |
| 183 | 3 | } | |
| 184 | |||
| 185 | 2 | void TextFormat::addText(String const& text) | |
| 186 | { | ||
| 187 | 2 | result_t res = gate_text_format_text(&this->impl, text.c_impl()); | |
| 188 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | GATEXX_CHECK_ERROR(res); |
| 189 | 2 | } | |
| 190 | 10 | void TextFormat::addInt(gate_int64_t num) | |
| 191 | { | ||
| 192 | 10 | result_t res = gate_text_format_int(&this->impl, num); | |
| 193 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 10 times.
|
10 | GATEXX_CHECK_ERROR(res); |
| 194 | 10 | } | |
| 195 | 2 | void TextFormat::addReal(gate_real64_t num) | |
| 196 | { | ||
| 197 | 2 | result_t res = gate_text_format_real(&this->impl, num); | |
| 198 |
1/2✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
|
2 | GATEXX_CHECK_ERROR(res); |
| 199 | 2 | } | |
| 200 | |||
| 201 | 3 | String TextFormat::toString() | |
| 202 | { | ||
| 203 | 3 | gate_string_t tmp = GATE_STRING_INIT_EMPTY; | |
| 204 |
1/2✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
|
3 | result_t res = gate_text_format_print(&this->impl, &tmp); |
| 205 |
1/4✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
|
3 | GATEXX_CHECK_ERROR(res); |
| 206 | 6 | return String::createFrom(tmp); | |
| 207 | } | ||
| 208 | ✗ | String TextFormat::toString() const | |
| 209 | { | ||
| 210 | ✗ | gate_string_t tmp = GATE_STRING_INIT_EMPTY; | |
| 211 | ✗ | result_t res = gate_text_format_extract(&this->impl, &tmp); | |
| 212 | ✗ | GATEXX_CHECK_ERROR(res); | |
| 213 | ✗ | return String::createFrom(tmp); | |
| 214 | } | ||
| 215 | |||
| 216 | 3 | TextFormat::operator String() | |
| 217 | { | ||
| 218 | 3 | return this->toString(); | |
| 219 | } | ||
| 220 | ✗ | TextFormat::operator String() const | |
| 221 | { | ||
| 222 | ✗ | return this->toString(); | |
| 223 | } | ||
| 224 | |||
| 225 | |||
| 226 | 2 | TextFormat& TextFormat::operator%(String const& text) | |
| 227 | { | ||
| 228 | 2 | this->addText(text); | |
| 229 | 2 | return *this; | |
| 230 | } | ||
| 231 | 1 | TextFormat& TextFormat::operator%(int8_t const& num) | |
| 232 | { | ||
| 233 | 1 | this->addInt(static_cast<int64_t>(num)); | |
| 234 | 1 | return *this; | |
| 235 | } | ||
| 236 | 1 | TextFormat& TextFormat::operator%(int16_t const& num) | |
| 237 | { | ||
| 238 | 1 | this->addInt(static_cast<int64_t>(num)); | |
| 239 | 1 | return *this; | |
| 240 | } | ||
| 241 | 3 | TextFormat& TextFormat::operator%(int32_t const& num) | |
| 242 | { | ||
| 243 | 3 | this->addInt(static_cast<int64_t>(num)); | |
| 244 | 3 | return *this; | |
| 245 | } | ||
| 246 | 1 | TextFormat& TextFormat::operator%(int64_t const& num) | |
| 247 | { | ||
| 248 | 1 | this->addInt(static_cast<int64_t>(num)); | |
| 249 | 1 | return *this; | |
| 250 | } | ||
| 251 | 1 | TextFormat& TextFormat::operator%(uint8_t const& num) | |
| 252 | { | ||
| 253 | 1 | this->addInt(static_cast<int64_t>(num)); | |
| 254 | 1 | return *this; | |
| 255 | } | ||
| 256 | 1 | TextFormat& TextFormat::operator%(uint16_t const& num) | |
| 257 | { | ||
| 258 | 1 | this->addInt(static_cast<int64_t>(num)); | |
| 259 | 1 | return *this; | |
| 260 | } | ||
| 261 | 1 | TextFormat& TextFormat::operator%(uint32_t const& num) | |
| 262 | { | ||
| 263 | 1 | this->addInt(static_cast<int64_t>(num)); | |
| 264 | 1 | return *this; | |
| 265 | } | ||
| 266 | 1 | TextFormat& TextFormat::operator%(uint64_t const& num) | |
| 267 | { | ||
| 268 | 1 | this->addInt(static_cast<int64_t>(num)); | |
| 269 | 1 | return *this; | |
| 270 | } | ||
| 271 | ✗ | TextFormat& TextFormat::operator%(real32_t const& real) | |
| 272 | { | ||
| 273 | ✗ | this->addReal(static_cast<real64_t>(real)); | |
| 274 | ✗ | return *this; | |
| 275 | } | ||
| 276 | 2 | TextFormat& TextFormat::operator%(real64_t const& real) | |
| 277 | { | ||
| 278 | 2 | this->addReal(static_cast<real64_t>(real)); | |
| 279 | 2 | return *this; | |
| 280 | } | ||
| 281 | |||
| 282 | ✗ | gate_text_formater_t* TextFormat::c_impl() | |
| 283 | { | ||
| 284 | ✗ | return &this->impl; | |
| 285 | } | ||
| 286 | ✗ | gate_text_formater_t const* TextFormat::c_impl() const | |
| 287 | { | ||
| 288 | ✗ | return &this->impl; | |
| 289 | } | ||
| 290 | |||
| 291 | |||
| 292 | } // end of namespace enc | ||
| 293 | } // end of namespace gate | ||
| 294 |