Mercurial > hgrepos > Python2 > PyMuPDF
comparison mupdf-source/thirdparty/extract/src/xml.h @ 2:b50eed0cc0ef upstream
ADD: MuPDF v1.26.7: the MuPDF source as downloaded by a default build of PyMuPDF 1.26.4.
The directory name has changed: no version number in the expanded directory now.
| author | Franz Glasner <fzglas.hg@dom66.de> |
|---|---|
| date | Mon, 15 Sep 2025 11:43:07 +0200 |
| parents | |
| children |
comparison
equal
deleted
inserted
replaced
| 1:1d09e1dec1d9 | 2:b50eed0cc0ef |
|---|---|
| 1 #ifndef ARTIFEX_EXTRACT_XML | |
| 2 #define ARTIFEX_EXTRACT_XML | |
| 3 | |
| 4 /* Only for internal use by extract code. */ | |
| 5 | |
| 6 #include "extract/buffer.h" | |
| 7 | |
| 8 #include "astring.h" | |
| 9 | |
| 10 | |
| 11 /* Things for representing XML. */ | |
| 12 | |
| 13 typedef struct { | |
| 14 char *name; | |
| 15 char *value; | |
| 16 } extract_xml_attribute_t; | |
| 17 | |
| 18 /* Represents a single <...> XML tag plus trailing text. */ | |
| 19 typedef struct { | |
| 20 char *name; | |
| 21 extract_xml_attribute_t *attributes; | |
| 22 int attributes_num; | |
| 23 extract_astring_t text; | |
| 24 } extract_xml_tag_t; | |
| 25 | |
| 26 | |
| 27 /* Initialises tag. Will cause leak if tag contains data - in this case call | |
| 28 extract_xml_tag_free(). */ | |
| 29 void extract_xml_tag_init(extract_xml_tag_t *tag); | |
| 30 | |
| 31 /* Frees tag and then calls extract_xml_tag_init(). */ | |
| 32 void extract_xml_tag_free(extract_alloc_t *alloc, extract_xml_tag_t *tag); | |
| 33 | |
| 34 | |
| 35 /* extract_xml_pparse_*(): simple XML 'pull' parser. | |
| 36 | |
| 37 If <first_line> is not NULL, we require that <buffer> starts with the specified | |
| 38 text. Usually one would include a final newline in <first_line>. | |
| 39 | |
| 40 extract_xml_pparse_init() merely consumes the initial '<'. Thereafter | |
| 41 extract_xml_pparse_next() consumes the next '<' before returning the previous | |
| 42 tag. */ | |
| 43 | |
| 44 /* Opens specified file. | |
| 45 | |
| 46 If first_line is not NULL, we check that it matches the first line in the file. | |
| 47 | |
| 48 Returns -1 with errno=ESRCH if we fail to read the first '<' due to EOF. | |
| 49 */ | |
| 50 int extract_xml_pparse_init(extract_alloc_t *alloc, extract_buffer_t *buffer, const char *first_line); | |
| 51 | |
| 52 | |
| 53 | |
| 54 /* Returns the next XML tag. | |
| 55 | |
| 56 Returns 0 with *out containing next tag; or -1 with errno set if error; or +1 | |
| 57 with errno=ESRCH if EOF. | |
| 58 | |
| 59 If we return 0, we guarantee that out->name points to valid string and that | |
| 60 each item in out->attributes has similarly valid name and value members. | |
| 61 | |
| 62 *out is initially passed to extract_xml_tag_free(), so *out must have been | |
| 63 initialised, e.g. by by extract_xml_tag_init(). */ | |
| 64 int extract_xml_pparse_next(extract_buffer_t *buffer, extract_xml_tag_t *out); | |
| 65 | |
| 66 | |
| 67 /* Returns pointer to value of specified attribute, or NULL if not found. */ | |
| 68 char *extract_xml_tag_attributes_find(extract_xml_tag_t *tag, const char *name); | |
| 69 | |
| 70 /* Finds float value of specified attribute, returning error if not found or | |
| 71 there is trailing text. */ | |
| 72 int extract_xml_tag_attributes_find_float( | |
| 73 extract_xml_tag_t *tag, | |
| 74 const char *name, | |
| 75 float *o_out); | |
| 76 | |
| 77 /* Finds double value of specified attribute, returning error if not found or there is | |
| 78 trailing text. */ | |
| 79 int extract_xml_tag_attributes_find_double( | |
| 80 extract_xml_tag_t *tag, | |
| 81 const char *name, | |
| 82 double *o_out); | |
| 83 | |
| 84 | |
| 85 /* Next few functions write to out-param and return zero on success, else | |
| 86 return -1 with errno set. | |
| 87 | |
| 88 An error is returned if value is out of range or there is any trailing text. */ | |
| 89 | |
| 90 int extract_xml_str_to_llint(const char *text, long long *o_out); | |
| 91 | |
| 92 int extract_xml_str_to_ullint(const char *text, unsigned long long *o_out); | |
| 93 | |
| 94 int extract_xml_str_to_int(const char *text, int *o_out); | |
| 95 | |
| 96 int extract_xml_str_to_uint(const char *text, unsigned *o_out); | |
| 97 | |
| 98 int extract_xml_str_to_size(const char *text, size_t *o_out); | |
| 99 | |
| 100 int extract_xml_str_to_double(const char *text, double *o_out); | |
| 101 | |
| 102 int extract_xml_str_to_float(const char *text, float *o_out); | |
| 103 | |
| 104 | |
| 105 /* Finds int value of specified attribute, returning error if not found. */ | |
| 106 int extract_xml_tag_attributes_find_int( | |
| 107 extract_xml_tag_t *tag, | |
| 108 const char *name, | |
| 109 int *o_out); | |
| 110 | |
| 111 /* Finds unsigned int value of specified attribute, returning error if not | |
| 112 found. */ | |
| 113 int extract_xml_tag_attributes_find_uint( | |
| 114 extract_xml_tag_t *tag, | |
| 115 const char *name, | |
| 116 unsigned *o_out); | |
| 117 | |
| 118 /* Finds unsigned int value of specified attribute, returning error if not | |
| 119 found. */ | |
| 120 int extract_xml_tag_attributes_find_size( | |
| 121 extract_xml_tag_t *tag, | |
| 122 const char *name, | |
| 123 size_t *o_out); | |
| 124 | |
| 125 #endif |
