Mstdlib-1.24.0
m_parser.h
1/* The MIT License (MIT)
2 *
3 * Copyright (c) 2015 Monetra Technologies, LLC.
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a copy
6 * of this software and associated documentation files (the "Software"), to deal
7 * in the Software without restriction, including without limitation the rights
8 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 * copies of the Software, and to permit persons to whom the Software is
10 * furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be included in
13 * all copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21 * THE SOFTWARE.
22 */
23
24#ifndef __M_PARSER_H__
25#define __M_PARSER_H__
26
27/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
28
29#include <mstdlib/base/m_defs.h>
30#include <mstdlib/base/m_types.h>
31#include <mstdlib/base/m_list_str.h>
32#include <mstdlib/base/m_decimal.h>
33#include <mstdlib/base/m_buf.h>
34
35/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
36
37__BEGIN_DECLS
38
39/*! \addtogroup m_parser Data Parser
40 * \ingroup mstdlib_base
41 *
42 * Buffer based data parser.
43 *
44 * Efficient parser that prevents reading past the end of the data buffer.
45 * Has helpers for reading specific types from the buffer (auto conversion).
46 * Also supports line and column tracking.
47 *
48 * @{
49 */
50
51struct M_parser;
52typedef struct M_parser M_parser_t;
53
54
55typedef M_bool (*M_parser_predicate_func)(unsigned char c);
56
57
58/*! Flags controlling behavior of the parser. */
60 M_PARSER_FLAG_NONE = 0, /*!< No Flags. */
61 M_PARSER_FLAG_TRACKLINES = 1 << 0 /*!< Track lines and columns. This should
62 only be enabled if needed as it will
63 cause an additional data scan. */
64};
65
66/*! Flags controlling what constitutes whitespace. */
68 M_PARSER_WHITESPACE_NONE = 0, /*!< Consumes all whitespace */
69 M_PARSER_WHITESPACE_TO_NEWLINE = 1 << 0, /*!< Only consume whitespace up to and including the next new line. */
70 M_PARSER_WHITESPACE_SPACEONLY = 1 << 1 /*!< Only consume space 0x20 characters. */
71};
72
73/*! Integer binary format. */
75 M_PARSER_INTEGER_ASCII = 0, /*!< Integer represented in ASCII form. */
76 M_PARSER_INTEGER_BIGENDIAN = 1, /*!< Integer represented in Big Endian form. */
77 M_PARSER_INTEGER_LITTLEENDIAN = 2 /*!< Integer represented in Little Endian form. */
78};
79
80/*! Splitting flags. */
81typedef enum {
82 M_PARSER_SPLIT_FLAG_NONE = 0, /*!< No flags, standard behavior */
83 M_PARSER_SPLIT_FLAG_NODELIM_ERROR = 1 << 0, /*!< Return an error if the specified delimiter is not found, otherwise all the data is put in a single parser object */
84 M_PARSER_SPLIT_FLAG_DONT_TRIM_LAST = 1 << 1, /*!< Don't trim the last section if it is empty. The default is to not return it as a section */
86
87/*! Framing characters. */
88typedef enum {
89 M_PARSER_FRAME_NONE = 0, /*!< No framing characters. */
90 M_PARSER_FRAME_STX = 1 << 0, /*!< STX (0x02) */
91 M_PARSER_FRAME_ETX = 1 << 1 /*!< ETX (0x03) */
93
94/*! STX, ETX, LRC unwrapping responses. */
95typedef enum {
96 M_PARSER_FRAME_ERROR_SUCCESS = 0, /*!< Success. */
97 M_PARSER_FRAME_ERROR_INVALID, /*!< Invalid input. */
98 M_PARSER_FRAME_ERROR_NO_STX, /*!< Data does not start with STX. */
99 M_PARSER_FRAME_ERROR_NO_ETX, /*!< ETX not found. */
100 M_PARSER_FRAME_ERROR_NO_LRC, /*!< Not enough data for LRC. */
101 M_PARSER_FRAME_ERROR_LRC_CALC_FAILED /*!< LRC calculation failed. */
103
104/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
105
106/*! Initialize a parser object using const data.
107 *
108 * The object is initialized with constant data which cannot be appended to. Memory is not duplicated and therefore the
109 * memory for the buffer pointed to must exist for the life of the parser. The parser will not clean up the memory for
110 * the referenced object.
111 *
112 * \param[in] buf Data to parse, must not be NULL.
113 * \param[in] len Length of data to be parsed.
114 * \param[in] flags Any of the enum M_PARSER_FLAGS bitwise OR'd together.
115 *
116 * \return Parser object, or NULL on failure.
117 *
118 * \see M_parser_destroy
119 */
120M_API M_parser_t *M_parser_create_const(const unsigned char *buf, size_t len, M_uint32 flags);
121
122
123/*! Initialize an empty parser object.
124 *
125 * Its initial state is empty and data must be appended to it before any data can be parsed.
126 *
127 * IMPLEMENTATION NOTE: For efficiency, data which is parsed will be purged
128 * from memory when additional internal buffer space
129 * is required during an append operation. This is
130 * to reclaim space and reduce the number of allocations
131 * required when parsing stream-based data.
132 *
133 * \return Parser object, or NULL on failure.
134 *
135 * \see M_parser_destroy
136 */
137M_API M_parser_t *M_parser_create(M_uint32 flags);
138
139
140/*! Destroy the parser object.
141 *
142 * \param[in] parser Parser object.
143 */
144M_API void M_parser_destroy(M_parser_t *parser);
145
146
147/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
148
149/*! Append data to a parser object.
150 *
151 * The parser object must have been initialized with M_parser_create(). This will append the data to the internal
152 * buffer extending the available length of data to parse.
153 *
154 * \param[in,out] parser Parser object, but not be a const object.
155 * \param[in] data Data to append.
156 * \param[in] len Length of data to append.
157 *
158 * \return M_TRUE on success, M_FALSE on misuse.
159 */
160M_API M_bool M_parser_append(M_parser_t *parser, const unsigned char *data, size_t len);
161
162
163/*! Begin a direct write operation. In general, this function should not be used,
164 * it is meant as an optimization to prevent double buffering when reading I/O.
165 * A writable buffer will be returned of at least the length requested, often it
166 * will be much larger. To end the direct write process, M_parser_direct_write_end()
167 * must be called with the length actually written. It is not valid to call any
168 * other M_parser_*() functions between start and end.
169 *
170 * \param[in,out] parser Parser object, but not be a const object
171 * \param[in,out] len Pass in the minimum requested buffer size, outputs the maximum
172 * writable buffer size.
173 * \return Writable buffer or NULL on failure */
174M_API unsigned char *M_parser_direct_write_start(M_parser_t *parser, size_t *len);
175
176
177/*! End a direct write operation. Please see M_parser_direct_write_start() for more
178 * information. This terminates a direct write sequence regardless of if data was
179 * written or not (len = 0 is acceptable).
180 *
181 * \param[in,out] parser Parser object, but not a const object
182 * \param[in] len Length of data written.
183 */
184M_API void M_parser_direct_write_end(M_parser_t *parser, size_t len);
185
186
187/*! Retrieve the length of data remaining in the buffer being parsed.
188 *
189 * \param[in] parser Parser object.
190 *
191 * \return Length of remaining data.
192 */
193M_API size_t M_parser_len(const M_parser_t *parser);
194
195
196/*! Retrieve the total number of bytes processed so far.
197 *
198 * \param parser Parser object.
199 *
200 * \return Total number of processed bytes.
201 */
202M_API size_t M_parser_current_offset(const M_parser_t *parser);
203
204
205/*! Retrieves the current line number.
206 *
207 * Line numbers are determined based on how many @\n's have been evaluated in the data stream. This can only be called if
208 * M_PARSER_FLAG_TRACKLINES was used during initialization of the parser.
209 *
210 * \param[in] parser parser object.
211 *
212 * \return Line number starting at 1.
213 */
214M_API size_t M_parser_current_line(const M_parser_t *parser);
215
216
217/*! Retrieves the current column for the current line.
218 *
219 * The column count resets each time a @\n is passed. This can only be called if M_PARSER_FLAG_TRACKLINES was used during
220 * initialization of the parser.
221 *
222 * \param parser Parser object.
223 *
224 * \return Column number starting at 1.
225 */
226M_API size_t M_parser_current_column(const M_parser_t *parser);
227
228
229/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
230
231/*! Compare parser contents to provided buffer
232 *
233 * Does not advance.
234 *
235 * \param[in] parser Parser object.
236 * \param[in] data Data to compare.
237 * \param[in] data_len Length of data to compare
238 *
239 * \return M_TRUE if match, M_FALSE otherwise
240 */
241M_API M_bool M_parser_compare(const M_parser_t *parser, const unsigned char *data, size_t data_len);
242
243
244/*! Compare parser contents to provided string.
245 *
246 * Does not advance.
247 *
248 * \param[in] parser Parser object.
249 * \param[in] str String data to compare.
250 * \param[in] max_len Maximum length of data to compare, 0 for entire string. If 0 is
251 * specified, then also the entire parser buffer must be an exact
252 * match. If there are extra bytes after the match, this will not
253 * be considered an exact match.
254 * \param[in] casecmp Perform case-insensitive comparison?
255 *
256 * \return M_TRUE if match, M_FALSE otherwise
257 */
258M_API M_bool M_parser_compare_str(const M_parser_t *parser, const char *str, size_t max_len, M_bool casecmp);
259
260
261/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
262
263/*! Marks the current position for future reference in case additional data might need to be pulled from this marked
264 * point forward.
265 *
266 * If a data position is marked, it will not be eligible to be destroyed/chopped until the marked position is cleared.
267 *
268 * \param[in,out] parser Parser object.
269 */
270M_API void M_parser_mark(M_parser_t *parser);
271
272
273/*! Clears the current marked position, allowing it to be garbage collected.
274 *
275 * \param[in,out] parser Parser object.
276 */
277M_API void M_parser_mark_clear(M_parser_t *parser);
278
279
280/*! Obtain the length of the marked position to the current position.
281 *
282 * \param[in] parser Parser object.
283 *
284 * \return Length or 0 on error.
285 */
286M_API size_t M_parser_mark_len(const M_parser_t *parser);
287
288
289/*! Rewind data back to the marked position.
290 *
291 * This will automaticaly clear the marked position so if the marked position
292 * is still needed, the caller must re-mark it.
293 *
294 * \param[in,out] parser Parser object.
295 *
296 * \return Number of bytes rewinded or 0 on error.
297 */
298M_API size_t M_parser_mark_rewind(M_parser_t *parser);
299
300
301/*! Reset set the parser back to the beginning of the data.
302 *
303 * This is only applicable to 'const' parsers, and will fail on dynamic parsers.
304 * If this scans back past a marked position, the mark will be automatically cleared.
305 *
306 * \param[in,out] parser Parser object.
307 *
308 * \return Number of bytes regurgitated or 0 on error.
309 */
310M_API size_t M_parser_reset(M_parser_t *parser);
311
312
313/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
314
315/*! Retrieve the internal pointer for the current position in the parse buffer.
316 *
317 * \param[in] parser Parser object.
318 *
319 * \return Pointer to data.
320 */
321M_API const unsigned char *M_parser_peek(const M_parser_t *parser);
322
323
324/*! Retrieve the internal pointer for the marked position in the parse buffer.
325 *
326 * \param[in] parser Parser object.
327 * \param[out] len Length of marked data.
328 *
329 * \return Pointer to data.
330 */
331M_API const unsigned char *M_parser_peek_mark(const M_parser_t *parser, size_t *len);
332
333
334/*! Read a single byte from the current buffer without advancing.
335 *
336 * \param[in] parser Parser object.
337 * \param[out] byte Outputs byte read.
338 *
339 * \return M_TRUE on success, M_FALSE on failure.
340 */
341M_API M_bool M_parser_peek_byte(const M_parser_t *parser, unsigned char *byte);
342
343
344/*! Read bytes (binary) from the current buffer and output in the user-provided
345 * buffer without advancing.
346 *
347 * The data read will not be NULL terminated and the buffer provided must be at least as large as large as the
348 * requested data.
349 *
350 * \param[in] parser Parser object.
351 * \param[in] len Length of data to read.
352 * \param[in,out] buf Buffer to hold output.
353 *
354 * \return M_TRUE on success, M_FALSE if not enough bytes or other error.
355 */
356M_API M_bool M_parser_peek_bytes(const M_parser_t *parser, size_t len, unsigned char *buf);
357
358
359/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
360
361/*! Truncate the parse buffer at the position specified (relative to the
362 * current parse offset).
363 *
364 * \param[in,out] parser Parser object.
365 * \param[in] len Length to truncate to.
366 *
367 * \return M_TRUE on success, M_FALSE if not enough bytes exist in the data
368 * stream or other error.
369 */
370M_API M_bool M_parser_truncate(M_parser_t *parser, size_t len);
371
372
373/*! Truncate all available whitespace.
374 *
375 * Searches backwards from end to start.
376 *
377 * \param[in,out] parser Parser object.
378 * \param[in] flags A bitmap of enum M_PARSER_WHITESPACE_FLAGS.
379 *
380 * \return Number of bytes consumed.
381 */
382M_API size_t M_parser_truncate_whitespace(M_parser_t *parser, M_uint32 flags);
383
384
385/*! Truncate all bytes until the specified sequence of bytes is encountered in the data stream.
386 *
387 * Searches backwards from end to start.
388 *
389 * \param[in,out] parser Parser object.
390 * \param[in] pat Sequence of bytes to search for.
391 * \param[in] len Length of pattern data.
392 * \param[in] eat_pat Should the sequence of bytes be consumed. Useful for ignoring data until end of comment.
393 *
394 * \return Number of bytes consumed, or 0 if not found.
395 */
396M_API size_t M_parser_truncate_until(M_parser_t *parser, const unsigned char *pat, size_t len, M_bool eat_pat);
397
398
399/*! Truncate all bytes matching the given charset.
400 *
401 * Searches backwards from end to start.
402 *
403 * \param[in,out] parser Parser object.
404 * \param[in] charset Character set.
405 * \param[in] charset_len Length of given character set.
406 *
407 * \return Number of bytes consumed, or 0 if none/error.
408 */
409M_API size_t M_parser_truncate_charset(M_parser_t *parser, const unsigned char *charset, size_t charset_len);
410
411
412/*! Truncate all bytes matching the given predicate function.
413 *
414 * Searches backwards from end to start.
415 *
416 * \param[in,out] parser Parser object.
417 * \param[in] func Predicate function.
418 *
419 * \return Number of bytes consumed, or 0 if none/error.
420 */
422
423
424/*! Truncate all bytes matching the given predicate function up to a given maximum.
425 *
426 * Searches backwards from end to start.
427 *
428 * \param[in,out] parser Parser object.
429 * \param[in] func Predicate function.
430 * \param[in] max Requested length of data to read.
431 *
432 * \return Number of bytes consumed, or 0 if none/error.
433 */
435
436
437/*! Truncate all bytes matching the given chr predicate function.
438 *
439 * Searches backwards from end to start.
440 *
441 * \param[in,out] parser Parser object.
442 * \param[in] func Predicate function.
443 *
444 * \return Number of bytes consumed, or 0 if none/error.
445 */
447
448
449/*! Truncate all bytes matching the given chr predicate function up to a given maximum.
450 *
451 * Searches backwards from end to start.
452 *
453 * \param[in,out] parser Parser object.
454 * \param[in] func Predicate function.
455 * \param[in] max Requested length of data to read.
456 *
457 * \return Number of bytes consumed, or 0 if none/error.
458 */
460
461
462/*! Truncate all bytes until the specified string is encountered in the data stream.
463 *
464 * Searches backwards from end to start.
465 *
466 * \param[in,out] parser Parser object.
467 * \param[in] pat String to search for.
468 * \param[in] eat_pat Should the sequence of bytes be consumed. Useful for ignoring data until end of comment.
469 *
470 * \return Number of bytes consumed, or 0 if not found.
471 */
472M_API size_t M_parser_truncate_str_until(M_parser_t *parser, const char *pat, M_bool eat_pat);
473
474
475/*! Truncate all bytes matching the given NULL-terminated charset.
476 *
477 * Searches backwards from end to start.
478 *
479 * \param[in,out] parser Parser object.
480 * \param[in] charset Character set, NULL-terminated.
481 *
482 * \return Number of bytes consumed, or 0 if none/error.
483 */
484M_API size_t M_parser_truncate_str_charset(M_parser_t *parser, const char *charset);
485
486/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
487
488/*! Consume the given number of bytes.
489 *
490 * \param[in,out] parser Parser object.
491 * \param[in] len Number of bytes to consume.
492 *
493 * \return M_TRUE on success, M_FALSE if not enough bytes.
494 */
495M_API M_bool M_parser_consume(M_parser_t *parser, size_t len);
496
497
498/*! Consume all available whitespace.
499 *
500 * \param[in,out] parser Parser object.
501 * \param[in] flags A bitmap of enum M_PARSER_WHITESPACE_FLAGS.
502 *
503 * \return Number of bytes consumed.
504 */
505M_API size_t M_parser_consume_whitespace(M_parser_t *parser, M_uint32 flags);
506
507
508/*! Consume all bytes until the specified sequence of bytes is encountered in the data stream.
509 *
510 * \param[in,out] parser Parser object.
511 * \param[in] pat Sequence of bytes to search for.
512 * \param[in] len Length of pattern data.
513 * \param[in] eat_pat Should the sequence of bytes be consumed. Useful for ignoring data until end of comment.
514 *
515 * \return Number of bytes consumed, or 0 if not found.
516 */
517M_API size_t M_parser_consume_until(M_parser_t *parser, const unsigned char *pat, size_t len, M_bool eat_pat);
518
519
520/*! Consume all bytes before a pat.
521 *
522 * Will stop if parser ends with a partially matching pat. Will only eat the pattern
523 * if a full pat is found.
524 *
525 * Will stop consuming if a partial match of the pat is found.
526 * E.g. parser = "ABC1234" pat = "12345".
527 * Will consume "ABC" leaving "12345".
528 * If more data is added and and parser = "123461234".
529 * Will consume "12346".
530 * If more data is added and and parser = "1234612345"
531 * Will consume everything is eat_path is M_TRUE. Otherwise, "12346".
532 *
533 * \param[in,out] parser Parser object.
534 * \param[in] pat Sequence of bytes to search for.
535 * \param[in] len Length of pattern data.
536 * \param[in] eat_pat Should the sequence of bytes be consumed. Useful for ignoring data until end of comment.
537 * \param[out] found Was the full pat found. A partial boundy might still be in the parser if M_FALSE.
538 *
539 * \return Number of bytes consumed. 0 if not found or if starts with a partial pat match.
540 */
541M_API size_t M_parser_consume_boundary(M_parser_t *parser, const unsigned char *pat, size_t len, M_bool eat_pat, M_bool *found);
542
543
544/*! Consume all bytes matching the given charset.
545 *
546 * \param[in,out] parser Parser object.
547 * \param[in] charset Character set.
548 * \param[in] charset_len Length of given character set.
549 *
550 * \return Number of bytes consumed, or 0 if none/error.
551 */
552M_API size_t M_parser_consume_charset(M_parser_t *parser, const unsigned char *charset, size_t charset_len);
553
554
555/*! Consume all bytes matching the given predicate function.
556 *
557 * \param[in,out] parser Parser object.
558 * \param[in] func Predicate function.
559 *
560 * \return Number of bytes consumed, or 0 if none/error.
561 */
563
564
565/*! Consume all bytes matching the given predicate function up to a given maximum.
566 *
567 * \param[in,out] parser Parser object.
568 * \param[in] func Predicate function.
569 * \param[in] max Requested length of data to read.
570 *
571 * \return Number of bytes consumed, or 0 if none/error.
572 */
574
575
576/*! Consume all bytes matching the given chr predicate function.
577 *
578 * \param[in,out] parser Parser object.
579 * \param[in] func Predicate function.
580 *
581 * \return Number of bytes consumed, or 0 if none/error.
582 */
584
585
586/*! Consume all bytes matching the given chr predicate function up to a given maximum.
587 *
588 * \param[in,out] parser Parser object.
589 * \param[in] func Predicate function.
590 * \param[in] max Requested length of data to read.
591 *
592 * \return Number of bytes consumed, or 0 if none/error.
593 */
595
596
597/*! Consume all bytes until the specified string is encountered in the data stream.
598 *
599 * \param[in,out] parser Parser object.
600 * \param[in] pat String to search for.
601 * \param[in] eat_pat Should the sequence of bytes be consumed. Useful for ignoring data until end of comment.
602 *
603 * \return Number of bytes consumed, or 0 if not found.
604 */
605M_API size_t M_parser_consume_str_until(M_parser_t *parser, const char *pat, M_bool eat_pat);
606
607
608/*! Consume all bytes before a pat.
609 *
610 * Will stop if parser ends with a partially matching pat. Will only eat the pattern
611 * if a full pat is found.
612 *
613 * Will stop consuming if a partial match of the pat is found.
614 * E.g. parser = "ABC1234" pat = "12345".
615 * Will consume "ABC" leaving "12345".
616 * If more data is added and and parser = "123461234".
617 * Will consume "12346".
618 * If more data is added and and parser = "1234612345"
619 * Will consume everything is eat_path is M_TRUE. Otherwise, "12346".
620 *
621 * \param[in,out] parser Parser object.
622 * \param[in] pat String to search for.
623 * \param[in] eat_pat Should the sequence of bytes be consumed. Useful for ignoring data until end of comment.
624 * \param[out] found Was the full pat found. A partial boundy might still be in the parser if M_FALSE.
625 *
626 * \return Number of bytes consumed. 0 if not found or if starts with a partial pat match.
627 */
628M_API size_t M_parser_consume_str_boundary(M_parser_t *parser, const char *pat, M_bool eat_pat, M_bool *found);
629
630
631/*! Consume all bytes matching the given NULL-terminated charset.
632 *
633 * \param[in,out] parser Parser object.
634 * \param[in] charset Character set, NULL-terminated.
635 *
636 * \return Number of bytes consumed, or 0 if none/error.
637 */
638M_API size_t M_parser_consume_str_charset(M_parser_t *parser, const char *charset);
639
640
641/*! Consume all bytes not matching the given charset.
642 *
643 * \param[in,out] parser Parser object.
644 * \param[in] charset Character set, NULL-terminated.
645 * \param[in] charset_len Length of given character set.
646 *
647 * \return Number of bytes consumed, or 0 if none/error.
648 */
649M_API size_t M_parser_consume_not_charset(M_parser_t *parser, const unsigned char *charset, size_t charset_len);
650
651
652/*! Consume all bytes not matching the given NULL-terminated charset.
653 *
654 * \param[in,out] parser Parser object.
655 * \param[in] charset Character set, NULL-terminated.
656 *
657 * \return Number of bytes consumed, or 0 if none/error.
658 */
659M_API size_t M_parser_consume_str_not_charset(M_parser_t *parser, const char *charset);
660
661
662/*! Consume all bytes until and including the next end of line.
663 *
664 * Useful for ignoring data until end of single-line comment. If there is no new line, will consume all remaining data.
665 *
666 * \param[in,out] parser Parser object.
667 *
668 * \return Number of bytes consumed.
669 */
670M_API size_t M_parser_consume_eol(M_parser_t *parser);
671
672
673/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
674
675/*! Read a signed integer from the current buffer and advance.
676 *
677 * For ASCII formatted integers:
678 * - if len is not specified, it will read up until the first non-numeric
679 * character is encountered. At least one numeric must be encountered or
680 * it is considered an error.
681 * - if len is specified, the integer must be exactly that length (no shorter)
682 * or it is considered an error.
683 * - if base is specified as 0, will attempt to auto-detect the base.
684 *
685 * For BigEndian or Little Endian formatted integers:
686 * - The len is mandatory, and base is ignored. Maximum len is 8.
687 *
688 * \param[in,out] parser Parser object.
689 * \param[in] type How integer is represented in the data stream.
690 * \param[in] len Length of integer, or 0 to auto-determine for ASCII.
691 * \param[in] base Base represented in ASCII, or 0 to auto-determine (or non-ascii).
692 * \param[out] integer Integer storage.
693 *
694 * \return M_FALSE on failure, M_TRUE on success.
695 */
696M_API 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);
697
698
699/*! Read an unsigned integer from the current buffer and advance.
700 *
701 * See M_parser_read_int() for details on usage as requirements are the same.
702 *
703 * \param[in,out] parser Parser object.
704 * \param[in] type How integer is represented in the data stream.
705 * \param[in] len Length of integer, or 0 to auto-determine for ASCII.
706 * \param[in] base Base represented in ASCII, or 0 to auto-determine (or non-ascii).
707 * \param[out] integer Integer storage.
708 *
709 * \return M_FALSE on failure, M_TRUE on success.
710 *
711 * \see M_parser_read_int
712 */
713M_API 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);
714
715
716/*! Read and unsigned Binary Coded Decimal integer from the current buffer and advance
717 *
718 * \param[in,out] parser Parser object.
719 * \param[in] len Length of integer in bytes.
720 * \param[out] integer Integer storage.
721 *
722 * \return M_FALSE on failure, M_TRUE on success.
723 */
724M_API M_bool M_parser_read_uint_bcd(M_parser_t *parser, size_t len, M_uint64 *integer);
725
726
727/*! Read a decimal number from current buffer and advance.
728 *
729 * The number must be represented in base 10 and in ASCII form.
730 *
731 * \param[in,out] parser Parser object.
732 * \param[in] len Length of decimal, or 0 to auto-determine.
733 * \param[in] truncate_fail M_TRUE to treat a truncation as a failure and not increment the consumer.
734 * M_FALSE otherwise.
735 * \param[out] decimal Decimal storage.
736 *
737 * \return enum M_DECIMAL_RETVAL values.
738 */
739M_API enum M_DECIMAL_RETVAL M_parser_read_decimal(M_parser_t *parser, size_t len, M_bool truncate_fail, M_decimal_t *decimal);
740
741
742/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
743
744/*! Read a single byte from the current buffer and advance.
745 *
746 * \param[in,out] parser Parser object.
747 * \param[out] byte Outputs byte read.
748 *
749 * \return M_TRUE on success, M_FALSE on failure.
750 */
751M_API M_bool M_parser_read_byte(M_parser_t *parser, unsigned char *byte);
752
753
754/*! Read the exact number of bytes (binary) from the current buffer and output in the user-provided buffer and advance.
755 * If there are fewer than the requested bytes available, an error will be returned.
756 *
757 * The data read will not be NULL terminated and the buffer provided must be at least as large as as the
758 * requested data.
759 *
760 * \param[in,out] parser Parser object.
761 * \param[in] len Length of data to read.
762 * \param[out] buf Buffer to hold output.
763 *
764 * \return M_TRUE on success, M_FALSE if not enough bytes or other error.
765 */
766M_API M_bool M_parser_read_bytes(M_parser_t *parser, size_t len, unsigned char *buf);
767
768
769/*! Read bytes (binary) from the current buffer and output in the user-provided buffer and advance.
770 *
771 * The data read will not be NULL terminated and the buffer provided must be at least as large as large as the
772 * requested data. If the length of data specified is not available, it will return the number of
773 * bytes actually read.
774 *
775 * \param[in,out] parser Parser object.
776 * \param[in] len Requested length of data to read.
777 * \param[out] buf Buffer to hold output.
778 * \param[in] buf_len Length of buffer to hold output.
779 *
780 * \return number of bytes read, or 0 on error or no bytes available.
781 */
782M_API size_t M_parser_read_bytes_max(M_parser_t *parser, size_t len, unsigned char *buf, size_t buf_len);
783
784
785/*! Read bytes (binary) until the specified sequence of bytes is encountered in the data stream.
786 *
787 * \param[in,out] parser Parser object.
788 * \param[out] buf Buffer to hold output.
789 * \param[in] buf_len Length of buffer to hold output.
790 * \param[in] pat Sequence of bytes to search for.
791 * \param[in] pat_len Length of pattern data.
792 * \param[in] eat_pat Should the sequence of bytes be consumed. Useful for ignoring data until end of comment.
793 *
794 * \return number of bytes read, or 0 on error or no bytes available.
795 */
796M_API 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);
797
798
799/*! Read bytes (binary) until the specified pat is encountered in the data stream.
800 *
801 * The data read will not be NULL terminated.
802 *
803 * Will stop if parser ends with a partially matching pat. Will only eat the pattern
804 * if a full pat is found.
805 *
806 * \param[in,out] parser Parser object.
807 * \param[out] buf Buffer to hold output.
808 * \param[in] buf_len Length of buffer to hold output.
809 * \param[in] pat Sequence of bytes to search for.
810 * \param[in] len Length of pattern data.
811 * \param[in] eat_pat Should the sequence of bytes be consumed. Useful for ignoring data until end of comment.
812 * \param[out] found Was the full pat found. A partial boundy might still be in the parser if M_FALSE.
813 *
814 * \return number of bytes read, or 0 on error or no bytes available.
815 */
816M_API 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);
817
818
819/*! Read bytes (binary) from the current buffer as long as the bytes match the
820 * provided character set, output in the user-provided buffer and advance.
821 *
822 * The data read will not be NULL terminated.
823 *
824 * \param[in,out] parser Parser object.
825 * \param[in] charset Array of characters that are allowed.
826 * \param[in] charset_len Length of character set.
827 * \param[out] buf Buffer to store result.
828 * \param[in] buf_len Size of result buffer.
829 *
830 * \return Length of data read, or 0 on error.
831 */
832M_API 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);
833
834
835/*! Read bytes (binary) from the current buffer as long as the bytes do not match the
836 * provided character set, output in the user-provided buffer and advance.
837 *
838 * The data read will not be NULL terminated.
839 *
840 * \param[in,out] parser Parser object.
841 * \param[in] charset Array of characters that are allowed.
842 * \param[in] charset_len Length of character set.
843 * \param[out] buf Buffer to store result.
844 * \param[in] buf_len Size of result buffer.
845 *
846 * \return Length of data read, or 0 on error.
847 */
848M_API 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);
849
850
851/*! Read bytes (binary) from the current buffer as long as the bytes match the
852 * provided predicate, output in the user-provided buffer and advance.
853 *
854 * The data read will not be NULL terminated.
855 *
856 * \param[in,out] parser Parser object.
857 * \param[in] func Predicate function.
858 * \param[out] buf Buffer to store result.
859 * \param[in] buf_len Size of result buffer.
860 *
861 * \return Length of data read, or 0 on error.
862 */
863M_API size_t M_parser_read_bytes_predicate(M_parser_t *parser, M_parser_predicate_func func, unsigned char *buf, size_t buf_len);
864
865
866/*! Read bytes (binary) from the current buffer as long as the bytes match the
867 * provided chr predicate, output in the user-provided buffer and advance.
868 *
869 * The data read will not be NULL terminated.
870 *
871 * \param[in,out] parser Parser object.
872 * \param[in] func Predicate function.
873 * \param[out] buf Buffer to store result.
874 * \param[in] buf_len Size of result buffer.
875 *
876 * \return Length of data read, or 0 on error.
877 */
878M_API size_t M_parser_read_bytes_chr_predicate(M_parser_t *parser, M_chr_predicate_func func, unsigned char *buf, size_t buf_len);
879
880
881/*! Read data from a marked position until the current parser position.
882 *
883 * The marked position will be automatically cleared. Provided buffer must be at least M_parser_mark_len() bytes long.
884 *
885 * \param[in,out] parser Parser object.
886 * \param[out] buf Buffer to store result.
887 * \param[in] buf_len Size of result buffer.
888 *
889 * \return number of bytes written to buffer or 0 on error.
890 */
891M_API size_t M_parser_read_bytes_mark(M_parser_t *parser, unsigned char *buf, size_t buf_len);
892
893/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
894
895/*! Read a string from the current buffer of the exact given length, output in
896 * the user-provided buffer and advance. If there are insufficient bytes a
897 * failure will be returned.
898 *
899 * The length of the requested string must be at least one byte shorter than
900 * the buffer size to account for the null termination. If you do not already
901 * have a buffer, use M_parser_read_strdup() which will return a newly allocated
902 * buffer for you.
903 *
904 * \param[in,out] parser Parser object.
905 * \param[in] len Length of string to read (must be at least one byte shorter than buf_len).
906 * \param[out] buf Output pointer to store result.
907 * \param[in] buf_len Length of output buffer (must be at least one byte greater than len).
908 *
909 * \return M_TRUE on success, or M_FALSE if not enough bytes or other error.
910 *
911 * \see M_parser_read_strdup
912 */
913M_API M_bool M_parser_read_str(M_parser_t *parser, size_t len, char *buf, size_t buf_len);
914
915
916/*! Read a string from the current buffer, output in the user-provided buffer and advance.
917 *
918 * The length of the requested string must be at least one byte shorter than
919 * the buffer size to account for the null termination. If you do not already
920 * have a buffer, use M_parser_read_strdup() which will return a newly allocated
921 * buffer for you.
922 *
923 * \param[in,out] parser Parser object.
924 * \param[in] len Requested length of string to read (must be at least one
925 * byte shorter than buf_len).
926 * \param[out] buf Output pointer to store result.
927 * \param[in] buf_len Length of output buffer (must be at least one byte greater than len).
928 *
929 * \return number of bytes read, or 0 on failure.
930 *
931 * \see M_parser_read_str
932 */
933M_API size_t M_parser_read_str_max(M_parser_t *parser, size_t len, char *buf, size_t buf_len);
934
935
936/*! Read data until the specified sequence of bytes is encountered in the data stream.
937 *
938 *
939 * \param[in,out] parser Parser object.
940 * \param[out] buf Buffer to hold output.
941 * \param[in] buf_len Length of buffer to hold output.
942 * \param[in] pat String to search for.
943 * \param[in] eat_pat Should the sequence of bytes be consumed. Useful for ignoring data until end of comment.
944 *
945 * \return number of bytes read, or 0 on error or no bytes available.
946 */
947M_API size_t M_parser_read_str_until(M_parser_t *parser, char *buf, size_t buf_len, const char *pat, M_bool eat_pat);
948
949
950/*! Read data until the specified pat is encountered in the data stream.
951 *
952 * Will stop if parser ends with a partially matching pat. Will only eat the pattern
953 * if a full pat is found.
954 *
955 * \param[in,out] parser Parser object.
956 * \param[out] buf Buffer to hold output.
957 * \param[in] buf_len Length of buffer to hold output.
958 * \param[in] pat String to search for.
959 * \param[in] eat_pat Should the sequence of bytes be consumed. Useful for ignoring data until end of comment.
960 * \param[out] found Was the full pat found. A partial boundy might still be in the parser if M_FALSE.
961 *
962 * \return number of bytes read, or 0 on error or no bytes available.
963 */
964M_API 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);
965
966
967/*! Read data from the buffer for as long as it matches one of the bytes in the given character set and advance.
968 *
969 * Put the resulting bytes in the provided buffer.
970 *
971 * \param[in,out] parser Parser object.
972 * \param[in] charset Array of characters that are allowed, NULL terminated.
973 * \param[out] buf Buffer to store result. Will be NULL terminated.
974 * \param[in] buf_len Size of result buffer.
975 *
976 * \return Length of data read, or 0 on error.
977 *
978 * \see M_parser_read_strdup_charset
979 */
980M_API size_t M_parser_read_str_charset(M_parser_t *parser, const char *charset, char *buf, size_t buf_len);
981
982
983/*! Read data from the buffer for as long as it does not match one of the bytes in the given character set and advance.
984 *
985 * Put the resulting bytes in the provided buffer.
986 *
987 * \param[in,out] parser Parser object.
988 * \param[in] charset Array of characters that are allowed, NULL terminated.
989 * \param[out] buf Buffer to store result. Will be NULL terminated.
990 * \param[in] buf_len Size of result buffer.
991 *
992 * \return Length of data read, or 0 on error.
993 *
994 * \see M_parser_read_strdup_charset
995 */
996M_API size_t M_parser_read_str_not_charset(M_parser_t *parser, const char *charset, char *buf, size_t buf_len);
997
998
999/*! Read data from the buffer for as long as it matches the given predicate function and advance.
1000 *
1001 * Put the resulting bytes in the provided buffer.
1002 *
1003 * \param[in,out] parser Parser object.
1004 * \param[in] func predicate function.
1005 * \param[out] buf Buffer to store result. Will be NULL terminated.
1006 * \param[in] buf_len Size of result buffer.
1007 *
1008 * \return Length of data read, or 0 on error.
1009 *
1010 * \see M_parser_read_strdup_predicate
1011 */
1012M_API size_t M_parser_read_str_predicate(M_parser_t *parser, M_parser_predicate_func func, char *buf, size_t buf_len);
1013
1014
1015/*! Read data from the buffer for as long as it matches the given chr predicate function and advance.
1016 *
1017 * Put the resulting bytes in the provided buffer.
1018 *
1019 * \param[in,out] parser Parser object.
1020 * \param[in] func predicate function.
1021 * \param[out] buf Buffer to store result. Will be NULL terminated.
1022 * \param[in] buf_len Size of result buffer.
1023 *
1024 * \return Length of data read, or 0 on error.
1025 *
1026 * \see M_parser_read_strdup_predicate
1027 */
1028M_API size_t M_parser_read_str_chr_predicate(M_parser_t *parser, M_chr_predicate_func func, char *buf, size_t buf_len);
1029
1030
1031/*! Read data from a marked position until the current parser position.
1032 *
1033 * The marked position will be automatically cleared. Provided buffer must be at least M_parser_mark_len() bytes plus
1034 * the NULL terminator.
1035 *
1036 * \param[in,out] parser Parser object.
1037 * \param[out] buf Buffer to store result.
1038 * \param[in] buf_len Size of result buffer.
1039 *
1040 * \return Number of bytes written to buffer or 0 on error.
1041 */
1042M_API size_t M_parser_read_str_mark(M_parser_t *parser, char *buf, size_t buf_len);
1043
1044
1045/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
1046
1047/*! Read a string for the given length from the current buffer, allocates an output buffer and advance.
1048 *
1049 * \param[in,out] parser Parser object.
1050 * \param[in] len Length of string to read.
1051 *
1052 * \return Buffer containing the string on success, or NULL on failure.
1053 *
1054 * \see M_parser_read_str
1055 */
1056M_API char *M_parser_read_strdup(M_parser_t *parser, size_t len);
1057
1058
1059/*! Read bytes (binary) from the parser, return as hex-encoded string and advance.
1060 *
1061 * \param[in,out] parser Parser object to read binary bytes from.
1062 * \param[in] len Number of binary bytes to read from parser.
1063 *
1064 * \return null-terminated hex string on success, NULL if not enough bytes or other error
1065 *
1066 * \see M_parser_read_buf_hex
1067 */
1068M_API char *M_parser_read_strdup_hex(M_parser_t *parser, size_t len);
1069
1070
1071/*! Read data until the specified sequence of bytes is encountered in the data stream.
1072 *
1073 * Put the resulting bytes in a newly allocated buffer.
1074 *
1075 * \param[in,out] parser Parser object.
1076 * \param[in] pat Sequence of bytes to search for.
1077 * \param[in] eat_pat Should the sequence of bytes be consumed. Useful for ignoring data until end of comment.
1078 *
1079 * \return number of bytes read, or 0 on error or no bytes available.
1080 */
1081M_API char *M_parser_read_strdup_until(M_parser_t *parser, const char *pat, M_bool eat_pat);
1082
1083
1084/*! Read data until the specified pat is encountered in the data stream.
1085 *
1086 * Will stop if parser ends with a partially matching pat. Will only eat the pattern
1087 * if a full pat is found.
1088 *
1089 * Put the resulting bytes in a newly allocated buffer.
1090 *
1091 * \param[in,out] parser Parser object.
1092 * \param[in] pat String to search for.
1093 * \param[in] eat_pat Should the sequence of bytes be consumed. Useful for ignoring data until end of comment.
1094 * \param[out] found Was the full pat found. A partial boundy might still be in the parser if M_FALSE.
1095 *
1096 * \return number of bytes read, or 0 on error or no bytes available.
1097 */
1098M_API char *M_parser_read_strdup_boundary(M_parser_t *parser, const char *pat, M_bool eat_pat, M_bool *found);
1099
1100
1101/*! Read data from the buffer for as long as it matches one of the bytes in the given character set and advance.
1102 *
1103 * Put the resulting bytes in a newly allocated buffer.
1104 *
1105 * \param[in,out] parser Parser object.
1106 * \param[in] charset Array of characters that are allowed, NULL terminated.
1107 *
1108 * \return NULL-terminated result buffer, or NULL on error.
1109 *
1110 * \see M_parser_read_str_charset
1111 */
1112M_API char *M_parser_read_strdup_charset(M_parser_t *parser, const char *charset);
1113
1114
1115/*! Read data from the buffer for as long as it does not match one of the bytes in the given character set and advance.
1116 *
1117 * Put the resulting bytes in a newly allocated buffer.
1118 *
1119 * \param[in,out] parser Parser object.
1120 * \param[in] charset Array of characters that are allowed, NULL terminated.
1121 *
1122 * \return NULL-terminated result buffer, or NULL on error.
1123 *
1124 * \see M_parser_read_str_not_charset
1125 */
1126M_API char *M_parser_read_strdup_not_charset(M_parser_t *parser, const char *charset);
1127
1128
1129/*! Read data from the buffer for as long as it matches the given predicate function and advance.
1130 *
1131 * Put the resulting bytes in a newly allocated buffer.
1132 *
1133 * \param[in,out] parser Parser object.
1134 * \param[in] func Predicate function.
1135 *
1136 * \return NULL-terminated result buffer, or NULL on error.
1137 *
1138 * \see M_parser_read_str_predicate
1139 */
1141
1142
1143/*! Read data from the buffer for as long as it matches the given predicate function
1144 * up to a given maximum and advance.
1145 *
1146 * Put the resulting bytes in a newly allocated buffer.
1147 *
1148 * \param[in,out] parser Parser object.
1149 * \param[in] func Predicate function.
1150 * \param[in] max Requested length of data to read.
1151 *
1152 * \return NULL-terminated result buffer, or NULL on error.
1153 *
1154 * \see M_parser_read_str_predicate
1155 */
1157
1158
1159/*! Read data from the buffer for as long as it matches the given predicate function and advance.
1160 *
1161 * Put the resulting bytes in a newly allocated buffer.
1162 *
1163 * \param[in,out] parser Parser object.
1164 * \param[in] func predicate function.
1165 *
1166 * \return NULL-terminated result buffer, or NULL on error.
1167 *
1168 * \see M_parser_read_str_predicate
1169 */
1171
1172
1173/*! Read data from the buffer for as long as it matches the given predicate function
1174 * up to a given maximum and advance.
1175 *
1176 * Put the resulting bytes in a newly allocated buffer.
1177 *
1178 * \param[in,out] parser Parser object.
1179 * \param[in] func predicate function.
1180 * \param[in] max Requested length of data to read.
1181 *
1182 * \return NULL-terminated result buffer, or NULL on error.
1183 *
1184 * \see M_parser_read_str_predicate
1185 */
1187
1188
1189/*! Read data from a marked position until the current parser position.
1190 *
1191 * The marked position will be automatically cleared. An allocated buffer with the requested data will be returned,
1192 * NULL terminated.
1193 *
1194 * \param[in,out] parser Parser object.
1195 *
1196 * \return NULL-terminated result, or NULL on error.
1197 */
1199
1200/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
1201
1202
1203/*! Read the exact number of bytes (binary) from the current buffer and output in the user-provided buffer and advance.
1204 *
1205 * If there are fewer than the requested bytes available, an error will be returned.
1206 *
1207 * The data read will not be NULL terminated.
1208 *
1209 * \param[in,out] parser Parser object.
1210 * \param[out] buf Buffer to hold output.
1211 * \param[in] len Length of data to read.
1212 *
1213 * \return M_TRUE on success, M_FALSE if not enough bytes or other error.
1214 */
1215M_API M_bool M_parser_read_buf(M_parser_t *parser, M_buf_t *buf, size_t len);
1216
1217
1218/*! Read bytes (binary) from the parser, write as hex-encoded string into the provided buffer, and advance.
1219 *
1220 * \param[in,out] parser Parser object to read binary bytes from.
1221 * \param[out] buf Buffer to hold hex-ascii output.
1222 * \param[in] len Number of binary bytes to read from parser.
1223 *
1224 * \return M_TRUE on success, M_FALSE if not enough bytes or other error.
1225 */
1226M_API M_bool M_parser_read_buf_hex(M_parser_t *parser, M_buf_t *buf, size_t len);
1227
1228
1229/*! Read bytes (binary) from the current buffer and output in the user-provided buffer and advance.
1230 *
1231 * The data read will not be NULL terminated. If the length of data specified
1232 * is not available, it will return the number of bytes actually read.
1233 *
1234 * \param[in,out] parser Parser object.
1235 * \param[out] buf Buffer to hold output.
1236 * \param[in] len Requested length of data to read.
1237 *
1238 * \return number of bytes read, or 0 on error or no bytes available.
1239 */
1240M_API size_t M_parser_read_buf_max(M_parser_t *parser, M_buf_t *buf, size_t len);
1241
1242
1243/*! Read bytes (binary) until the specified sequence of bytes is encountered in the data stream.
1244 *
1245 * The data read will not be NULL terminated.
1246 *
1247 * \param[in,out] parser Parser object.
1248 * \param[out] buf Buffer to hold output.
1249 * \param[in] pat Sequence of bytes to search for.
1250 * \param[in] pat_len Length of pattern data.
1251 * \param[in] eat_pat Should the sequence of bytes be consumed. Useful for ignoring data until end of comment.
1252 *
1253 * \return number of bytes read, or 0 on error or no bytes available.
1254 */
1255M_API 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);
1256
1257
1258/*! Read bytes (binary) until the specified pat is encountered in the data stream.
1259 *
1260 * The data read will not be NULL terminated.
1261 *
1262 * Will stop if parser ends with a partially matching pat. Will only eat the pattern
1263 * if a full pat is found.
1264 *
1265 * \param[in,out] parser Parser object.
1266 * \param[out] buf Buffer to hold output.
1267 * \param[in] pat Sequence of bytes to search for.
1268 * \param[in] len Length of pattern data.
1269 * \param[in] eat_pat Should the sequence of bytes be consumed. Useful for ignoring data until end of comment.
1270 * \param[out] found Was the full pat found. A partial boundy might still be in the parser if M_FALSE.
1271 *
1272 * \return number of bytes read, or 0 on error or no bytes available.
1273 */
1274M_API 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);
1275
1276
1277/*! Read bytes (binary) from the current buffer as long as the bytes match the
1278 * provided character set, output in the user-provided buffer and advance.
1279 *
1280 * The data read will not be NULL terminated.
1281 *
1282 * \param[in,out] parser Parser object.
1283 * \param[out] buf Buffer to store result.
1284 * \param[in] charset Array of characters that are allowed.
1285 * \param[in] charset_len Length of character set.
1286 *
1287 * \return Length of data read, or 0 on error.
1288 */
1289M_API size_t M_parser_read_buf_charset(M_parser_t *parser, M_buf_t *buf, const unsigned char *charset, size_t charset_len);
1290
1291
1292/*! Read bytes (binary) from the current buffer as long as the bytes do not match the
1293 * provided character set, output in the user-provided buffer and advance.
1294 *
1295 * The data read will not be NULL terminated.
1296 *
1297 * \param[in,out] parser Parser object.
1298 * \param[out] buf Buffer to store result.
1299 * \param[in] charset Array of characters that are allowed.
1300 * \param[in] charset_len Length of character set.
1301 *
1302 * \return Length of data read, or 0 on error.
1303 */
1304M_API size_t M_parser_read_buf_not_charset(M_parser_t *parser, M_buf_t *buf, const unsigned char *charset, size_t charset_len);
1305
1306
1307/*! Read bytes (binary) from the current buffer as long as the bytes match the
1308 * provided predicate, output in the user-provided buffer and advance.
1309 *
1310 * The data read will not be NULL terminated.
1311 *
1312 * \param[in,out] parser Parser object.
1313 * \param[out] buf Buffer to store result.
1314 * \param[in] func Predicate function.
1315 *
1316 * \return Length of data read, or 0 on error.
1317 */
1319
1320
1321/*! Read bytes (binary) from the current buffer as long as the bytes match the
1322 * provided predicate up to a given maximum, output in the user-provided buffer and advance.
1323 *
1324 * The data read will not be NULL terminated.
1325 *
1326 * \param[in,out] parser Parser object.
1327 * \param[out] buf Buffer to store result.
1328 * \param[in] func Predicate function.
1329 * \param[in] max Requested length of data to read.
1330 *
1331 * \return Length of data read, or 0 on error.
1332 */
1334
1335
1336/*! Read bytes (binary) from the current buffer as long as the bytes match the
1337 * provided chr predicate, output in the user-provided buffer and advance.
1338 *
1339 * The data read will not be NULL terminated.
1340 *
1341 * \param[in,out] parser Parser object.
1342 * \param[out] buf Buffer to store result.
1343 * \param[in] func Predicate function.
1344 *
1345 * \return Length of data read, or 0 on error.
1346 */
1348
1349
1350/*! Read bytes (binary) from the current buffer as long as the bytes match the
1351 * provided chr predicate up to a given maximum, output in the user-provided buffer and advance.
1352 *
1353 * The data read will not be NULL terminated.
1354 *
1355 * \param[in,out] parser Parser object.
1356 * \param[out] buf Buffer to store result.
1357 * \param[in] func Predicate function.
1358 * \param[in] max Requested length of data to read.
1359 *
1360 * \return Length of data read, or 0 on error.
1361 */
1363
1364
1365/*! Read data from a marked position until the current parser position.
1366 *
1367 * The marked position will be automatically cleared.
1368 *
1369 * The data read will not be NULL terminated.
1370 *
1371 * \param[in,out] parser Parser object.
1372 * \param[out] buf Buffer to store result.
1373 *
1374 * \return number of bytes written to buffer or 0 on error.
1375 */
1376M_API size_t M_parser_read_buf_mark(M_parser_t *parser, M_buf_t *buf);
1377
1378/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
1379
1380/*! Create new parser from the current position for the given length from the current buffer, allocates a parser and advance.
1381 * All data is copied into a new memory segment.
1382 *
1383 * \param[in,out] parser Parser object.
1384 * \param[in] len Length to read.
1385 *
1386 * \return parser.
1387 */
1388M_API M_parser_t *M_parser_read_parser(M_parser_t *parser, size_t len);
1389
1390
1391/*! Read data from the buffer until the specified sequence of bytes is encountered in the data stream.
1392 * All data is copied into a new memory segment.
1393 *
1394 * Put the resulting bytes in a newly allocated parser.
1395 *
1396 * \param[in,out] parser Parser object.
1397 * \param[in] pat Sequence of bytes to search for.
1398 * \param[in] len Length of pattern data.
1399 * \param[in] eat_pat Should the sequence of bytes be consumed. Useful for ignoring data until end of comment.
1400 *
1401 * \return parser.
1402 */
1403M_API M_parser_t *M_parser_read_parser_until(M_parser_t *parser, const unsigned char *pat, size_t len, M_bool eat_pat);
1404
1405
1406/*! Read data from the buffer until the specified sequence of bytes is encountered in the data stream.
1407 * All data is copied into a new memory segment.
1408 *
1409 * Put the resulting bytes in a newly allocated parser.
1410 *
1411 * \param[in,out] parser Parser object.
1412 * \param[in] pat Sequence of bytes to search for.
1413 * \param[in] len Length of pattern data.
1414 * \param[in] eat_pat Should the sequence of bytes be consumed. Useful for ignoring data until end of comment.
1415 * \param[out] found Was the full pat found. A partial boundy might still be in the parser if M_FALSE.
1416 *
1417 * \return parser.
1418 */
1419M_API 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);
1420
1421
1422/*! Read data from the buffer for as long as it matches one of the bytes in the given character set and advance.
1423 * All data is copied into a new memory segment.
1424 *
1425 * Put the resulting bytes in a newly allocated parser.
1426 *
1427 * \param[in,out] parser Parser object.
1428 * \param[in] charset Array of characters that are allowed, NULL terminated.
1429 * \param[in] charset_len Number of characters in the set.
1430 *
1431 * \return parser.
1432 */
1433M_API M_parser_t *M_parser_read_parser_charset(M_parser_t *parser, unsigned const char *charset, size_t charset_len);
1434
1435
1436/*! Create new parser from the buffer for as long as it matches the given predicate function and advance.
1437 * All data is copied into a new memory segment.
1438 *
1439 * Put the resulting bytes in a newly allocated parser.
1440 *
1441 * \param[in,out] parser Parser object.
1442 * \param[in] func Predicate function.
1443 *
1444 * \return parser.
1445 */
1447
1448
1449/*! Create new parser from the buffer for as long as it matches the given predicate function
1450 * up to a given maximum and advance. All data is copied into a new memory segment.
1451 *
1452 * Put the resulting bytes in a newly allocated parser.
1453 *
1454 * \param[in,out] parser Parser object.
1455 * \param[in] func Predicate function.
1456 * \param[in] max Requested length of data to read.
1457 *
1458 * \return parser.
1459 */
1461
1462
1463/*! Create new parser from the buffer for as long as it matches the given predicate function and advance.
1464 * All data is copied into a new memory segment.
1465 *
1466 * Put the resulting bytes in a newly allocated parser.
1467 *
1468 * \param[in,out] parser Parser object.
1469 * \param[in] func Predicate function.
1470 *
1471 * \return parser.
1472 */
1474
1475
1476/*! Create new parser from the buffer for as long as it matches the given predicate function
1477 * up to a given maximum and advance. All data is copied into a new memory segment.
1478 *
1479 * Put the resulting bytes in a newly allocated parser.
1480 *
1481 * \param[in,out] parser Parser object.
1482 * \param[in] func Predicate function.
1483 * \param[in] max Requested length of data to read.
1484 *
1485 * \return parser.
1486 */
1488
1489
1490/*! Create new parser from a marked position until the current parser position, allocates a parser and advance.
1491 * All data is copied into a new memory segment.
1492 *
1493 * \param[in,out] parser Parser object.
1494 *
1495 * \return parser.
1496 */
1498
1499/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
1500
1501/*! Read an STX, ETX, LRC wrapped message.
1502 *
1503 * The first character in the parser must be an STX.
1504 *
1505 * \param[in,out] parser Parser object.
1506 * \param[out] out Parser object with result message.
1507 * \param[in] lrc_frame_chars Framing characters that should be included in LRC calculation.
1508 *
1509 * \return result. On success and LRC calculation failure the message will be returned in the output parser.
1510 * Otherwise the output parser's contents are undefined.
1511 *
1512 * Results M_PARSER_FRAME_ERROR_NO_STX, M_PARSER_FRAME_ERROR_NO_ETX, and M_PARSER_FRAME_ERROR_NO_LRC
1513 * will not advance the parser.
1514 */
1515M_API M_PARSER_FRAME_ERROR M_parser_read_stxetxlrc_message(M_parser_t *parser, M_parser_t **out, M_uint32 lrc_frame_chars);
1516
1517
1518/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
1519
1520/*! Validate the parser matches the given predicate function.
1521 *
1522 * If the input char data is signed, use M_parser_is_chr_predicate() instead.
1523 *
1524 * \param[in] parser Parser object.
1525 * \param[in] len Length to validate. If larger than the parser length the parser length is used.
1526 * \param[in] func Predicate function.
1527 *
1528 * \return M_TRUE if matching. Otherwise M_FALSE.
1529 */
1530M_API M_bool M_parser_is_predicate(const M_parser_t *parser, size_t len, M_parser_predicate_func func);
1531
1532
1533/*! Validate the parser matches the given chr predicate function.
1534 *
1535 * If the input char data is unsigned, use M_parser_is_predicate() instead.
1536 *
1537 * \param[in] parser Parser object.
1538 * \param[in] len Length to validate. If larger than the parser length the parser length is used.
1539 * \param[in] func Char predicate function.
1540 *
1541 * \return M_TRUE if matching. Otherwise M_FALSE.
1542 */
1543M_API M_bool M_parser_is_chr_predicate(const M_parser_t *parser, size_t len, M_chr_predicate_func func);
1544
1545
1546/*! Validate the parser matches the given character set.
1547 *
1548 * \param[in] parser Parser object.
1549 * \param[in] len Length to validate. If larger than the parser length the parser length is used.
1550 * \param[in] charset Character set.
1551 * \param[in] charset_len Length of given character set.
1552 *
1553 * \return M_TRUE if matching. Otherwise M_FALSE.
1554 */
1555M_API M_bool M_parser_is_charset(const M_parser_t *parser, size_t len, const unsigned char *charset, size_t charset_len);
1556
1557
1558/*! Validate the parser matches the given NULL-terminated charset.
1559 *
1560 * \param[in] parser Parser object.
1561 * \param[in] len Length to validate. If larger than the parser length the parser length is used.
1562 * \param[in] charset Character set.
1563 *
1564 * \return M_TRUE if matching. Otherwise M_FALSE.
1565 */
1566M_API M_bool M_parser_is_str_charset(const M_parser_t *parser, size_t len, const char *charset);
1567
1568
1569/*! Validate the parser does not match the given predicate function.
1570 *
1571 * If the input char data is signed, use M_parser_is_not_chr_predicate() instead.
1572 *
1573 * \param[in] parser Parser object.
1574 * \param[in] len Length to validate. If larger than the parser length the parser length is used.
1575 * \param[in] func Predicate function.
1576 *
1577 * \return M_TRUE if not matching. Otherwise M_FALSE. If parser is NULL, len is 0, or func is NULL, this will return M_TRUE.
1578 */
1579M_API M_bool M_parser_is_not_predicate(const M_parser_t *parser, size_t len, M_parser_predicate_func func);
1580
1581
1582/*! Validate the parser does not match the given chr predicate function.
1583 *
1584 * If the input char data is unsigned, use M_parser_is_not_predicate() instead.
1585 *
1586 * \param[in] parser Parser object.
1587 * \param[in] len Length to validate. If larger than the parser length the parser length is used.
1588 * \param[in] func Char predicate function.
1589 *
1590 * \return M_TRUE if not matching. Otherwise M_FALSE. If parser is NULL, len is 0, or func is NULL, this will return M_TRUE.
1591 */
1592M_API M_bool M_parser_is_not_chr_predicate(const M_parser_t *parser, size_t len, M_chr_predicate_func func);
1593
1594
1595/*! Validate the parser does not match the given character set.
1596 *
1597 * \param[in] parser Parser object.
1598 * \param[in] len Length to validate. If larger than the parser length the parser length is used.
1599 * \param[in] charset Character set.
1600 * \param[in] charset_len Length of given character set.
1601 *
1602 * \return M_TRUE if not matching. Otherwise M_FALSE. If parser is NULL, len is 0, charset is NULL, or charset_len is 0, this will return M_TRUE.
1603 */
1604M_API M_bool M_parser_is_not_charset(const M_parser_t *parser, size_t len, const unsigned char *charset, size_t charset_len);
1605
1606
1607/*! Validate the parser does not match the given NULL-terminated charset.
1608 *
1609 * \param[in] parser Parser object.
1610 * \param[in] len Length to validate. If larger than the parser length the parser length is used.
1611 * \param[in] charset Character set.
1612 *
1613 * \return M_TRUE if not matching. Otherwise M_FALSE. If parser is NULL, len is 0, or charset is NULL, this will return M_TRUE.
1614 */
1615M_API M_bool M_parser_is_not_str_charset(const M_parser_t *parser, size_t len, const char *charset);
1616
1617
1618/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
1619
1620/*! Split the data in the parser object by the delimiter specified into
1621 * additional parser objects.
1622 *
1623 * \param[in,out] parser Parser
1624 * \param[in] delim The delimiter to split on
1625 * \param[in] maxcnt Maximum number of objects to create, remaining data will be part of the last object.
1626 * 0 if no maximum.
1627 * \param[in] flags M_PARSER_SPLIT_FLAGS flags controlling behavior of parser
1628 * \param[out] num_output The number of parser objects output
1629 * \return array of parser objects or NULL on failure
1630 */
1631M_API M_parser_t **M_parser_split(M_parser_t *parser, unsigned char delim, size_t maxcnt, M_uint32 flags, size_t *num_output);
1632
1633
1634/*! Split the data in the parser object by the pattern specified into
1635 * additional parser objects.
1636 *
1637 * \param[in,out] parser Parser
1638 * \param[in] pat Sequence of bytes to search for.
1639 * \param[in] pat_len Length of pattern data.
1640 * \param[in] maxcnt Maximum number of objects to create, remaining data will be part of the last object.
1641 * 0 if no maximum.
1642 * \param[in] flags M_PARSER_SPLIT_FLAGS flags controlling behavior of parser
1643 * \param[out] num_output The number of parser objects output
1644 * \return array of parser objects or NULL on failure
1645 */
1646M_API 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);
1647
1648
1649/*! Split the data in the parser object by the pattern specified into
1650 * additional parser objects.
1651 *
1652 * \param[in,out] parser Parser
1653 * \param[in] pat String to search for.
1654 * \param[in] maxcnt Maximum number of objects to create, remaining data will be part of the last object.
1655 * 0 if no maximum.
1656 * \param[in] flags M_PARSER_SPLIT_FLAGS flags controlling behavior of parser
1657 * \param[out] num_output The number of parser objects output
1658 * \return array of parser objects or NULL on failure
1659 */
1660M_API 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);
1661
1662
1663/*! Free child parser objects returned from M_parser_split
1664 * \param[in] parsers Array of parser objects
1665 * \param[in] cnt Count of objects as returned from M_parser_split
1666 */
1667M_API void M_parser_split_free(M_parser_t **parsers, size_t cnt);
1668
1669/*! @} */
1670
1671__END_DECLS
1672
1673#endif /* __M_PARSER_H__ */
struct M_buf M_buf_t
Definition: m_buf.h:77
M_bool(* M_chr_predicate_func)(char c)
Definition: m_chr.h:134
M_DECIMAL_RETVAL
Definition: m_decimal.h:85
Definition: m_decimal.h:78
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_truncate_predicate_max(M_parser_t *parser, M_parser_predicate_func func, size_t max)
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_truncate_chr_predicate(M_parser_t *parser, M_chr_predicate_func func)
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)
M_bool M_parser_truncate(M_parser_t *parser, size_t len)
void M_parser_direct_write_end(M_parser_t *parser, size_t len)
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_truncate_until(M_parser_t *parser, const unsigned char *pat, size_t len, M_bool eat_pat)
char * M_parser_read_strdup_chr_predicate_max(M_parser_t *parser, M_chr_predicate_func func, size_t max)
M_bool M_parser_is_not_charset(const M_parser_t *parser, size_t len, const unsigned char *charset, size_t charset_len)
size_t M_parser_len(const M_parser_t *parser)
size_t M_parser_consume_whitespace(M_parser_t *parser, M_uint32 flags)
size_t M_parser_current_column(const M_parser_t *parser)
M_parser_t * M_parser_read_parser_chr_predicate(M_parser_t *parser, M_parser_predicate_func func)
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)
char * M_parser_read_strdup_not_charset(M_parser_t *parser, const char *charset)
M_parser_t * M_parser_read_parser_chr_predicate_max(M_parser_t *parser, M_parser_predicate_func func, size_t max)
void M_parser_split_free(M_parser_t **parsers, size_t cnt)
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_WHITESPACE_FLAGS
Definition: m_parser.h:67
M_bool M_parser_read_buf(M_parser_t *parser, M_buf_t *buf, size_t len)
M_bool M_parser_read_bytes(M_parser_t *parser, size_t len, unsigned char *buf)
M_parser_t * M_parser_read_parser(M_parser_t *parser, size_t len)
M_parser_t ** M_parser_split(M_parser_t *parser, unsigned char delim, size_t maxcnt, M_uint32 flags, size_t *num_output)
size_t M_parser_consume_str_until(M_parser_t *parser, const char *pat, M_bool eat_pat)
M_bool M_parser_append(M_parser_t *parser, const unsigned char *data, size_t len)
void M_parser_destroy(M_parser_t *parser)
size_t M_parser_consume_str_charset(M_parser_t *parser, const char *charset)
M_PARSER_FRAME_BYES
Definition: m_parser.h:88
M_parser_t * M_parser_read_parser_predicate(M_parser_t *parser, M_parser_predicate_func func)
size_t M_parser_consume_predicate(M_parser_t *parser, M_parser_predicate_func func)
size_t M_parser_read_str_not_charset(M_parser_t *parser, const char *charset, char *buf, size_t buf_len)
char * M_parser_read_strdup(M_parser_t *parser, size_t len)
char * M_parser_read_strdup_charset(M_parser_t *parser, const char *charset)
size_t M_parser_read_buf_not_charset(M_parser_t *parser, M_buf_t *buf, const unsigned char *charset, size_t charset_len)
M_bool M_parser_is_chr_predicate(const M_parser_t *parser, size_t len, M_chr_predicate_func func)
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_consume_chr_predicate(M_parser_t *parser, M_chr_predicate_func func)
M_PARSER_FLAGS
Definition: m_parser.h:59
M_bool M_parser_read_uint_bcd(M_parser_t *parser, size_t len, M_uint64 *integer)
struct M_parser M_parser_t
Definition: m_parser.h:52
size_t M_parser_truncate_charset(M_parser_t *parser, const unsigned char *charset, size_t charset_len)
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_consume_not_charset(M_parser_t *parser, const unsigned char *charset, size_t charset_len)
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)
const unsigned char * M_parser_peek(const M_parser_t *parser)
M_parser_t * M_parser_read_parser_charset(M_parser_t *parser, unsigned const char *charset, size_t charset_len)
M_PARSER_FRAME_ERROR
Definition: m_parser.h:95
size_t M_parser_read_str_until(M_parser_t *parser, char *buf, size_t buf_len, const char *pat, M_bool eat_pat)
M_bool M_parser_is_predicate(const M_parser_t *parser, size_t len, 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_split_pat(M_parser_t *parser, const unsigned char *pat, size_t pat_len, size_t maxcnt, M_uint32 flags, size_t *num_output)
char * M_parser_read_strdup_chr_predicate(M_parser_t *parser, M_chr_predicate_func func)
char * M_parser_read_strdup_mark(M_parser_t *parser)
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)
size_t M_parser_consume_eol(M_parser_t *parser)
M_bool M_parser_peek_bytes(const M_parser_t *parser, size_t len, unsigned char *buf)
char * M_parser_read_strdup_until(M_parser_t *parser, const char *pat, M_bool eat_pat)
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_current_line(const 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)
size_t M_parser_consume_str_boundary(M_parser_t *parser, const char *pat, M_bool eat_pat, M_bool *found)
M_bool M_parser_is_str_charset(const M_parser_t *parser, size_t len, const char *charset)
size_t M_parser_consume_charset(M_parser_t *parser, const unsigned char *charset, size_t charset_len)
M_bool M_parser_read_str(M_parser_t *parser, size_t len, char *buf, size_t buf_len)
M_parser_t * M_parser_create(M_uint32 flags)
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)
M_bool M_parser_read_buf_hex(M_parser_t *parser, M_buf_t *buf, size_t len)
size_t M_parser_consume_chr_predicate_max(M_parser_t *parser, M_chr_predicate_func func, size_t max)
M_bool M_parser_is_not_str_charset(const M_parser_t *parser, size_t len, const char *charset)
M_bool M_parser_peek_byte(const M_parser_t *parser, unsigned char *byte)
size_t M_parser_current_offset(const M_parser_t *parser)
char * M_parser_read_strdup_predicate_max(M_parser_t *parser, M_parser_predicate_func func, size_t max)
M_parser_t * M_parser_create_const(const unsigned char *buf, size_t len, M_uint32 flags)
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)
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_buf_mark(M_parser_t *parser, M_buf_t *buf)
M_bool M_parser_compare_str(const M_parser_t *parser, const char *str, size_t max_len, M_bool casecmp)
size_t M_parser_mark_rewind(M_parser_t *parser)
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_buf_predicate(M_parser_t *parser, M_buf_t *buf, M_parser_predicate_func func)
M_bool M_parser_read_byte(M_parser_t *parser, unsigned char *byte)
size_t M_parser_truncate_whitespace(M_parser_t *parser, M_uint32 flags)
size_t M_parser_read_bytes_mark(M_parser_t *parser, unsigned char *buf, size_t buf_len)
M_bool M_parser_is_not_chr_predicate(const M_parser_t *parser, size_t len, M_chr_predicate_func func)
size_t M_parser_mark_len(const M_parser_t *parser)
M_bool M_parser_is_charset(const M_parser_t *parser, size_t len, const unsigned char *charset, size_t charset_len)
M_parser_t * M_parser_read_parser_mark(M_parser_t *parser)
void M_parser_mark_clear(M_parser_t *parser)
unsigned char * M_parser_direct_write_start(M_parser_t *parser, size_t *len)
void M_parser_mark(M_parser_t *parser)
char * M_parser_read_strdup_boundary(M_parser_t *parser, const char *pat, M_bool eat_pat, M_bool *found)
size_t M_parser_read_buf_max(M_parser_t *parser, M_buf_t *buf, size_t len)
size_t M_parser_consume_str_not_charset(M_parser_t *parser, const char *charset)
char * M_parser_read_strdup_predicate(M_parser_t *parser, M_parser_predicate_func func)
size_t M_parser_reset(M_parser_t *parser)
size_t M_parser_truncate_str_until(M_parser_t *parser, const char *pat, M_bool eat_pat)
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_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_until(M_parser_t *parser, const unsigned char *pat, size_t len, M_bool eat_pat)
enum M_DECIMAL_RETVAL M_parser_read_decimal(M_parser_t *parser, size_t len, M_bool truncate_fail, M_decimal_t *decimal)
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_charset(M_parser_t *parser, const char *charset)
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)
size_t M_parser_truncate_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)
M_bool M_parser_consume(M_parser_t *parser, size_t len)
size_t M_parser_read_bytes_predicate(M_parser_t *parser, M_parser_predicate_func func, unsigned char *buf, size_t buf_len)
M_bool(* M_parser_predicate_func)(unsigned char c)
Definition: m_parser.h:55
char * M_parser_read_strdup_hex(M_parser_t *parser, size_t len)
M_bool M_parser_is_not_predicate(const M_parser_t *parser, size_t len, M_parser_predicate_func func)
size_t M_parser_read_str_mark(M_parser_t *parser, char *buf, size_t buf_len)
const unsigned char * M_parser_peek_mark(const M_parser_t *parser, size_t *len)
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_str_max(M_parser_t *parser, size_t len, char *buf, size_t buf_len)
M_bool M_parser_compare(const M_parser_t *parser, const unsigned char *data, size_t data_len)
M_PARSER_INTEGER_TYPE
Definition: m_parser.h:74
M_PARSER_SPLIT_FLAGS
Definition: m_parser.h:81
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)
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_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)
@ M_PARSER_WHITESPACE_TO_NEWLINE
Definition: m_parser.h:69
@ M_PARSER_WHITESPACE_SPACEONLY
Definition: m_parser.h:70
@ M_PARSER_WHITESPACE_NONE
Definition: m_parser.h:68
@ M_PARSER_FRAME_NONE
Definition: m_parser.h:89
@ M_PARSER_FRAME_STX
Definition: m_parser.h:90
@ M_PARSER_FRAME_ETX
Definition: m_parser.h:91
@ M_PARSER_FLAG_TRACKLINES
Definition: m_parser.h:61
@ M_PARSER_FLAG_NONE
Definition: m_parser.h:60
@ M_PARSER_FRAME_ERROR_SUCCESS
Definition: m_parser.h:96
@ M_PARSER_FRAME_ERROR_NO_LRC
Definition: m_parser.h:100
@ M_PARSER_FRAME_ERROR_INVALID
Definition: m_parser.h:97
@ M_PARSER_FRAME_ERROR_NO_STX
Definition: m_parser.h:98
@ M_PARSER_FRAME_ERROR_LRC_CALC_FAILED
Definition: m_parser.h:101
@ M_PARSER_FRAME_ERROR_NO_ETX
Definition: m_parser.h:99
@ M_PARSER_INTEGER_BIGENDIAN
Definition: m_parser.h:76
@ M_PARSER_INTEGER_LITTLEENDIAN
Definition: m_parser.h:77
@ M_PARSER_INTEGER_ASCII
Definition: m_parser.h:75
@ M_PARSER_SPLIT_FLAG_NODELIM_ERROR
Definition: m_parser.h:83
@ M_PARSER_SPLIT_FLAG_NONE
Definition: m_parser.h:82
@ M_PARSER_SPLIT_FLAG_DONT_TRIM_LAST
Definition: m_parser.h:84