Mstdlib-1.24.0
|
Typedefs | |
typedef struct M_parser | M_parser_t |
typedef M_bool(* | M_parser_predicate_func) (unsigned char c) |
Enumerations | |
enum | M_PARSER_FLAGS { M_PARSER_FLAG_NONE = 0 , M_PARSER_FLAG_TRACKLINES = 1 << 0 } |
enum | M_PARSER_WHITESPACE_FLAGS { M_PARSER_WHITESPACE_NONE = 0 , M_PARSER_WHITESPACE_TO_NEWLINE = 1 << 0 , M_PARSER_WHITESPACE_SPACEONLY = 1 << 1 } |
enum | M_PARSER_INTEGER_TYPE { M_PARSER_INTEGER_ASCII = 0 , M_PARSER_INTEGER_BIGENDIAN = 1 , M_PARSER_INTEGER_LITTLEENDIAN = 2 } |
enum | M_PARSER_SPLIT_FLAGS { M_PARSER_SPLIT_FLAG_NONE = 0 , M_PARSER_SPLIT_FLAG_NODELIM_ERROR = 1 << 0 , M_PARSER_SPLIT_FLAG_DONT_TRIM_LAST = 1 << 1 } |
enum | M_PARSER_FRAME_BYES { M_PARSER_FRAME_NONE = 0 , M_PARSER_FRAME_STX = 1 << 0 , M_PARSER_FRAME_ETX = 1 << 1 } |
enum | M_PARSER_FRAME_ERROR { M_PARSER_FRAME_ERROR_SUCCESS = 0 , M_PARSER_FRAME_ERROR_INVALID , M_PARSER_FRAME_ERROR_NO_STX , M_PARSER_FRAME_ERROR_NO_ETX , M_PARSER_FRAME_ERROR_NO_LRC , M_PARSER_FRAME_ERROR_LRC_CALC_FAILED } |
Functions | |
M_parser_t * | M_parser_create_const (const unsigned char *buf, size_t len, M_uint32 flags) |
M_parser_t * | M_parser_create (M_uint32 flags) |
void | M_parser_destroy (M_parser_t *parser) |
M_bool | M_parser_append (M_parser_t *parser, const unsigned char *data, size_t len) |
unsigned char * | M_parser_direct_write_start (M_parser_t *parser, size_t *len) |
void | M_parser_direct_write_end (M_parser_t *parser, size_t len) |
size_t | M_parser_len (const M_parser_t *parser) |
size_t | M_parser_current_offset (const M_parser_t *parser) |
size_t | M_parser_current_line (const M_parser_t *parser) |
size_t | M_parser_current_column (const M_parser_t *parser) |
M_bool | M_parser_compare (const M_parser_t *parser, const unsigned char *data, size_t data_len) |
M_bool | M_parser_compare_str (const M_parser_t *parser, const char *str, size_t max_len, M_bool casecmp) |
void | M_parser_mark (M_parser_t *parser) |
void | M_parser_mark_clear (M_parser_t *parser) |
size_t | M_parser_mark_len (const M_parser_t *parser) |
size_t | M_parser_mark_rewind (M_parser_t *parser) |
size_t | M_parser_reset (M_parser_t *parser) |
const unsigned char * | M_parser_peek (const M_parser_t *parser) |
const unsigned char * | M_parser_peek_mark (const M_parser_t *parser, size_t *len) |
M_bool | M_parser_peek_byte (const M_parser_t *parser, unsigned char *byte) |
M_bool | M_parser_peek_bytes (const M_parser_t *parser, size_t len, unsigned char *buf) |
M_bool | M_parser_truncate (M_parser_t *parser, size_t len) |
size_t | M_parser_truncate_whitespace (M_parser_t *parser, M_uint32 flags) |
size_t | M_parser_truncate_until (M_parser_t *parser, const unsigned char *pat, size_t len, M_bool eat_pat) |
size_t | M_parser_truncate_charset (M_parser_t *parser, const unsigned char *charset, size_t charset_len) |
size_t | M_parser_truncate_predicate (M_parser_t *parser, M_parser_predicate_func func) |
size_t | M_parser_truncate_predicate_max (M_parser_t *parser, M_parser_predicate_func func, size_t max) |
size_t | M_parser_truncate_chr_predicate (M_parser_t *parser, M_chr_predicate_func func) |
size_t | M_parser_truncate_chr_predicate_max (M_parser_t *parser, M_chr_predicate_func func, size_t max) |
size_t | M_parser_truncate_str_until (M_parser_t *parser, const char *pat, M_bool eat_pat) |
size_t | M_parser_truncate_str_charset (M_parser_t *parser, const char *charset) |
M_bool | M_parser_consume (M_parser_t *parser, size_t len) |
size_t | M_parser_consume_whitespace (M_parser_t *parser, M_uint32 flags) |
size_t | M_parser_consume_until (M_parser_t *parser, const unsigned char *pat, size_t len, M_bool eat_pat) |
size_t | M_parser_consume_boundary (M_parser_t *parser, const unsigned char *pat, size_t len, M_bool eat_pat, M_bool *found) |
size_t | M_parser_consume_charset (M_parser_t *parser, const unsigned char *charset, size_t charset_len) |
size_t | M_parser_consume_predicate (M_parser_t *parser, M_parser_predicate_func func) |
size_t | M_parser_consume_predicate_max (M_parser_t *parser, M_parser_predicate_func func, size_t max) |
size_t | M_parser_consume_chr_predicate (M_parser_t *parser, M_chr_predicate_func func) |
size_t | M_parser_consume_chr_predicate_max (M_parser_t *parser, M_chr_predicate_func func, size_t max) |
size_t | M_parser_consume_str_until (M_parser_t *parser, const char *pat, M_bool eat_pat) |
size_t | M_parser_consume_str_boundary (M_parser_t *parser, const char *pat, M_bool eat_pat, M_bool *found) |
size_t | M_parser_consume_str_charset (M_parser_t *parser, const char *charset) |
size_t | M_parser_consume_not_charset (M_parser_t *parser, const unsigned char *charset, size_t charset_len) |
size_t | M_parser_consume_str_not_charset (M_parser_t *parser, const char *charset) |
size_t | M_parser_consume_eol (M_parser_t *parser) |
M_bool | M_parser_read_int (M_parser_t *parser, enum M_PARSER_INTEGER_TYPE type, size_t len, unsigned char base, M_int64 *integer) |
M_bool | M_parser_read_uint (M_parser_t *parser, enum M_PARSER_INTEGER_TYPE type, size_t len, unsigned char base, M_uint64 *integer) |
M_bool | M_parser_read_uint_bcd (M_parser_t *parser, size_t len, M_uint64 *integer) |
enum M_DECIMAL_RETVAL | M_parser_read_decimal (M_parser_t *parser, size_t len, M_bool truncate_fail, M_decimal_t *decimal) |
M_bool | M_parser_read_byte (M_parser_t *parser, unsigned char *byte) |
M_bool | M_parser_read_bytes (M_parser_t *parser, size_t len, unsigned char *buf) |
size_t | M_parser_read_bytes_max (M_parser_t *parser, size_t len, unsigned char *buf, size_t buf_len) |
size_t | M_parser_read_bytes_until (M_parser_t *parser, unsigned char *buf, size_t buf_len, const unsigned char *pat, size_t pat_len, M_bool eat_pat) |
size_t | M_parser_read_bytes_boundary (M_parser_t *parser, unsigned char *buf, size_t buf_len, const unsigned char *pat, size_t len, M_bool eat_pat, M_bool *found) |
size_t | M_parser_read_bytes_charset (M_parser_t *parser, const unsigned char *charset, size_t charset_len, unsigned char *buf, size_t buf_len) |
size_t | M_parser_read_bytes_not_charset (M_parser_t *parser, const unsigned char *charset, size_t charset_len, unsigned char *buf, size_t buf_len) |
size_t | M_parser_read_bytes_predicate (M_parser_t *parser, M_parser_predicate_func func, unsigned char *buf, size_t buf_len) |
size_t | M_parser_read_bytes_chr_predicate (M_parser_t *parser, M_chr_predicate_func func, unsigned char *buf, size_t buf_len) |
size_t | M_parser_read_bytes_mark (M_parser_t *parser, unsigned char *buf, size_t buf_len) |
M_bool | M_parser_read_str (M_parser_t *parser, size_t len, char *buf, size_t buf_len) |
size_t | M_parser_read_str_max (M_parser_t *parser, size_t len, char *buf, size_t buf_len) |
size_t | M_parser_read_str_until (M_parser_t *parser, char *buf, size_t buf_len, const char *pat, M_bool eat_pat) |
size_t | M_parser_read_str_boundary (M_parser_t *parser, char *buf, size_t buf_len, const char *pat, M_bool eat_pat, M_bool *found) |
size_t | M_parser_read_str_charset (M_parser_t *parser, const char *charset, char *buf, size_t buf_len) |
size_t | M_parser_read_str_not_charset (M_parser_t *parser, const char *charset, char *buf, size_t buf_len) |
size_t | M_parser_read_str_predicate (M_parser_t *parser, M_parser_predicate_func func, char *buf, size_t buf_len) |
size_t | M_parser_read_str_chr_predicate (M_parser_t *parser, M_chr_predicate_func func, char *buf, size_t buf_len) |
size_t | M_parser_read_str_mark (M_parser_t *parser, char *buf, size_t buf_len) |
char * | M_parser_read_strdup (M_parser_t *parser, size_t len) |
char * | M_parser_read_strdup_hex (M_parser_t *parser, size_t len) |
char * | M_parser_read_strdup_until (M_parser_t *parser, const char *pat, M_bool eat_pat) |
char * | M_parser_read_strdup_boundary (M_parser_t *parser, const char *pat, M_bool eat_pat, M_bool *found) |
char * | M_parser_read_strdup_charset (M_parser_t *parser, const char *charset) |
char * | M_parser_read_strdup_not_charset (M_parser_t *parser, const char *charset) |
char * | M_parser_read_strdup_predicate (M_parser_t *parser, M_parser_predicate_func func) |
char * | M_parser_read_strdup_predicate_max (M_parser_t *parser, M_parser_predicate_func func, size_t max) |
char * | M_parser_read_strdup_chr_predicate (M_parser_t *parser, M_chr_predicate_func func) |
char * | M_parser_read_strdup_chr_predicate_max (M_parser_t *parser, M_chr_predicate_func func, size_t max) |
char * | M_parser_read_strdup_mark (M_parser_t *parser) |
M_bool | M_parser_read_buf (M_parser_t *parser, M_buf_t *buf, size_t len) |
M_bool | M_parser_read_buf_hex (M_parser_t *parser, M_buf_t *buf, size_t len) |
size_t | M_parser_read_buf_max (M_parser_t *parser, M_buf_t *buf, size_t len) |
size_t | M_parser_read_buf_until (M_parser_t *parser, M_buf_t *buf, const unsigned char *pat, size_t pat_len, M_bool eat_pat) |
size_t | M_parser_read_buf_boundary (M_parser_t *parser, M_buf_t *buf, const unsigned char *pat, size_t len, M_bool eat_pat, M_bool *found) |
size_t | M_parser_read_buf_charset (M_parser_t *parser, M_buf_t *buf, const unsigned char *charset, size_t charset_len) |
size_t | M_parser_read_buf_not_charset (M_parser_t *parser, M_buf_t *buf, const unsigned char *charset, size_t charset_len) |
size_t | M_parser_read_buf_predicate (M_parser_t *parser, M_buf_t *buf, M_parser_predicate_func func) |
size_t | M_parser_read_buf_predicate_max (M_parser_t *parser, M_buf_t *buf, M_parser_predicate_func func, size_t max) |
size_t | M_parser_read_buf_chr_predicate (M_parser_t *parser, M_buf_t *buf, M_chr_predicate_func func) |
size_t | M_parser_read_buf_chr_predicate_max (M_parser_t *parser, M_buf_t *buf, M_chr_predicate_func func, size_t max) |
size_t | M_parser_read_buf_mark (M_parser_t *parser, M_buf_t *buf) |
M_parser_t * | M_parser_read_parser (M_parser_t *parser, size_t len) |
M_parser_t * | M_parser_read_parser_until (M_parser_t *parser, const unsigned char *pat, size_t len, M_bool eat_pat) |
M_parser_t * | M_parser_read_parser_boundary (M_parser_t *parser, const unsigned char *pat, size_t len, M_bool eat_pat, M_bool *found) |
M_parser_t * | M_parser_read_parser_charset (M_parser_t *parser, unsigned const char *charset, size_t charset_len) |
M_parser_t * | M_parser_read_parser_predicate (M_parser_t *parser, M_parser_predicate_func func) |
M_parser_t * | M_parser_read_parser_predicate_max (M_parser_t *parser, M_parser_predicate_func func, size_t max) |
M_parser_t * | M_parser_read_parser_chr_predicate (M_parser_t *parser, M_parser_predicate_func func) |
M_parser_t * | M_parser_read_parser_chr_predicate_max (M_parser_t *parser, M_parser_predicate_func func, size_t max) |
M_parser_t * | M_parser_read_parser_mark (M_parser_t *parser) |
M_PARSER_FRAME_ERROR | M_parser_read_stxetxlrc_message (M_parser_t *parser, M_parser_t **out, M_uint32 lrc_frame_chars) |
M_bool | M_parser_is_predicate (const M_parser_t *parser, size_t len, M_parser_predicate_func func) |
M_bool | M_parser_is_chr_predicate (const M_parser_t *parser, size_t len, M_chr_predicate_func func) |
M_bool | M_parser_is_charset (const M_parser_t *parser, size_t len, const unsigned char *charset, size_t charset_len) |
M_bool | M_parser_is_str_charset (const M_parser_t *parser, size_t len, const char *charset) |
M_bool | M_parser_is_not_predicate (const M_parser_t *parser, size_t len, M_parser_predicate_func func) |
M_bool | M_parser_is_not_chr_predicate (const M_parser_t *parser, size_t len, M_chr_predicate_func func) |
M_bool | M_parser_is_not_charset (const M_parser_t *parser, size_t len, const unsigned char *charset, size_t charset_len) |
M_bool | M_parser_is_not_str_charset (const M_parser_t *parser, size_t len, const char *charset) |
M_parser_t ** | M_parser_split (M_parser_t *parser, unsigned char delim, size_t maxcnt, M_uint32 flags, size_t *num_output) |
M_parser_t ** | M_parser_split_pat (M_parser_t *parser, const unsigned char *pat, size_t pat_len, size_t maxcnt, M_uint32 flags, size_t *num_output) |
M_parser_t ** | M_parser_split_str_pat (M_parser_t *parser, const char *pat, size_t maxcnt, M_uint32 flags, size_t *num_output) |
void | M_parser_split_free (M_parser_t **parsers, size_t cnt) |
Buffer based data parser.
Efficient parser that prevents reading past the end of the data buffer. Has helpers for reading specific types from the buffer (auto conversion). Also supports line and column tracking.
typedef struct M_parser M_parser_t |
typedef M_bool(* M_parser_predicate_func) (unsigned char c) |
enum M_PARSER_FLAGS |
enum M_PARSER_SPLIT_FLAGS |
Splitting flags.
enum M_PARSER_FRAME_BYES |
enum M_PARSER_FRAME_ERROR |
STX, ETX, LRC unwrapping responses.
M_parser_t * M_parser_create_const | ( | const unsigned char * | buf, |
size_t | len, | ||
M_uint32 | flags | ||
) |
Initialize a parser object using const data.
The object is initialized with constant data which cannot be appended to. Memory is not duplicated and therefore the memory for the buffer pointed to must exist for the life of the parser. The parser will not clean up the memory for the referenced object.
[in] | buf | Data to parse, must not be NULL. |
[in] | len | Length of data to be parsed. |
[in] | flags | Any of the enum M_PARSER_FLAGS bitwise OR'd together. |
M_parser_t * M_parser_create | ( | M_uint32 | flags | ) |
Initialize an empty parser object.
Its initial state is empty and data must be appended to it before any data can be parsed.
IMPLEMENTATION NOTE: For efficiency, data which is parsed will be purged from memory when additional internal buffer space is required during an append operation. This is to reclaim space and reduce the number of allocations required when parsing stream-based data.
void M_parser_destroy | ( | M_parser_t * | parser | ) |
Destroy the parser object.
[in] | parser | Parser object. |
M_bool M_parser_append | ( | M_parser_t * | parser, |
const unsigned char * | data, | ||
size_t | len | ||
) |
Append data to a parser object.
The parser object must have been initialized with M_parser_create(). This will append the data to the internal buffer extending the available length of data to parse.
[in,out] | parser | Parser object, but not be a const object. |
[in] | data | Data to append. |
[in] | len | Length of data to append. |
unsigned char * M_parser_direct_write_start | ( | M_parser_t * | parser, |
size_t * | len | ||
) |
Begin a direct write operation. In general, this function should not be used, it is meant as an optimization to prevent double buffering when reading I/O. A writable buffer will be returned of at least the length requested, often it will be much larger. To end the direct write process, M_parser_direct_write_end() must be called with the length actually written. It is not valid to call any other M_parser_*() functions between start and end.
[in,out] | parser | Parser object, but not be a const object |
[in,out] | len | Pass in the minimum requested buffer size, outputs the maximum writable buffer size. |
void M_parser_direct_write_end | ( | M_parser_t * | parser, |
size_t | len | ||
) |
End a direct write operation. Please see M_parser_direct_write_start() for more information. This terminates a direct write sequence regardless of if data was written or not (len = 0 is acceptable).
[in,out] | parser | Parser object, but not a const object |
[in] | len | Length of data written. |
size_t M_parser_len | ( | const M_parser_t * | parser | ) |
Retrieve the length of data remaining in the buffer being parsed.
[in] | parser | Parser object. |
size_t M_parser_current_offset | ( | const M_parser_t * | parser | ) |
Retrieve the total number of bytes processed so far.
parser | Parser object. |
size_t M_parser_current_line | ( | const M_parser_t * | parser | ) |
Retrieves the current line number.
Line numbers are determined based on how many \n's have been evaluated in the data stream. This can only be called if M_PARSER_FLAG_TRACKLINES was used during initialization of the parser.
[in] | parser | parser object. |
size_t M_parser_current_column | ( | const M_parser_t * | parser | ) |
Retrieves the current column for the current line.
The column count resets each time a \n is passed. This can only be called if M_PARSER_FLAG_TRACKLINES was used during initialization of the parser.
parser | Parser object. |
M_bool M_parser_compare | ( | const M_parser_t * | parser, |
const unsigned char * | data, | ||
size_t | data_len | ||
) |
Compare parser contents to provided buffer
Does not advance.
[in] | parser | Parser object. |
[in] | data | Data to compare. |
[in] | data_len | Length of data to compare |
M_bool M_parser_compare_str | ( | const M_parser_t * | parser, |
const char * | str, | ||
size_t | max_len, | ||
M_bool | casecmp | ||
) |
Compare parser contents to provided string.
Does not advance.
[in] | parser | Parser object. |
[in] | str | String data to compare. |
[in] | max_len | Maximum length of data to compare, 0 for entire string. If 0 is specified, then also the entire parser buffer must be an exact match. If there are extra bytes after the match, this will not be considered an exact match. |
[in] | casecmp | Perform case-insensitive comparison? |
void M_parser_mark | ( | M_parser_t * | parser | ) |
Marks the current position for future reference in case additional data might need to be pulled from this marked point forward.
If a data position is marked, it will not be eligible to be destroyed/chopped until the marked position is cleared.
[in,out] | parser | Parser object. |
void M_parser_mark_clear | ( | M_parser_t * | parser | ) |
Clears the current marked position, allowing it to be garbage collected.
[in,out] | parser | Parser object. |
size_t M_parser_mark_len | ( | const M_parser_t * | parser | ) |
Obtain the length of the marked position to the current position.
[in] | parser | Parser object. |
size_t M_parser_mark_rewind | ( | M_parser_t * | parser | ) |
Rewind data back to the marked position.
This will automaticaly clear the marked position so if the marked position is still needed, the caller must re-mark it.
[in,out] | parser | Parser object. |
size_t M_parser_reset | ( | M_parser_t * | parser | ) |
Reset set the parser back to the beginning of the data.
This is only applicable to 'const' parsers, and will fail on dynamic parsers. If this scans back past a marked position, the mark will be automatically cleared.
[in,out] | parser | Parser object. |
const unsigned char * M_parser_peek | ( | const M_parser_t * | parser | ) |
Retrieve the internal pointer for the current position in the parse buffer.
[in] | parser | Parser object. |
const unsigned char * M_parser_peek_mark | ( | const M_parser_t * | parser, |
size_t * | len | ||
) |
Retrieve the internal pointer for the marked position in the parse buffer.
[in] | parser | Parser object. |
[out] | len | Length of marked data. |
M_bool M_parser_peek_byte | ( | const M_parser_t * | parser, |
unsigned char * | byte | ||
) |
Read a single byte from the current buffer without advancing.
[in] | parser | Parser object. |
[out] | byte | Outputs byte read. |
M_bool M_parser_peek_bytes | ( | const M_parser_t * | parser, |
size_t | len, | ||
unsigned char * | buf | ||
) |
Read bytes (binary) from the current buffer and output in the user-provided buffer without advancing.
The data read will not be NULL terminated and the buffer provided must be at least as large as large as the requested data.
[in] | parser | Parser object. |
[in] | len | Length of data to read. |
[in,out] | buf | Buffer to hold output. |
M_bool M_parser_truncate | ( | M_parser_t * | parser, |
size_t | len | ||
) |
Truncate the parse buffer at the position specified (relative to the current parse offset).
[in,out] | parser | Parser object. |
[in] | len | Length to truncate to. |
size_t M_parser_truncate_whitespace | ( | M_parser_t * | parser, |
M_uint32 | flags | ||
) |
Truncate all available whitespace.
Searches backwards from end to start.
[in,out] | parser | Parser object. |
[in] | flags | A bitmap of enum M_PARSER_WHITESPACE_FLAGS. |
size_t M_parser_truncate_until | ( | M_parser_t * | parser, |
const unsigned char * | pat, | ||
size_t | len, | ||
M_bool | eat_pat | ||
) |
Truncate all bytes until the specified sequence of bytes is encountered in the data stream.
Searches backwards from end to start.
[in,out] | parser | Parser object. |
[in] | pat | Sequence of bytes to search for. |
[in] | len | Length of pattern data. |
[in] | eat_pat | Should the sequence of bytes be consumed. Useful for ignoring data until end of comment. |
size_t M_parser_truncate_charset | ( | M_parser_t * | parser, |
const unsigned char * | charset, | ||
size_t | charset_len | ||
) |
Truncate all bytes matching the given charset.
Searches backwards from end to start.
[in,out] | parser | Parser object. |
[in] | charset | Character set. |
[in] | charset_len | Length of given character set. |
size_t M_parser_truncate_predicate | ( | M_parser_t * | parser, |
M_parser_predicate_func | func | ||
) |
Truncate all bytes matching the given predicate function.
Searches backwards from end to start.
[in,out] | parser | Parser object. |
[in] | func | Predicate function. |
size_t M_parser_truncate_predicate_max | ( | M_parser_t * | parser, |
M_parser_predicate_func | func, | ||
size_t | max | ||
) |
Truncate all bytes matching the given predicate function up to a given maximum.
Searches backwards from end to start.
[in,out] | parser | Parser object. |
[in] | func | Predicate function. |
[in] | max | Requested length of data to read. |
size_t M_parser_truncate_chr_predicate | ( | M_parser_t * | parser, |
M_chr_predicate_func | func | ||
) |
Truncate all bytes matching the given chr predicate function.
Searches backwards from end to start.
[in,out] | parser | Parser object. |
[in] | func | Predicate function. |
size_t M_parser_truncate_chr_predicate_max | ( | M_parser_t * | parser, |
M_chr_predicate_func | func, | ||
size_t | max | ||
) |
Truncate all bytes matching the given chr predicate function up to a given maximum.
Searches backwards from end to start.
[in,out] | parser | Parser object. |
[in] | func | Predicate function. |
[in] | max | Requested length of data to read. |
size_t M_parser_truncate_str_until | ( | M_parser_t * | parser, |
const char * | pat, | ||
M_bool | eat_pat | ||
) |
Truncate all bytes until the specified string is encountered in the data stream.
Searches backwards from end to start.
[in,out] | parser | Parser object. |
[in] | pat | String to search for. |
[in] | eat_pat | Should the sequence of bytes be consumed. Useful for ignoring data until end of comment. |
size_t M_parser_truncate_str_charset | ( | M_parser_t * | parser, |
const char * | charset | ||
) |
Truncate all bytes matching the given NULL-terminated charset.
Searches backwards from end to start.
[in,out] | parser | Parser object. |
[in] | charset | Character set, NULL-terminated. |
M_bool M_parser_consume | ( | M_parser_t * | parser, |
size_t | len | ||
) |
Consume the given number of bytes.
[in,out] | parser | Parser object. |
[in] | len | Number of bytes to consume. |
size_t M_parser_consume_whitespace | ( | M_parser_t * | parser, |
M_uint32 | flags | ||
) |
Consume all available whitespace.
[in,out] | parser | Parser object. |
[in] | flags | A bitmap of enum M_PARSER_WHITESPACE_FLAGS. |
size_t M_parser_consume_until | ( | M_parser_t * | parser, |
const unsigned char * | pat, | ||
size_t | len, | ||
M_bool | eat_pat | ||
) |
Consume all bytes until the specified sequence of bytes is encountered in the data stream.
[in,out] | parser | Parser object. |
[in] | pat | Sequence of bytes to search for. |
[in] | len | Length of pattern data. |
[in] | eat_pat | Should the sequence of bytes be consumed. Useful for ignoring data until end of comment. |
size_t M_parser_consume_boundary | ( | M_parser_t * | parser, |
const unsigned char * | pat, | ||
size_t | len, | ||
M_bool | eat_pat, | ||
M_bool * | found | ||
) |
Consume all bytes before a pat.
Will stop if parser ends with a partially matching pat. Will only eat the pattern if a full pat is found.
Will stop consuming if a partial match of the pat is found. E.g. parser = "ABC1234" pat = "12345". Will consume "ABC" leaving "12345". If more data is added and and parser = "123461234". Will consume "12346". If more data is added and and parser = "1234612345" Will consume everything is eat_path is M_TRUE. Otherwise, "12346".
[in,out] | parser | Parser object. |
[in] | pat | Sequence of bytes to search for. |
[in] | len | Length of pattern data. |
[in] | eat_pat | Should the sequence of bytes be consumed. Useful for ignoring data until end of comment. |
[out] | found | Was the full pat found. A partial boundy might still be in the parser if M_FALSE. |
size_t M_parser_consume_charset | ( | M_parser_t * | parser, |
const unsigned char * | charset, | ||
size_t | charset_len | ||
) |
Consume all bytes matching the given charset.
[in,out] | parser | Parser object. |
[in] | charset | Character set. |
[in] | charset_len | Length of given character set. |
size_t M_parser_consume_predicate | ( | M_parser_t * | parser, |
M_parser_predicate_func | func | ||
) |
Consume all bytes matching the given predicate function.
[in,out] | parser | Parser object. |
[in] | func | Predicate function. |
size_t M_parser_consume_predicate_max | ( | M_parser_t * | parser, |
M_parser_predicate_func | func, | ||
size_t | max | ||
) |
Consume all bytes matching the given predicate function up to a given maximum.
[in,out] | parser | Parser object. |
[in] | func | Predicate function. |
[in] | max | Requested length of data to read. |
size_t M_parser_consume_chr_predicate | ( | M_parser_t * | parser, |
M_chr_predicate_func | func | ||
) |
Consume all bytes matching the given chr predicate function.
[in,out] | parser | Parser object. |
[in] | func | Predicate function. |
size_t M_parser_consume_chr_predicate_max | ( | M_parser_t * | parser, |
M_chr_predicate_func | func, | ||
size_t | max | ||
) |
Consume all bytes matching the given chr predicate function up to a given maximum.
[in,out] | parser | Parser object. |
[in] | func | Predicate function. |
[in] | max | Requested length of data to read. |
size_t M_parser_consume_str_until | ( | M_parser_t * | parser, |
const char * | pat, | ||
M_bool | eat_pat | ||
) |
Consume all bytes until the specified string is encountered in the data stream.
[in,out] | parser | Parser object. |
[in] | pat | String to search for. |
[in] | eat_pat | Should the sequence of bytes be consumed. Useful for ignoring data until end of comment. |
size_t M_parser_consume_str_boundary | ( | M_parser_t * | parser, |
const char * | pat, | ||
M_bool | eat_pat, | ||
M_bool * | found | ||
) |
Consume all bytes before a pat.
Will stop if parser ends with a partially matching pat. Will only eat the pattern if a full pat is found.
Will stop consuming if a partial match of the pat is found. E.g. parser = "ABC1234" pat = "12345". Will consume "ABC" leaving "12345". If more data is added and and parser = "123461234". Will consume "12346". If more data is added and and parser = "1234612345" Will consume everything is eat_path is M_TRUE. Otherwise, "12346".
[in,out] | parser | Parser object. |
[in] | pat | String to search for. |
[in] | eat_pat | Should the sequence of bytes be consumed. Useful for ignoring data until end of comment. |
[out] | found | Was the full pat found. A partial boundy might still be in the parser if M_FALSE. |
size_t M_parser_consume_str_charset | ( | M_parser_t * | parser, |
const char * | charset | ||
) |
Consume all bytes matching the given NULL-terminated charset.
[in,out] | parser | Parser object. |
[in] | charset | Character set, NULL-terminated. |
size_t M_parser_consume_not_charset | ( | M_parser_t * | parser, |
const unsigned char * | charset, | ||
size_t | charset_len | ||
) |
Consume all bytes not matching the given charset.
[in,out] | parser | Parser object. |
[in] | charset | Character set, NULL-terminated. |
[in] | charset_len | Length of given character set. |
size_t M_parser_consume_str_not_charset | ( | M_parser_t * | parser, |
const char * | charset | ||
) |
Consume all bytes not matching the given NULL-terminated charset.
[in,out] | parser | Parser object. |
[in] | charset | Character set, NULL-terminated. |
size_t M_parser_consume_eol | ( | M_parser_t * | parser | ) |
Consume all bytes until and including the next end of line.
Useful for ignoring data until end of single-line comment. If there is no new line, will consume all remaining data.
[in,out] | parser | Parser object. |
M_bool M_parser_read_int | ( | M_parser_t * | parser, |
enum M_PARSER_INTEGER_TYPE | type, | ||
size_t | len, | ||
unsigned char | base, | ||
M_int64 * | integer | ||
) |
Read a signed integer from the current buffer and advance.
For ASCII formatted integers:
For BigEndian or Little Endian formatted integers:
[in,out] | parser | Parser object. |
[in] | type | How integer is represented in the data stream. |
[in] | len | Length of integer, or 0 to auto-determine for ASCII. |
[in] | base | Base represented in ASCII, or 0 to auto-determine (or non-ascii). |
[out] | integer | Integer storage. |
M_bool M_parser_read_uint | ( | M_parser_t * | parser, |
enum M_PARSER_INTEGER_TYPE | type, | ||
size_t | len, | ||
unsigned char | base, | ||
M_uint64 * | integer | ||
) |
Read an unsigned integer from the current buffer and advance.
See M_parser_read_int() for details on usage as requirements are the same.
[in,out] | parser | Parser object. |
[in] | type | How integer is represented in the data stream. |
[in] | len | Length of integer, or 0 to auto-determine for ASCII. |
[in] | base | Base represented in ASCII, or 0 to auto-determine (or non-ascii). |
[out] | integer | Integer storage. |
M_bool M_parser_read_uint_bcd | ( | M_parser_t * | parser, |
size_t | len, | ||
M_uint64 * | integer | ||
) |
Read and unsigned Binary Coded Decimal integer from the current buffer and advance
[in,out] | parser | Parser object. |
[in] | len | Length of integer in bytes. |
[out] | integer | Integer storage. |
enum M_DECIMAL_RETVAL M_parser_read_decimal | ( | M_parser_t * | parser, |
size_t | len, | ||
M_bool | truncate_fail, | ||
M_decimal_t * | decimal | ||
) |
Read a decimal number from current buffer and advance.
The number must be represented in base 10 and in ASCII form.
[in,out] | parser | Parser object. |
[in] | len | Length of decimal, or 0 to auto-determine. |
[in] | truncate_fail | M_TRUE to treat a truncation as a failure and not increment the consumer. M_FALSE otherwise. |
[out] | decimal | Decimal storage. |
M_bool M_parser_read_byte | ( | M_parser_t * | parser, |
unsigned char * | byte | ||
) |
Read a single byte from the current buffer and advance.
[in,out] | parser | Parser object. |
[out] | byte | Outputs byte read. |
M_bool M_parser_read_bytes | ( | M_parser_t * | parser, |
size_t | len, | ||
unsigned char * | buf | ||
) |
Read the exact number of bytes (binary) from the current buffer and output in the user-provided buffer and advance. If there are fewer than the requested bytes available, an error will be returned.
The data read will not be NULL terminated and the buffer provided must be at least as large as as the requested data.
[in,out] | parser | Parser object. |
[in] | len | Length of data to read. |
[out] | buf | Buffer to hold output. |
size_t M_parser_read_bytes_max | ( | M_parser_t * | parser, |
size_t | len, | ||
unsigned char * | buf, | ||
size_t | buf_len | ||
) |
Read bytes (binary) from the current buffer and output in the user-provided buffer and advance.
The data read will not be NULL terminated and the buffer provided must be at least as large as large as the requested data. If the length of data specified is not available, it will return the number of bytes actually read.
[in,out] | parser | Parser object. |
[in] | len | Requested length of data to read. |
[out] | buf | Buffer to hold output. |
[in] | buf_len | Length of buffer to hold output. |
size_t M_parser_read_bytes_until | ( | M_parser_t * | parser, |
unsigned char * | buf, | ||
size_t | buf_len, | ||
const unsigned char * | pat, | ||
size_t | pat_len, | ||
M_bool | eat_pat | ||
) |
Read bytes (binary) until the specified sequence of bytes is encountered in the data stream.
[in,out] | parser | Parser object. |
[out] | buf | Buffer to hold output. |
[in] | buf_len | Length of buffer to hold output. |
[in] | pat | Sequence of bytes to search for. |
[in] | pat_len | Length of pattern data. |
[in] | eat_pat | Should the sequence of bytes be consumed. Useful for ignoring data until end of comment. |
size_t M_parser_read_bytes_boundary | ( | M_parser_t * | parser, |
unsigned char * | buf, | ||
size_t | buf_len, | ||
const unsigned char * | pat, | ||
size_t | len, | ||
M_bool | eat_pat, | ||
M_bool * | found | ||
) |
Read bytes (binary) until the specified pat is encountered in the data stream.
The data read will not be NULL terminated.
Will stop if parser ends with a partially matching pat. Will only eat the pattern if a full pat is found.
[in,out] | parser | Parser object. |
[out] | buf | Buffer to hold output. |
[in] | buf_len | Length of buffer to hold output. |
[in] | pat | Sequence of bytes to search for. |
[in] | len | Length of pattern data. |
[in] | eat_pat | Should the sequence of bytes be consumed. Useful for ignoring data until end of comment. |
[out] | found | Was the full pat found. A partial boundy might still be in the parser if M_FALSE. |
size_t M_parser_read_bytes_charset | ( | M_parser_t * | parser, |
const unsigned char * | charset, | ||
size_t | charset_len, | ||
unsigned char * | buf, | ||
size_t | buf_len | ||
) |
Read bytes (binary) from the current buffer as long as the bytes match the provided character set, output in the user-provided buffer and advance.
The data read will not be NULL terminated.
[in,out] | parser | Parser object. |
[in] | charset | Array of characters that are allowed. |
[in] | charset_len | Length of character set. |
[out] | buf | Buffer to store result. |
[in] | buf_len | Size of result buffer. |
size_t M_parser_read_bytes_not_charset | ( | M_parser_t * | parser, |
const unsigned char * | charset, | ||
size_t | charset_len, | ||
unsigned char * | buf, | ||
size_t | buf_len | ||
) |
Read bytes (binary) from the current buffer as long as the bytes do not match the provided character set, output in the user-provided buffer and advance.
The data read will not be NULL terminated.
[in,out] | parser | Parser object. |
[in] | charset | Array of characters that are allowed. |
[in] | charset_len | Length of character set. |
[out] | buf | Buffer to store result. |
[in] | buf_len | Size of result buffer. |
size_t M_parser_read_bytes_predicate | ( | M_parser_t * | parser, |
M_parser_predicate_func | func, | ||
unsigned char * | buf, | ||
size_t | buf_len | ||
) |
Read bytes (binary) from the current buffer as long as the bytes match the provided predicate, output in the user-provided buffer and advance.
The data read will not be NULL terminated.
[in,out] | parser | Parser object. |
[in] | func | Predicate function. |
[out] | buf | Buffer to store result. |
[in] | buf_len | Size of result buffer. |
size_t M_parser_read_bytes_chr_predicate | ( | M_parser_t * | parser, |
M_chr_predicate_func | func, | ||
unsigned char * | buf, | ||
size_t | buf_len | ||
) |
Read bytes (binary) from the current buffer as long as the bytes match the provided chr predicate, output in the user-provided buffer and advance.
The data read will not be NULL terminated.
[in,out] | parser | Parser object. |
[in] | func | Predicate function. |
[out] | buf | Buffer to store result. |
[in] | buf_len | Size of result buffer. |
size_t M_parser_read_bytes_mark | ( | M_parser_t * | parser, |
unsigned char * | buf, | ||
size_t | buf_len | ||
) |
Read data from a marked position until the current parser position.
The marked position will be automatically cleared. Provided buffer must be at least M_parser_mark_len() bytes long.
[in,out] | parser | Parser object. |
[out] | buf | Buffer to store result. |
[in] | buf_len | Size of result buffer. |
M_bool M_parser_read_str | ( | M_parser_t * | parser, |
size_t | len, | ||
char * | buf, | ||
size_t | buf_len | ||
) |
Read a string from the current buffer of the exact given length, output in the user-provided buffer and advance. If there are insufficient bytes a failure will be returned.
The length of the requested string must be at least one byte shorter than the buffer size to account for the null termination. If you do not already have a buffer, use M_parser_read_strdup() which will return a newly allocated buffer for you.
[in,out] | parser | Parser object. |
[in] | len | Length of string to read (must be at least one byte shorter than buf_len). |
[out] | buf | Output pointer to store result. |
[in] | buf_len | Length of output buffer (must be at least one byte greater than len). |
size_t M_parser_read_str_max | ( | M_parser_t * | parser, |
size_t | len, | ||
char * | buf, | ||
size_t | buf_len | ||
) |
Read a string from the current buffer, output in the user-provided buffer and advance.
The length of the requested string must be at least one byte shorter than the buffer size to account for the null termination. If you do not already have a buffer, use M_parser_read_strdup() which will return a newly allocated buffer for you.
[in,out] | parser | Parser object. |
[in] | len | Requested length of string to read (must be at least one byte shorter than buf_len). |
[out] | buf | Output pointer to store result. |
[in] | buf_len | Length of output buffer (must be at least one byte greater than len). |
size_t M_parser_read_str_until | ( | M_parser_t * | parser, |
char * | buf, | ||
size_t | buf_len, | ||
const char * | pat, | ||
M_bool | eat_pat | ||
) |
Read data until the specified sequence of bytes is encountered in the data stream.
[in,out] | parser | Parser object. |
[out] | buf | Buffer to hold output. |
[in] | buf_len | Length of buffer to hold output. |
[in] | pat | String to search for. |
[in] | eat_pat | Should the sequence of bytes be consumed. Useful for ignoring data until end of comment. |
size_t M_parser_read_str_boundary | ( | M_parser_t * | parser, |
char * | buf, | ||
size_t | buf_len, | ||
const char * | pat, | ||
M_bool | eat_pat, | ||
M_bool * | found | ||
) |
Read data until the specified pat is encountered in the data stream.
Will stop if parser ends with a partially matching pat. Will only eat the pattern if a full pat is found.
[in,out] | parser | Parser object. |
[out] | buf | Buffer to hold output. |
[in] | buf_len | Length of buffer to hold output. |
[in] | pat | String to search for. |
[in] | eat_pat | Should the sequence of bytes be consumed. Useful for ignoring data until end of comment. |
[out] | found | Was the full pat found. A partial boundy might still be in the parser if M_FALSE. |
size_t M_parser_read_str_charset | ( | M_parser_t * | parser, |
const char * | charset, | ||
char * | buf, | ||
size_t | buf_len | ||
) |
Read data from the buffer for as long as it matches one of the bytes in the given character set and advance.
Put the resulting bytes in the provided buffer.
[in,out] | parser | Parser object. |
[in] | charset | Array of characters that are allowed, NULL terminated. |
[out] | buf | Buffer to store result. Will be NULL terminated. |
[in] | buf_len | Size of result buffer. |
size_t M_parser_read_str_not_charset | ( | M_parser_t * | parser, |
const char * | charset, | ||
char * | buf, | ||
size_t | buf_len | ||
) |
Read data from the buffer for as long as it does not match one of the bytes in the given character set and advance.
Put the resulting bytes in the provided buffer.
[in,out] | parser | Parser object. |
[in] | charset | Array of characters that are allowed, NULL terminated. |
[out] | buf | Buffer to store result. Will be NULL terminated. |
[in] | buf_len | Size of result buffer. |
size_t M_parser_read_str_predicate | ( | M_parser_t * | parser, |
M_parser_predicate_func | func, | ||
char * | buf, | ||
size_t | buf_len | ||
) |
Read data from the buffer for as long as it matches the given predicate function and advance.
Put the resulting bytes in the provided buffer.
[in,out] | parser | Parser object. |
[in] | func | predicate function. |
[out] | buf | Buffer to store result. Will be NULL terminated. |
[in] | buf_len | Size of result buffer. |
size_t M_parser_read_str_chr_predicate | ( | M_parser_t * | parser, |
M_chr_predicate_func | func, | ||
char * | buf, | ||
size_t | buf_len | ||
) |
Read data from the buffer for as long as it matches the given chr predicate function and advance.
Put the resulting bytes in the provided buffer.
[in,out] | parser | Parser object. |
[in] | func | predicate function. |
[out] | buf | Buffer to store result. Will be NULL terminated. |
[in] | buf_len | Size of result buffer. |
size_t M_parser_read_str_mark | ( | M_parser_t * | parser, |
char * | buf, | ||
size_t | buf_len | ||
) |
Read data from a marked position until the current parser position.
The marked position will be automatically cleared. Provided buffer must be at least M_parser_mark_len() bytes plus the NULL terminator.
[in,out] | parser | Parser object. |
[out] | buf | Buffer to store result. |
[in] | buf_len | Size of result buffer. |
char * M_parser_read_strdup | ( | M_parser_t * | parser, |
size_t | len | ||
) |
Read a string for the given length from the current buffer, allocates an output buffer and advance.
[in,out] | parser | Parser object. |
[in] | len | Length of string to read. |
char * M_parser_read_strdup_hex | ( | M_parser_t * | parser, |
size_t | len | ||
) |
Read bytes (binary) from the parser, return as hex-encoded string and advance.
[in,out] | parser | Parser object to read binary bytes from. |
[in] | len | Number of binary bytes to read from parser. |
char * M_parser_read_strdup_until | ( | M_parser_t * | parser, |
const char * | pat, | ||
M_bool | eat_pat | ||
) |
Read data until the specified sequence of bytes is encountered in the data stream.
Put the resulting bytes in a newly allocated buffer.
[in,out] | parser | Parser object. |
[in] | pat | Sequence of bytes to search for. |
[in] | eat_pat | Should the sequence of bytes be consumed. Useful for ignoring data until end of comment. |
char * M_parser_read_strdup_boundary | ( | M_parser_t * | parser, |
const char * | pat, | ||
M_bool | eat_pat, | ||
M_bool * | found | ||
) |
Read data until the specified pat is encountered in the data stream.
Will stop if parser ends with a partially matching pat. Will only eat the pattern if a full pat is found.
Put the resulting bytes in a newly allocated buffer.
[in,out] | parser | Parser object. |
[in] | pat | String to search for. |
[in] | eat_pat | Should the sequence of bytes be consumed. Useful for ignoring data until end of comment. |
[out] | found | Was the full pat found. A partial boundy might still be in the parser if M_FALSE. |
char * M_parser_read_strdup_charset | ( | M_parser_t * | parser, |
const char * | charset | ||
) |
Read data from the buffer for as long as it matches one of the bytes in the given character set and advance.
Put the resulting bytes in a newly allocated buffer.
[in,out] | parser | Parser object. |
[in] | charset | Array of characters that are allowed, NULL terminated. |
char * M_parser_read_strdup_not_charset | ( | M_parser_t * | parser, |
const char * | charset | ||
) |
Read data from the buffer for as long as it does not match one of the bytes in the given character set and advance.
Put the resulting bytes in a newly allocated buffer.
[in,out] | parser | Parser object. |
[in] | charset | Array of characters that are allowed, NULL terminated. |
char * M_parser_read_strdup_predicate | ( | M_parser_t * | parser, |
M_parser_predicate_func | func | ||
) |
Read data from the buffer for as long as it matches the given predicate function and advance.
Put the resulting bytes in a newly allocated buffer.
[in,out] | parser | Parser object. |
[in] | func | Predicate function. |
char * M_parser_read_strdup_predicate_max | ( | M_parser_t * | parser, |
M_parser_predicate_func | func, | ||
size_t | max | ||
) |
Read data from the buffer for as long as it matches the given predicate function up to a given maximum and advance.
Put the resulting bytes in a newly allocated buffer.
[in,out] | parser | Parser object. |
[in] | func | Predicate function. |
[in] | max | Requested length of data to read. |
char * M_parser_read_strdup_chr_predicate | ( | M_parser_t * | parser, |
M_chr_predicate_func | func | ||
) |
Read data from the buffer for as long as it matches the given predicate function and advance.
Put the resulting bytes in a newly allocated buffer.
[in,out] | parser | Parser object. |
[in] | func | predicate function. |
char * M_parser_read_strdup_chr_predicate_max | ( | M_parser_t * | parser, |
M_chr_predicate_func | func, | ||
size_t | max | ||
) |
Read data from the buffer for as long as it matches the given predicate function up to a given maximum and advance.
Put the resulting bytes in a newly allocated buffer.
[in,out] | parser | Parser object. |
[in] | func | predicate function. |
[in] | max | Requested length of data to read. |
char * M_parser_read_strdup_mark | ( | M_parser_t * | parser | ) |
Read data from a marked position until the current parser position.
The marked position will be automatically cleared. An allocated buffer with the requested data will be returned, NULL terminated.
[in,out] | parser | Parser object. |
M_bool M_parser_read_buf | ( | M_parser_t * | parser, |
M_buf_t * | buf, | ||
size_t | len | ||
) |
Read the exact number of bytes (binary) from the current buffer and output in the user-provided buffer and advance.
If there are fewer than the requested bytes available, an error will be returned.
The data read will not be NULL terminated.
[in,out] | parser | Parser object. |
[out] | buf | Buffer to hold output. |
[in] | len | Length of data to read. |
M_bool M_parser_read_buf_hex | ( | M_parser_t * | parser, |
M_buf_t * | buf, | ||
size_t | len | ||
) |
Read bytes (binary) from the parser, write as hex-encoded string into the provided buffer, and advance.
[in,out] | parser | Parser object to read binary bytes from. |
[out] | buf | Buffer to hold hex-ascii output. |
[in] | len | Number of binary bytes to read from parser. |
size_t M_parser_read_buf_max | ( | M_parser_t * | parser, |
M_buf_t * | buf, | ||
size_t | len | ||
) |
Read bytes (binary) from the current buffer and output in the user-provided buffer and advance.
The data read will not be NULL terminated. If the length of data specified is not available, it will return the number of bytes actually read.
[in,out] | parser | Parser object. |
[out] | buf | Buffer to hold output. |
[in] | len | Requested length of data to read. |
size_t M_parser_read_buf_until | ( | M_parser_t * | parser, |
M_buf_t * | buf, | ||
const unsigned char * | pat, | ||
size_t | pat_len, | ||
M_bool | eat_pat | ||
) |
Read bytes (binary) until the specified sequence of bytes is encountered in the data stream.
The data read will not be NULL terminated.
[in,out] | parser | Parser object. |
[out] | buf | Buffer to hold output. |
[in] | pat | Sequence of bytes to search for. |
[in] | pat_len | Length of pattern data. |
[in] | eat_pat | Should the sequence of bytes be consumed. Useful for ignoring data until end of comment. |
size_t M_parser_read_buf_boundary | ( | M_parser_t * | parser, |
M_buf_t * | buf, | ||
const unsigned char * | pat, | ||
size_t | len, | ||
M_bool | eat_pat, | ||
M_bool * | found | ||
) |
Read bytes (binary) until the specified pat is encountered in the data stream.
The data read will not be NULL terminated.
Will stop if parser ends with a partially matching pat. Will only eat the pattern if a full pat is found.
[in,out] | parser | Parser object. |
[out] | buf | Buffer to hold output. |
[in] | pat | Sequence of bytes to search for. |
[in] | len | Length of pattern data. |
[in] | eat_pat | Should the sequence of bytes be consumed. Useful for ignoring data until end of comment. |
[out] | found | Was the full pat found. A partial boundy might still be in the parser if M_FALSE. |
size_t M_parser_read_buf_charset | ( | M_parser_t * | parser, |
M_buf_t * | buf, | ||
const unsigned char * | charset, | ||
size_t | charset_len | ||
) |
Read bytes (binary) from the current buffer as long as the bytes match the provided character set, output in the user-provided buffer and advance.
The data read will not be NULL terminated.
[in,out] | parser | Parser object. |
[out] | buf | Buffer to store result. |
[in] | charset | Array of characters that are allowed. |
[in] | charset_len | Length of character set. |
size_t M_parser_read_buf_not_charset | ( | M_parser_t * | parser, |
M_buf_t * | buf, | ||
const unsigned char * | charset, | ||
size_t | charset_len | ||
) |
Read bytes (binary) from the current buffer as long as the bytes do not match the provided character set, output in the user-provided buffer and advance.
The data read will not be NULL terminated.
[in,out] | parser | Parser object. |
[out] | buf | Buffer to store result. |
[in] | charset | Array of characters that are allowed. |
[in] | charset_len | Length of character set. |
size_t M_parser_read_buf_predicate | ( | M_parser_t * | parser, |
M_buf_t * | buf, | ||
M_parser_predicate_func | func | ||
) |
Read bytes (binary) from the current buffer as long as the bytes match the provided predicate, output in the user-provided buffer and advance.
The data read will not be NULL terminated.
[in,out] | parser | Parser object. |
[out] | buf | Buffer to store result. |
[in] | func | Predicate function. |
size_t M_parser_read_buf_predicate_max | ( | M_parser_t * | parser, |
M_buf_t * | buf, | ||
M_parser_predicate_func | func, | ||
size_t | max | ||
) |
Read bytes (binary) from the current buffer as long as the bytes match the provided predicate up to a given maximum, output in the user-provided buffer and advance.
The data read will not be NULL terminated.
[in,out] | parser | Parser object. |
[out] | buf | Buffer to store result. |
[in] | func | Predicate function. |
[in] | max | Requested length of data to read. |
size_t M_parser_read_buf_chr_predicate | ( | M_parser_t * | parser, |
M_buf_t * | buf, | ||
M_chr_predicate_func | func | ||
) |
Read bytes (binary) from the current buffer as long as the bytes match the provided chr predicate, output in the user-provided buffer and advance.
The data read will not be NULL terminated.
[in,out] | parser | Parser object. |
[out] | buf | Buffer to store result. |
[in] | func | Predicate function. |
size_t M_parser_read_buf_chr_predicate_max | ( | M_parser_t * | parser, |
M_buf_t * | buf, | ||
M_chr_predicate_func | func, | ||
size_t | max | ||
) |
Read bytes (binary) from the current buffer as long as the bytes match the provided chr predicate up to a given maximum, output in the user-provided buffer and advance.
The data read will not be NULL terminated.
[in,out] | parser | Parser object. |
[out] | buf | Buffer to store result. |
[in] | func | Predicate function. |
[in] | max | Requested length of data to read. |
size_t M_parser_read_buf_mark | ( | M_parser_t * | parser, |
M_buf_t * | buf | ||
) |
Read data from a marked position until the current parser position.
The marked position will be automatically cleared.
The data read will not be NULL terminated.
[in,out] | parser | Parser object. |
[out] | buf | Buffer to store result. |
M_parser_t * M_parser_read_parser | ( | M_parser_t * | parser, |
size_t | len | ||
) |
Create new parser from the current position for the given length from the current buffer, allocates a parser and advance. All data is copied into a new memory segment.
[in,out] | parser | Parser object. |
[in] | len | Length to read. |
M_parser_t * M_parser_read_parser_until | ( | M_parser_t * | parser, |
const unsigned char * | pat, | ||
size_t | len, | ||
M_bool | eat_pat | ||
) |
Read data from the buffer until the specified sequence of bytes is encountered in the data stream. All data is copied into a new memory segment.
Put the resulting bytes in a newly allocated parser.
[in,out] | parser | Parser object. |
[in] | pat | Sequence of bytes to search for. |
[in] | len | Length of pattern data. |
[in] | eat_pat | Should the sequence of bytes be consumed. Useful for ignoring data until end of comment. |
M_parser_t * M_parser_read_parser_boundary | ( | M_parser_t * | parser, |
const unsigned char * | pat, | ||
size_t | len, | ||
M_bool | eat_pat, | ||
M_bool * | found | ||
) |
Read data from the buffer until the specified sequence of bytes is encountered in the data stream. All data is copied into a new memory segment.
Put the resulting bytes in a newly allocated parser.
[in,out] | parser | Parser object. |
[in] | pat | Sequence of bytes to search for. |
[in] | len | Length of pattern data. |
[in] | eat_pat | Should the sequence of bytes be consumed. Useful for ignoring data until end of comment. |
[out] | found | Was the full pat found. A partial boundy might still be in the parser if M_FALSE. |
M_parser_t * M_parser_read_parser_charset | ( | M_parser_t * | parser, |
unsigned const char * | charset, | ||
size_t | charset_len | ||
) |
Read data from the buffer for as long as it matches one of the bytes in the given character set and advance. All data is copied into a new memory segment.
Put the resulting bytes in a newly allocated parser.
[in,out] | parser | Parser object. |
[in] | charset | Array of characters that are allowed, NULL terminated. |
[in] | charset_len | Number of characters in the set. |
M_parser_t * M_parser_read_parser_predicate | ( | M_parser_t * | parser, |
M_parser_predicate_func | func | ||
) |
Create new parser from the buffer for as long as it matches the given predicate function and advance. All data is copied into a new memory segment.
Put the resulting bytes in a newly allocated parser.
[in,out] | parser | Parser object. |
[in] | func | Predicate function. |
M_parser_t * M_parser_read_parser_predicate_max | ( | M_parser_t * | parser, |
M_parser_predicate_func | func, | ||
size_t | max | ||
) |
Create new parser from the buffer for as long as it matches the given predicate function up to a given maximum and advance. All data is copied into a new memory segment.
Put the resulting bytes in a newly allocated parser.
[in,out] | parser | Parser object. |
[in] | func | Predicate function. |
[in] | max | Requested length of data to read. |
M_parser_t * M_parser_read_parser_chr_predicate | ( | M_parser_t * | parser, |
M_parser_predicate_func | func | ||
) |
Create new parser from the buffer for as long as it matches the given predicate function and advance. All data is copied into a new memory segment.
Put the resulting bytes in a newly allocated parser.
[in,out] | parser | Parser object. |
[in] | func | Predicate function. |
M_parser_t * M_parser_read_parser_chr_predicate_max | ( | M_parser_t * | parser, |
M_parser_predicate_func | func, | ||
size_t | max | ||
) |
Create new parser from the buffer for as long as it matches the given predicate function up to a given maximum and advance. All data is copied into a new memory segment.
Put the resulting bytes in a newly allocated parser.
[in,out] | parser | Parser object. |
[in] | func | Predicate function. |
[in] | max | Requested length of data to read. |
M_parser_t * M_parser_read_parser_mark | ( | M_parser_t * | parser | ) |
Create new parser from a marked position until the current parser position, allocates a parser and advance. All data is copied into a new memory segment.
[in,out] | parser | Parser object. |
M_PARSER_FRAME_ERROR M_parser_read_stxetxlrc_message | ( | M_parser_t * | parser, |
M_parser_t ** | out, | ||
M_uint32 | lrc_frame_chars | ||
) |
Read an STX, ETX, LRC wrapped message.
The first character in the parser must be an STX.
[in,out] | parser | Parser object. |
[out] | out | Parser object with result message. |
[in] | lrc_frame_chars | Framing characters that should be included in LRC calculation. |
Results M_PARSER_FRAME_ERROR_NO_STX, M_PARSER_FRAME_ERROR_NO_ETX, and M_PARSER_FRAME_ERROR_NO_LRC will not advance the parser.
M_bool M_parser_is_predicate | ( | const M_parser_t * | parser, |
size_t | len, | ||
M_parser_predicate_func | func | ||
) |
Validate the parser matches the given predicate function.
If the input char data is signed, use M_parser_is_chr_predicate() instead.
[in] | parser | Parser object. |
[in] | len | Length to validate. If larger than the parser length the parser length is used. |
[in] | func | Predicate function. |
M_bool M_parser_is_chr_predicate | ( | const M_parser_t * | parser, |
size_t | len, | ||
M_chr_predicate_func | func | ||
) |
Validate the parser matches the given chr predicate function.
If the input char data is unsigned, use M_parser_is_predicate() instead.
[in] | parser | Parser object. |
[in] | len | Length to validate. If larger than the parser length the parser length is used. |
[in] | func | Char predicate function. |
M_bool M_parser_is_charset | ( | const M_parser_t * | parser, |
size_t | len, | ||
const unsigned char * | charset, | ||
size_t | charset_len | ||
) |
Validate the parser matches the given character set.
[in] | parser | Parser object. |
[in] | len | Length to validate. If larger than the parser length the parser length is used. |
[in] | charset | Character set. |
[in] | charset_len | Length of given character set. |
M_bool M_parser_is_str_charset | ( | const M_parser_t * | parser, |
size_t | len, | ||
const char * | charset | ||
) |
Validate the parser matches the given NULL-terminated charset.
[in] | parser | Parser object. |
[in] | len | Length to validate. If larger than the parser length the parser length is used. |
[in] | charset | Character set. |
M_bool M_parser_is_not_predicate | ( | const M_parser_t * | parser, |
size_t | len, | ||
M_parser_predicate_func | func | ||
) |
Validate the parser does not match the given predicate function.
If the input char data is signed, use M_parser_is_not_chr_predicate() instead.
[in] | parser | Parser object. |
[in] | len | Length to validate. If larger than the parser length the parser length is used. |
[in] | func | Predicate function. |
M_bool M_parser_is_not_chr_predicate | ( | const M_parser_t * | parser, |
size_t | len, | ||
M_chr_predicate_func | func | ||
) |
Validate the parser does not match the given chr predicate function.
If the input char data is unsigned, use M_parser_is_not_predicate() instead.
[in] | parser | Parser object. |
[in] | len | Length to validate. If larger than the parser length the parser length is used. |
[in] | func | Char predicate function. |
M_bool M_parser_is_not_charset | ( | const M_parser_t * | parser, |
size_t | len, | ||
const unsigned char * | charset, | ||
size_t | charset_len | ||
) |
Validate the parser does not match the given character set.
[in] | parser | Parser object. |
[in] | len | Length to validate. If larger than the parser length the parser length is used. |
[in] | charset | Character set. |
[in] | charset_len | Length of given character set. |
M_bool M_parser_is_not_str_charset | ( | const M_parser_t * | parser, |
size_t | len, | ||
const char * | charset | ||
) |
Validate the parser does not match the given NULL-terminated charset.
[in] | parser | Parser object. |
[in] | len | Length to validate. If larger than the parser length the parser length is used. |
[in] | charset | Character set. |
M_parser_t ** M_parser_split | ( | M_parser_t * | parser, |
unsigned char | delim, | ||
size_t | maxcnt, | ||
M_uint32 | flags, | ||
size_t * | num_output | ||
) |
Split the data in the parser object by the delimiter specified into additional parser objects.
[in,out] | parser | Parser |
[in] | delim | The delimiter to split on |
[in] | maxcnt | Maximum number of objects to create, remaining data will be part of the last object. 0 if no maximum. |
[in] | flags | M_PARSER_SPLIT_FLAGS flags controlling behavior of parser |
[out] | num_output | The number of parser objects output |
M_parser_t ** M_parser_split_pat | ( | M_parser_t * | parser, |
const unsigned char * | pat, | ||
size_t | pat_len, | ||
size_t | maxcnt, | ||
M_uint32 | flags, | ||
size_t * | num_output | ||
) |
Split the data in the parser object by the pattern specified into additional parser objects.
[in,out] | parser | Parser |
[in] | pat | Sequence of bytes to search for. |
[in] | pat_len | Length of pattern data. |
[in] | maxcnt | Maximum number of objects to create, remaining data will be part of the last object. 0 if no maximum. |
[in] | flags | M_PARSER_SPLIT_FLAGS flags controlling behavior of parser |
[out] | num_output | The number of parser objects output |
M_parser_t ** M_parser_split_str_pat | ( | M_parser_t * | parser, |
const char * | pat, | ||
size_t | maxcnt, | ||
M_uint32 | flags, | ||
size_t * | num_output | ||
) |
Split the data in the parser object by the pattern specified into additional parser objects.
[in,out] | parser | Parser |
[in] | pat | String to search for. |
[in] | maxcnt | Maximum number of objects to create, remaining data will be part of the last object. 0 if no maximum. |
[in] | flags | M_PARSER_SPLIT_FLAGS flags controlling behavior of parser |
[out] | num_output | The number of parser objects output |
void M_parser_split_free | ( | M_parser_t ** | parsers, |
size_t | cnt | ||
) |
Free child parser objects returned from M_parser_split
[in] | parsers | Array of parser objects |
[in] | cnt | Count of objects as returned from M_parser_split |