MCPcopy Create free account
hub / github.com/Kitware/VTK / xmlEscapeEntities

Function xmlEscapeEntities

ThirdParty/libxml2/vtklibxml2/xmlsave.c:184–267  ·  view source on GitHub ↗

* xmlEscapeEntities: * @out: a pointer to an array of bytes to store the result * @outlen: the length of @out * @in: a pointer to an array of unescaped UTF-8 bytes * @inlen: the length of @in * * Take a block of UTF-8 chars in and escape them. Used when there is no * encoding specified. * * Returns 0 if success, or -1 otherwise * The value of @inlen after return is the number of octe

Source from the content-addressed store, hash-verified

182 * The value of @outlen after return is the number of octets consumed.
183 */
184static int
185xmlEscapeEntities(unsigned char* out, int *outlen,
186 const xmlChar* in, int *inlen) {
187 unsigned char* outstart = out;
188 const unsigned char* base = in;
189 unsigned char* outend = out + *outlen;
190 const unsigned char* inend;
191 int val;
192
193 inend = in + (*inlen);
194
195 while ((in < inend) && (out < outend)) {
196 if (*in == '<') {
197 if (outend - out < 4) break;
198 *out++ = '&';
199 *out++ = 'l';
200 *out++ = 't';
201 *out++ = ';';
202 in++;
203 continue;
204 } else if (*in == '>') {
205 if (outend - out < 4) break;
206 *out++ = '&';
207 *out++ = 'g';
208 *out++ = 't';
209 *out++ = ';';
210 in++;
211 continue;
212 } else if (*in == '&') {
213 if (outend - out < 5) break;
214 *out++ = '&';
215 *out++ = 'a';
216 *out++ = 'm';
217 *out++ = 'p';
218 *out++ = ';';
219 in++;
220 continue;
221 } else if (*in == 0xD) {
222 if (outend - out < 5) break;
223 *out++ = '&';
224 *out++ = '#';
225 *out++ = 'x';
226 *out++ = 'D';
227 *out++ = ';';
228 in++;
229 } else if (((*in >= 0x20) && (*in < 0x80)) ||
230 (*in == 0xA) || (*in == 0x9)) {
231 /*
232 * default case, just copy !
233 */
234 *out++ = *in++;
235 continue;
236 } else if (*in < 0x80) {
237 /* invalid control char */
238 if (outend - out < 8) break;
239 out = xmlSerializeHexCharRef(out, 0xFFFD);
240 in++;
241 } else {

Callers

nothing calls this directly

Calls 2

xmlSerializeHexCharRefFunction · 0.85
xmlGetUTF8CharFunction · 0.85

Tested by

no test coverage detected