ReactOS 0.4.16-dev-297-gc569aee
enc.h File Reference
#include <libxml/tree.h>
Include dependency graph for enc.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

int xmlCharEncFirstLineInt (xmlCharEncodingHandler *handler, xmlBufferPtr out, xmlBufferPtr in, int len)
 
int xmlCharEncFirstLineInput (xmlParserInputBufferPtr input, int len)
 
int xmlCharEncInput (xmlParserInputBufferPtr input, int flush)
 
int xmlCharEncOutput (xmlOutputBufferPtr output, int init)
 

Function Documentation

◆ xmlCharEncFirstLineInput()

int xmlCharEncFirstLineInput ( xmlParserInputBufferPtr  input,
int  len 
)

xmlCharEncFirstLineInput: @input: a parser input buffer @len: number of bytes to convert for the first line, or -1

Front-end for the encoding handler input function, but handle only the very first line. Point is that this is based on autodetection of the encoding and once that first line is converted we may find out that a different decoder is needed to process the input.

Returns the number of byte written if success, or -1 general error -2 if the transcoding fails (for *in is not valid utf8 string or the result of transformation can't fit into the encoding we want), or

Definition at line 2181 of file encoding.c.

2182{
2183 int ret;
2184 size_t written;
2185 size_t toconv;
2186 int c_in;
2187 int c_out;
2188 xmlBufPtr in;
2189 xmlBufPtr out;
2190
2191 if ((input == NULL) || (input->encoder == NULL) ||
2192 (input->buffer == NULL) || (input->raw == NULL))
2193 return (-1);
2194 out = input->buffer;
2195 in = input->raw;
2196
2197 toconv = xmlBufUse(in);
2198 if (toconv == 0)
2199 return (0);
2200 written = xmlBufAvail(out);
2201 /*
2202 * echo '<?xml version="1.0" encoding="UCS4"?>' | wc -c => 38
2203 * 45 chars should be sufficient to reach the end of the encoding
2204 * declaration without going too far inside the document content.
2205 * on UTF-16 this means 90bytes, on UCS4 this means 180
2206 * The actual value depending on guessed encoding is passed as @len
2207 * if provided
2208 */
2209 if (len >= 0) {
2210 if (toconv > (unsigned int) len)
2211 toconv = len;
2212 } else {
2213 if (toconv > 180)
2214 toconv = 180;
2215 }
2216 if (toconv * 2 >= written) {
2217 xmlBufGrow(out, toconv * 2);
2218 written = xmlBufAvail(out);
2219 }
2220 if (written > 360)
2221 written = 360;
2222
2223 c_in = toconv;
2224 c_out = written;
2225 ret = xmlEncInputChunk(input->encoder, xmlBufEnd(out), &c_out,
2226 xmlBufContent(in), &c_in, 0);
2227 xmlBufShrink(in, c_in);
2228 xmlBufAddLen(out, c_out);
2229 if (ret == -1)
2230 ret = -3;
2231
2232 switch (ret) {
2233 case 0:
2234#ifdef DEBUG_ENCODING
2236 "converted %d bytes to %d bytes of input\n",
2237 c_in, c_out);
2238#endif
2239 break;
2240 case -1:
2241#ifdef DEBUG_ENCODING
2243 "converted %d bytes to %d bytes of input, %d left\n",
2244 c_in, c_out, (int)xmlBufUse(in));
2245#endif
2246 break;
2247 case -3:
2248#ifdef DEBUG_ENCODING
2250 "converted %d bytes to %d bytes of input, %d left\n",
2251 c_in, c_out, (int)xmlBufUse(in));
2252#endif
2253 break;
2254 case -2: {
2255 char buf[50];
2256 const xmlChar *content = xmlBufContent(in);
2257
2258 snprintf(&buf[0], 49, "0x%02X 0x%02X 0x%02X 0x%02X",
2259 content[0], content[1],
2260 content[2], content[3]);
2261 buf[49] = 0;
2262 xmlEncodingErr(XML_I18N_CONV_FAILED,
2263 "input conversion failed due to input error, bytes %s\n",
2264 buf);
2265 }
2266 }
2267 /*
2268 * Ignore when input buffer is not on a boundary
2269 */
2270 if (ret == -3) ret = 0;
2271 if (ret == -1) ret = 0;
2272 return(c_out ? c_out : ret);
2273}
size_t xmlBufAvail(const xmlBufPtr buf)
Definition: buf.c:655
int xmlBufAddLen(xmlBufPtr buf, size_t len)
Definition: buf.c:592
int xmlBufGrow(xmlBufPtr buf, int len)
Definition: buf.c:498
#define NULL
Definition: types.h:112
content
Definition: atl_ax.c:994
static int xmlEncInputChunk(xmlCharEncodingHandler *handler, unsigned char *out, int *outlen, const unsigned char *in, int *inlen, int flush)
Definition: encoding.c:1979
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
GLuint in
Definition: glext.h:9616
GLenum GLsizei len
Definition: glext.h:6722
GLenum GLenum GLenum input
Definition: glext.h:9031
static FILE * out
Definition: regtests2xml.c:44
XMLPUBVAR void * xmlGenericErrorContext
Definition: globals.h:353
XMLPUBVAR xmlGenericErrorFunc xmlGenericError
Definition: globals.h:337
XMLPUBFUN xmlChar *XMLCALL xmlBufEnd(xmlBufPtr buf)
Definition: buf.c:571
XMLPUBFUN size_t XMLCALL xmlBufUse(const xmlBufPtr buf)
Definition: buf.c:633
XMLPUBFUN size_t XMLCALL xmlBufShrink(xmlBufPtr buf, size_t len)
Definition: buf.c:381
XMLPUBFUN xmlChar *XMLCALL xmlBufContent(const xmlBuf *buf)
Definition: buf.c:553
Definition: buf.c:43
int ret
#define snprintf
Definition: wintirpc.h:48
@ XML_I18N_CONV_FAILED
Definition: xmlerror.h:833
unsigned char xmlChar
Definition: xmlstring.h:28

Referenced by xmlSwitchInputEncodingInt().

◆ xmlCharEncFirstLineInt()

int xmlCharEncFirstLineInt ( xmlCharEncodingHandler handler,
xmlBufferPtr  out,
xmlBufferPtr  in,
int  len 
)

xmlCharEncFirstLineInt: @handler: char encoding transformation data structure @out: an xmlBuffer for the output. @in: an xmlBuffer for the input @len: number of bytes to convert for the first line, or -1

Front-end for the encoding handler input function, but handle only the very first line, i.e. limit itself to 45 chars.

Returns the number of byte written if success, or -1 general error -2 if the transcoding fails (for *in is not valid utf8 string or the result of transformation can't fit into the encoding we want), or

Definition at line 2074 of file encoding.c.

2075 {
2076 int ret;
2077 int written;
2078 int toconv;
2079
2080 if (handler == NULL) return(-1);
2081 if (out == NULL) return(-1);
2082 if (in == NULL) return(-1);
2083
2084 /* calculate space available */
2085 written = out->size - out->use - 1; /* count '\0' */
2086 toconv = in->use;
2087 /*
2088 * echo '<?xml version="1.0" encoding="UCS4"?>' | wc -c => 38
2089 * 45 chars should be sufficient to reach the end of the encoding
2090 * declaration without going too far inside the document content.
2091 * on UTF-16 this means 90bytes, on UCS4 this means 180
2092 * The actual value depending on guessed encoding is passed as @len
2093 * if provided
2094 */
2095 if (len >= 0) {
2096 if (toconv > len)
2097 toconv = len;
2098 } else {
2099 if (toconv > 180)
2100 toconv = 180;
2101 }
2102 if (toconv * 2 >= written) {
2103 xmlBufferGrow(out, toconv * 2);
2104 written = out->size - out->use - 1;
2105 }
2106
2107 ret = xmlEncInputChunk(handler, &out->content[out->use], &written,
2108 in->content, &toconv, 0);
2109 xmlBufferShrink(in, toconv);
2110 out->use += written;
2111 out->content[out->use] = 0;
2112 if (ret == -1) ret = -3;
2113
2114#ifdef DEBUG_ENCODING
2115 switch (ret) {
2116 case 0:
2118 "converted %d bytes to %d bytes of input\n",
2119 toconv, written);
2120 break;
2121 case -1:
2122 xmlGenericError(xmlGenericErrorContext,"converted %d bytes to %d bytes of input, %d left\n",
2123 toconv, written, in->use);
2124 break;
2125 case -2:
2127 "input conversion failed due to input error\n");
2128 break;
2129 case -3:
2130 xmlGenericError(xmlGenericErrorContext,"converted %d bytes to %d bytes of input, %d left\n",
2131 toconv, written, in->use);
2132 break;
2133 default:
2134 xmlGenericError(xmlGenericErrorContext,"Unknown input conversion failed %d\n", ret);
2135 }
2136#endif /* DEBUG_ENCODING */
2137 /*
2138 * Ignore when input buffer is not on a boundary
2139 */
2140 if (ret == -3) ret = 0;
2141 if (ret == -1) ret = 0;
2142 return(written ? written : ret);
2143}
UINT(* handler)(MSIPACKAGE *)
Definition: action.c:7512
XMLPUBFUN int XMLCALL xmlBufferShrink(xmlBufferPtr buf, unsigned int len)
XMLPUBFUN int XMLCALL xmlBufferGrow(xmlBufferPtr buf, unsigned int len)

Referenced by xmlCharEncFirstLine().

◆ xmlCharEncInput()

int xmlCharEncInput ( xmlParserInputBufferPtr  input,
int  flush 
)

xmlCharEncInput: @input: a parser input buffer @flush: try to flush all the raw buffer

Generic front-end for the encoding handler on parser input

Returns the number of byte written if success, or -1 general error -2 if the transcoding fails (for *in is not valid utf8 string or the result of transformation can't fit into the encoding we want), or

Definition at line 2288 of file encoding.c.

2289{
2290 int ret;
2291 size_t written;
2292 size_t toconv;
2293 int c_in;
2294 int c_out;
2295 xmlBufPtr in;
2296 xmlBufPtr out;
2297
2298 if ((input == NULL) || (input->encoder == NULL) ||
2299 (input->buffer == NULL) || (input->raw == NULL))
2300 return (-1);
2301 out = input->buffer;
2302 in = input->raw;
2303
2304 toconv = xmlBufUse(in);
2305 if (toconv == 0)
2306 return (0);
2307 if ((toconv > 64 * 1024) && (flush == 0))
2308 toconv = 64 * 1024;
2309 written = xmlBufAvail(out);
2310 if (toconv * 2 >= written) {
2311 xmlBufGrow(out, toconv * 2);
2312 written = xmlBufAvail(out);
2313 }
2314 if ((written > 128 * 1024) && (flush == 0))
2315 written = 128 * 1024;
2316
2317 c_in = toconv;
2318 c_out = written;
2319 ret = xmlEncInputChunk(input->encoder, xmlBufEnd(out), &c_out,
2320 xmlBufContent(in), &c_in, flush);
2321 xmlBufShrink(in, c_in);
2322 xmlBufAddLen(out, c_out);
2323 if (ret == -1)
2324 ret = -3;
2325
2326 switch (ret) {
2327 case 0:
2328#ifdef DEBUG_ENCODING
2330 "converted %d bytes to %d bytes of input\n",
2331 c_in, c_out);
2332#endif
2333 break;
2334 case -1:
2335#ifdef DEBUG_ENCODING
2337 "converted %d bytes to %d bytes of input, %d left\n",
2338 c_in, c_out, (int)xmlBufUse(in));
2339#endif
2340 break;
2341 case -3:
2342#ifdef DEBUG_ENCODING
2344 "converted %d bytes to %d bytes of input, %d left\n",
2345 c_in, c_out, (int)xmlBufUse(in));
2346#endif
2347 break;
2348 case -2: {
2349 char buf[50];
2350 const xmlChar *content = xmlBufContent(in);
2351
2352 snprintf(&buf[0], 49, "0x%02X 0x%02X 0x%02X 0x%02X",
2353 content[0], content[1],
2354 content[2], content[3]);
2355 buf[49] = 0;
2356 xmlEncodingErr(XML_I18N_CONV_FAILED,
2357 "input conversion failed due to input error, bytes %s\n",
2358 buf);
2359 }
2360 }
2361 /*
2362 * Ignore when input buffer is not on a boundary
2363 */
2364 if (ret == -3)
2365 ret = 0;
2366 return (c_out? c_out : ret);
2367}

Referenced by xmlSwitchInputEncodingInt().

◆ xmlCharEncOutput()

int xmlCharEncOutput ( xmlOutputBufferPtr  output,
int  init 
)