1 /* libxml2 - Library for parsing XML documents 2 * Copyright (C) 2006-2019 Free Software Foundation, Inc. 3 * 4 * This file is not part of the GNU gettext program, but is used with 5 * GNU gettext. 6 * 7 * The original copyright notice is as follows: 8 */ 9 10 /* 11 * Copyright (C) 1998-2012 Daniel Veillard. All Rights Reserved. 12 * 13 * Permission is hereby granted, free of charge, to any person obtaining a copy 14 * of this software and associated documentation files (the "Software"), to deal 15 * in the Software without restriction, including without limitation the rights 16 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 17 * copies of the Software, and to permit persons to whom the Software is fur- 18 * nished to do so, subject to the following conditions: 19 * 20 * The above copyright notice and this permission notice shall be included in 21 * all copies or substantial portions of the Software. 22 * 23 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 24 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FIT- 25 * NESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 26 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 27 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 28 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 29 * THE SOFTWARE. 30 * 31 * Author: Daniel Veillard 32 */ 33 34 /* 35 * Summary: regular expressions handling 36 * Description: basic API for libxml regular expressions handling used 37 * for XML Schemas and validation. 38 */ 39 40 #ifndef __XML_REGEXP_H__ 41 #define __XML_REGEXP_H__ 42 43 #include <libxml/xmlversion.h> 44 45 #ifdef LIBXML_REGEXP_ENABLED 46 47 #ifdef __cplusplus 48 extern "C" { 49 #endif 50 51 /** 52 * xmlRegexpPtr: 53 * 54 * A libxml regular expression, they can actually be far more complex 55 * thank the POSIX regex expressions. 56 */ 57 typedef struct _xmlRegexp xmlRegexp; 58 typedef xmlRegexp *xmlRegexpPtr; 59 60 /** 61 * xmlRegExecCtxtPtr: 62 * 63 * A libxml progressive regular expression evaluation context 64 */ 65 typedef struct _xmlRegExecCtxt xmlRegExecCtxt; 66 typedef xmlRegExecCtxt *xmlRegExecCtxtPtr; 67 68 #ifdef __cplusplus 69 } 70 #endif 71 #include <libxml/tree.h> 72 #include <libxml/dict.h> 73 #ifdef __cplusplus 74 extern "C" { 75 #endif 76 77 /* 78 * The POSIX like API 79 */ 80 XMLPUBFUN xmlRegexpPtr XMLCALL 81 xmlRegexpCompile (const xmlChar *regexp); 82 XMLPUBFUN void XMLCALL xmlRegFreeRegexp(xmlRegexpPtr regexp); 83 XMLPUBFUN int XMLCALL 84 xmlRegexpExec (xmlRegexpPtr comp, 85 const xmlChar *value); 86 XMLPUBFUN void XMLCALL 87 xmlRegexpPrint (FILE *output, 88 xmlRegexpPtr regexp); 89 XMLPUBFUN int XMLCALL 90 xmlRegexpIsDeterminist(xmlRegexpPtr comp); 91 92 /** 93 * xmlRegExecCallbacks: 94 * @exec: the regular expression context 95 * @token: the current token string 96 * @transdata: transition data 97 * @inputdata: input data 98 * 99 * Callback function when doing a transition in the automata 100 */ 101 typedef void (*xmlRegExecCallbacks) (xmlRegExecCtxtPtr exec, 102 const xmlChar *token, 103 void *transdata, 104 void *inputdata); 105 106 /* 107 * The progressive API 108 */ 109 XMLPUBFUN xmlRegExecCtxtPtr XMLCALL 110 xmlRegNewExecCtxt (xmlRegexpPtr comp, 111 xmlRegExecCallbacks callback, 112 void *data); 113 XMLPUBFUN void XMLCALL 114 xmlRegFreeExecCtxt (xmlRegExecCtxtPtr exec); 115 XMLPUBFUN int XMLCALL 116 xmlRegExecPushString(xmlRegExecCtxtPtr exec, 117 const xmlChar *value, 118 void *data); 119 XMLPUBFUN int XMLCALL 120 xmlRegExecPushString2(xmlRegExecCtxtPtr exec, 121 const xmlChar *value, 122 const xmlChar *value2, 123 void *data); 124 125 XMLPUBFUN int XMLCALL 126 xmlRegExecNextValues(xmlRegExecCtxtPtr exec, 127 int *nbval, 128 int *nbneg, 129 xmlChar **values, 130 int *terminal); 131 XMLPUBFUN int XMLCALL 132 xmlRegExecErrInfo (xmlRegExecCtxtPtr exec, 133 const xmlChar **string, 134 int *nbval, 135 int *nbneg, 136 xmlChar **values, 137 int *terminal); 138 #ifdef LIBXML_EXPR_ENABLED 139 /* 140 * Formal regular expression handling 141 * Its goal is to do some formal work on content models 142 */ 143 144 /* expressions are used within a context */ 145 typedef struct _xmlExpCtxt xmlExpCtxt; 146 typedef xmlExpCtxt *xmlExpCtxtPtr; 147 148 XMLPUBFUN void XMLCALL 149 xmlExpFreeCtxt (xmlExpCtxtPtr ctxt); 150 XMLPUBFUN xmlExpCtxtPtr XMLCALL 151 xmlExpNewCtxt (int maxNodes, 152 xmlDictPtr dict); 153 154 XMLPUBFUN int XMLCALL 155 xmlExpCtxtNbNodes(xmlExpCtxtPtr ctxt); 156 XMLPUBFUN int XMLCALL 157 xmlExpCtxtNbCons(xmlExpCtxtPtr ctxt); 158 159 /* Expressions are trees but the tree is opaque */ 160 typedef struct _xmlExpNode xmlExpNode; 161 typedef xmlExpNode *xmlExpNodePtr; 162 163 typedef enum { 164 XML_EXP_EMPTY = 0, 165 XML_EXP_FORBID = 1, 166 XML_EXP_ATOM = 2, 167 XML_EXP_SEQ = 3, 168 XML_EXP_OR = 4, 169 XML_EXP_COUNT = 5 170 } xmlExpNodeType; 171 172 /* 173 * 2 core expressions shared by all for the empty language set 174 * and for the set with just the empty token 175 */ 176 XMLPUBVAR xmlExpNodePtr forbiddenExp; 177 XMLPUBVAR xmlExpNodePtr emptyExp; 178 179 /* 180 * Expressions are reference counted internally 181 */ 182 XMLPUBFUN void XMLCALL 183 xmlExpFree (xmlExpCtxtPtr ctxt, 184 xmlExpNodePtr expr); 185 XMLPUBFUN void XMLCALL 186 xmlExpRef (xmlExpNodePtr expr); 187 188 /* 189 * constructors can be either manual or from a string 190 */ 191 XMLPUBFUN xmlExpNodePtr XMLCALL 192 xmlExpParse (xmlExpCtxtPtr ctxt, 193 const char *expr); 194 XMLPUBFUN xmlExpNodePtr XMLCALL 195 xmlExpNewAtom (xmlExpCtxtPtr ctxt, 196 const xmlChar *name, 197 int len); 198 XMLPUBFUN xmlExpNodePtr XMLCALL 199 xmlExpNewOr (xmlExpCtxtPtr ctxt, 200 xmlExpNodePtr left, 201 xmlExpNodePtr right); 202 XMLPUBFUN xmlExpNodePtr XMLCALL 203 xmlExpNewSeq (xmlExpCtxtPtr ctxt, 204 xmlExpNodePtr left, 205 xmlExpNodePtr right); 206 XMLPUBFUN xmlExpNodePtr XMLCALL 207 xmlExpNewRange (xmlExpCtxtPtr ctxt, 208 xmlExpNodePtr subset, 209 int min, 210 int max); 211 /* 212 * The really interesting APIs 213 */ 214 XMLPUBFUN int XMLCALL 215 xmlExpIsNillable(xmlExpNodePtr expr); 216 XMLPUBFUN int XMLCALL 217 xmlExpMaxToken (xmlExpNodePtr expr); 218 XMLPUBFUN int XMLCALL 219 xmlExpGetLanguage(xmlExpCtxtPtr ctxt, 220 xmlExpNodePtr expr, 221 const xmlChar**langList, 222 int len); 223 XMLPUBFUN int XMLCALL 224 xmlExpGetStart (xmlExpCtxtPtr ctxt, 225 xmlExpNodePtr expr, 226 const xmlChar**tokList, 227 int len); 228 XMLPUBFUN xmlExpNodePtr XMLCALL 229 xmlExpStringDerive(xmlExpCtxtPtr ctxt, 230 xmlExpNodePtr expr, 231 const xmlChar *str, 232 int len); 233 XMLPUBFUN xmlExpNodePtr XMLCALL 234 xmlExpExpDerive (xmlExpCtxtPtr ctxt, 235 xmlExpNodePtr expr, 236 xmlExpNodePtr sub); 237 XMLPUBFUN int XMLCALL 238 xmlExpSubsume (xmlExpCtxtPtr ctxt, 239 xmlExpNodePtr expr, 240 xmlExpNodePtr sub); 241 XMLPUBFUN void XMLCALL 242 xmlExpDump (xmlBufferPtr buf, 243 xmlExpNodePtr expr); 244 #endif /* LIBXML_EXPR_ENABLED */ 245 #ifdef __cplusplus 246 } 247 #endif 248 249 #endif /* LIBXML_REGEXP_ENABLED */ 250 251 #endif /*__XML_REGEXP_H__ */ 252