GCC Code Coverage Report


Directory: src/gate/
File: src/gate/encode/cxx_texts.cpp
Date: 2026-02-03 22:06:38
Exec Total Coverage
Lines: 159 170 93.5%
Functions: 44 48 91.7%
Branches: 38 82 46.3%

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 #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 2 void Text::unescapeC(String const& src, StringBuilder& dst)
126 {
127 2 result_t res = gate_text_c_unescape(src.c_impl(), dst.c_impl());
128
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 GATEXX_CHECK_EXCEPTION(res);
129 2 }
130 2 String Text::unescapeC(String const& src)
131 {
132
1/2
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
4 StringBuilder builder;
133
1/2
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
2 unescapeC(src, builder);
134
1/2
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
4 return builder.toString();
135 }
136 2 size_t Text::unescapeC(char const* src, size_t srclen, char* dst, size_t dstcapacity)
137 {
138 2 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 1 void TextFormat::addText(String const& text)
186 {
187 1 result_t res = gate_text_format_text(&this->impl, text.c_impl());
188
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 GATEXX_CHECK_ERROR(res);
189 1 }
190 2 void TextFormat::addStr(char const* str)
191 {
192 2 result_t res = gate_text_format_str(&this->impl, str);
193
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 GATEXX_CHECK_ERROR(res);
194 2 }
195
196 10 void TextFormat::addInt(gate_int64_t num)
197 {
198 10 result_t res = gate_text_format_int(&this->impl, num);
199
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10 times.
10 GATEXX_CHECK_ERROR(res);
200 10 }
201 2 void TextFormat::addReal(gate_real64_t num)
202 {
203 2 result_t res = gate_text_format_real(&this->impl, num);
204
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 GATEXX_CHECK_ERROR(res);
205 2 }
206
207 3 String TextFormat::toString()
208 {
209 3 gate_string_t tmp = GATE_STRING_INIT_EMPTY;
210
1/2
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
3 result_t res = gate_text_format_print(&this->impl, &tmp);
211
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 3 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
3 GATEXX_CHECK_ERROR(res);
212 6 return String::createFrom(tmp);
213 }
214 1 String TextFormat::toString() const
215 {
216 1 gate_string_t tmp = GATE_STRING_INIT_EMPTY;
217
1/2
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
1 result_t res = gate_text_format_extract(&this->impl, &tmp);
218
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
1 GATEXX_CHECK_ERROR(res);
219 2 return String::createFrom(tmp);
220 }
221
222 3 TextFormat::operator String()
223 {
224 3 return this->toString();
225 }
226 1 TextFormat::operator String() const
227 {
228 1 return this->toString();
229 }
230
231
232 1 TextFormat& TextFormat::operator%(String const& text)
233 {
234 1 this->addText(text);
235 1 return *this;
236 }
237 2 TextFormat& TextFormat::operator%(char const* text)
238 {
239 2 this->addStr(text);
240 2 return *this;
241 }
242
243 1 TextFormat& TextFormat::operator%(int8_t const& num)
244 {
245 1 this->addInt(static_cast<int64_t>(num));
246 1 return *this;
247 }
248 1 TextFormat& TextFormat::operator%(int16_t const& num)
249 {
250 1 this->addInt(static_cast<int64_t>(num));
251 1 return *this;
252 }
253 3 TextFormat& TextFormat::operator%(int32_t const& num)
254 {
255 3 this->addInt(static_cast<int64_t>(num));
256 3 return *this;
257 }
258 1 TextFormat& TextFormat::operator%(int64_t const& num)
259 {
260 1 this->addInt(static_cast<int64_t>(num));
261 1 return *this;
262 }
263 1 TextFormat& TextFormat::operator%(uint8_t const& num)
264 {
265 1 this->addInt(static_cast<int64_t>(num));
266 1 return *this;
267 }
268 1 TextFormat& TextFormat::operator%(uint16_t const& num)
269 {
270 1 this->addInt(static_cast<int64_t>(num));
271 1 return *this;
272 }
273 1 TextFormat& TextFormat::operator%(uint32_t const& num)
274 {
275 1 this->addInt(static_cast<int64_t>(num));
276 1 return *this;
277 }
278 1 TextFormat& TextFormat::operator%(uint64_t const& num)
279 {
280 1 this->addInt(static_cast<int64_t>(num));
281 1 return *this;
282 }
283 TextFormat& TextFormat::operator%(real32_t const& real)
284 {
285 this->addReal(static_cast<real64_t>(real));
286 return *this;
287 }
288 2 TextFormat& TextFormat::operator%(real64_t const& real)
289 {
290 2 this->addReal(static_cast<real64_t>(real));
291 2 return *this;
292 }
293
294 gate_text_formater_t* TextFormat::c_impl()
295 {
296 return &this->impl;
297 }
298 gate_text_formater_t const* TextFormat::c_impl() const
299 {
300 return &this->impl;
301 }
302
303
304 } // end of namespace enc
305 } // end of namespace gate
306