XenevaOS
Loading...
Searching...
No Matches
Classes | Macros | Typedefs | Functions
inputstream.h File Reference
#include <stdbool.h>
#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>
#include <parserutils/errors.h>
#include <parserutils/functypes.h>
#include <parserutils/types.h>
#include <parserutils/charset/utf8.h>
#include <parserutils/utils/buffer.h>
Include dependency graph for inputstream.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  parserutils_inputstream
 

Macros

#define IS_ASCII(x)   (((x) & 0x80) == 0)
 

Typedefs

typedef parserutils_error(* parserutils_charset_detect_func) (const uint8_t *data, size_t len, uint16_t *mibenum, uint32_t *source)
 
typedef struct parserutils_inputstream parserutils_inputstream
 

Functions

parserutils_error parserutils_inputstream_create (const char *enc, uint32_t encsrc, parserutils_charset_detect_func csdetect, parserutils_inputstream **stream)
 
parserutils_error parserutils_inputstream_destroy (parserutils_inputstream *stream)
 
parserutils_error parserutils_inputstream_append (parserutils_inputstream *stream, const uint8_t *data, size_t len)
 
parserutils_error parserutils_inputstream_insert (parserutils_inputstream *stream, const uint8_t *data, size_t len)
 
parserutils_error parserutils_inputstream_peek_slow (parserutils_inputstream *stream, size_t offset, const uint8_t **ptr, size_t *length)
 
const char * parserutils_inputstream_read_charset (parserutils_inputstream *stream, uint32_t *source)
 
parserutils_error parserutils_inputstream_change_charset (parserutils_inputstream *stream, const char *enc, uint32_t source)
 

Macro Definition Documentation

◆ IS_ASCII

#define IS_ASCII (   x)    (((x) & 0x80) == 0)

Typedef Documentation

◆ parserutils_charset_detect_func

typedef parserutils_error(* parserutils_charset_detect_func) (const uint8_t *data, size_t len, uint16_t *mibenum, uint32_t *source)

Type of charset detection function

◆ parserutils_inputstream

Input stream object

Function Documentation

◆ parserutils_inputstream_append()

parserutils_error parserutils_inputstream_append ( parserutils_inputstream *  stream,
const uint8_t *  data,
size_t  len 
)

Append data to an input stream

Parameters
streamInput stream to append data to
dataData to append (in document charset), or NULL to flag EOF
lenLength, in bytes, of data
Returns
PARSERUTILS_OK on success, appropriate error otherwise

◆ parserutils_inputstream_change_charset()

parserutils_error parserutils_inputstream_change_charset ( parserutils_inputstream *  stream,
const char *  enc,
uint32_t  source 
)

Change the source charset of the input stream

Parameters
streamInput stream to modify
encCharset name
sourceCharset source identifier
Returns
PARSERUTILS_OK on success, PARSERUTILS_BADPARM on invalid parameters, PARSERUTILS_INVALID if called after data has been read from stream, PARSERUTILS_BADENCODING if the encoding is unsupported, PARSERUTILS_NOMEM on memory exhaustion.

◆ parserutils_inputstream_create()

parserutils_error parserutils_inputstream_create ( const char *  enc,
uint32_t  encsrc,
parserutils_charset_detect_func  csdetect,
parserutils_inputstream **  stream 
)

Create an input stream

Parameters
encDocument charset, or NULL to autodetect
encsrcValue for encoding source, if specified, or 0
csdetectCharset detection function, or NULL
streamPointer to location to receive stream instance
Returns
PARSERUTILS_OK on success, PARSERUTILS_BADPARM on bad parameters, PARSERUTILS_NOMEM on memory exhaustion, PARSERUTILS_BADENCODING on unsupported encoding

The value 0 is defined as being the lowest priority encoding source (i.e. the default fallback encoding). Beyond this, no further interpretation is made upon the encoding source.

◆ parserutils_inputstream_destroy()

parserutils_error parserutils_inputstream_destroy ( parserutils_inputstream *  stream)

Destroy an input stream

Parameters
streamInput stream to destroy
Returns
PARSERUTILS_OK on success, appropriate error otherwise

◆ parserutils_inputstream_insert()

parserutils_error parserutils_inputstream_insert ( parserutils_inputstream *  stream,
const uint8_t *  data,
size_t  len 
)

Insert data into stream at current location

Parameters
streamInput stream to insert into
dataData to insert (UTF-8 encoded)
lenLength, in bytes, of data
Returns
PARSERUTILS_OK on success, appropriate error otherwise

◆ parserutils_inputstream_peek_slow()

parserutils_error parserutils_inputstream_peek_slow ( parserutils_inputstream *  stream,
size_t  offset,
const uint8_t **  ptr,
size_t *  length 
)

Look at the character in the stream that starts at offset bytes from the cursor (slow version)

Parameters
streamStream to look in
offsetByte offset of start of character
ptrPointer to location to receive pointer to character data
lengthPointer to location to receive character length (in bytes)
Returns
PARSERUTILS_OK on success, _NEEDDATA on reaching the end of available input, _EOF on reaching the end of all input, _BADENCODING if the input cannot be decoded, _NOMEM on memory exhaustion, _BADPARM if bad parameters are passed.

Once the character pointed to by the result of this call has been advanced past (i.e. parserutils_inputstream_advance has caused the stream cursor to pass over the character), then no guarantee is made as to the validity of the data pointed to. Thus, any attempt to dereference the pointer after advancing past the data it points to is a bug.

◆ parserutils_inputstream_read_charset()

const char * parserutils_inputstream_read_charset ( parserutils_inputstream *  stream,
uint32_t *  source 
)

Read the source charset of the input stream

Parameters
streamInput stream to query
sourcePointer to location to receive charset source identifier
Returns
Pointer to charset name (constant; do not free)