xmlregexp.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. /*
  2. * Summary: regular expressions handling
  3. * Description: basic API for libxml regular expressions handling used
  4. * for XML Schemas and validation.
  5. *
  6. * Copy: See Copyright for the status of this software.
  7. *
  8. * Author: Daniel Veillard
  9. */
  10. #ifndef __XML_REGEXP_H__
  11. #define __XML_REGEXP_H__
  12. #include <libxml/xmlversion.h>
  13. #ifdef LIBXML_REGEXP_ENABLED
  14. #ifdef __cplusplus
  15. extern "C" {
  16. #endif
  17. /**
  18. * xmlRegexpPtr:
  19. *
  20. * A libxml regular expression, they can actually be far more complex
  21. * thank the POSIX regex expressions.
  22. */
  23. typedef struct _xmlRegexp xmlRegexp;
  24. typedef xmlRegexp *xmlRegexpPtr;
  25. /**
  26. * xmlRegExecCtxtPtr:
  27. *
  28. * A libxml progressive regular expression evaluation context
  29. */
  30. typedef struct _xmlRegExecCtxt xmlRegExecCtxt;
  31. typedef xmlRegExecCtxt *xmlRegExecCtxtPtr;
  32. #ifdef __cplusplus
  33. }
  34. #endif
  35. #include <libxml/tree.h>
  36. #include <libxml/dict.h>
  37. #ifdef __cplusplus
  38. extern "C" {
  39. #endif
  40. /*
  41. * The POSIX like API
  42. */
  43. XMLPUBFUN xmlRegexpPtr XMLCALL
  44. xmlRegexpCompile (const xmlChar *regexp);
  45. XMLPUBFUN void XMLCALL xmlRegFreeRegexp(xmlRegexpPtr regexp);
  46. XMLPUBFUN int XMLCALL
  47. xmlRegexpExec (xmlRegexpPtr comp,
  48. const xmlChar *value);
  49. XMLPUBFUN void XMLCALL
  50. xmlRegexpPrint (FILE *output,
  51. xmlRegexpPtr regexp);
  52. XMLPUBFUN int XMLCALL
  53. xmlRegexpIsDeterminist(xmlRegexpPtr comp);
  54. /**
  55. * xmlRegExecCallbacks:
  56. * @exec: the regular expression context
  57. * @token: the current token string
  58. * @transdata: transition data
  59. * @inputdata: input data
  60. *
  61. * Callback function when doing a transition in the automata
  62. */
  63. typedef void (*xmlRegExecCallbacks) (xmlRegExecCtxtPtr exec,
  64. const xmlChar *token,
  65. void *transdata,
  66. void *inputdata);
  67. /*
  68. * The progressive API
  69. */
  70. XMLPUBFUN xmlRegExecCtxtPtr XMLCALL
  71. xmlRegNewExecCtxt (xmlRegexpPtr comp,
  72. xmlRegExecCallbacks callback,
  73. void *data);
  74. XMLPUBFUN void XMLCALL
  75. xmlRegFreeExecCtxt (xmlRegExecCtxtPtr exec);
  76. XMLPUBFUN int XMLCALL
  77. xmlRegExecPushString(xmlRegExecCtxtPtr exec,
  78. const xmlChar *value,
  79. void *data);
  80. XMLPUBFUN int XMLCALL
  81. xmlRegExecPushString2(xmlRegExecCtxtPtr exec,
  82. const xmlChar *value,
  83. const xmlChar *value2,
  84. void *data);
  85. XMLPUBFUN int XMLCALL
  86. xmlRegExecNextValues(xmlRegExecCtxtPtr exec,
  87. int *nbval,
  88. int *nbneg,
  89. xmlChar **values,
  90. int *terminal);
  91. XMLPUBFUN int XMLCALL
  92. xmlRegExecErrInfo (xmlRegExecCtxtPtr exec,
  93. const xmlChar **string,
  94. int *nbval,
  95. int *nbneg,
  96. xmlChar **values,
  97. int *terminal);
  98. #ifdef LIBXML_EXPR_ENABLED
  99. /*
  100. * Formal regular expression handling
  101. * Its goal is to do some formal work on content models
  102. */
  103. /* expressions are used within a context */
  104. typedef struct _xmlExpCtxt xmlExpCtxt;
  105. typedef xmlExpCtxt *xmlExpCtxtPtr;
  106. XMLPUBFUN void XMLCALL
  107. xmlExpFreeCtxt (xmlExpCtxtPtr ctxt);
  108. XMLPUBFUN xmlExpCtxtPtr XMLCALL
  109. xmlExpNewCtxt (int maxNodes,
  110. xmlDictPtr dict);
  111. XMLPUBFUN int XMLCALL
  112. xmlExpCtxtNbNodes(xmlExpCtxtPtr ctxt);
  113. XMLPUBFUN int XMLCALL
  114. xmlExpCtxtNbCons(xmlExpCtxtPtr ctxt);
  115. /* Expressions are trees but the tree is opaque */
  116. typedef struct _xmlExpNode xmlExpNode;
  117. typedef xmlExpNode *xmlExpNodePtr;
  118. typedef enum {
  119. XML_EXP_EMPTY = 0,
  120. XML_EXP_FORBID = 1,
  121. XML_EXP_ATOM = 2,
  122. XML_EXP_SEQ = 3,
  123. XML_EXP_OR = 4,
  124. XML_EXP_COUNT = 5
  125. } xmlExpNodeType;
  126. /*
  127. * 2 core expressions shared by all for the empty language set
  128. * and for the set with just the empty token
  129. */
  130. XMLPUBVAR xmlExpNodePtr forbiddenExp;
  131. XMLPUBVAR xmlExpNodePtr emptyExp;
  132. /*
  133. * Expressions are reference counted internally
  134. */
  135. XMLPUBFUN void XMLCALL
  136. xmlExpFree (xmlExpCtxtPtr ctxt,
  137. xmlExpNodePtr expr);
  138. XMLPUBFUN void XMLCALL
  139. xmlExpRef (xmlExpNodePtr expr);
  140. /*
  141. * constructors can be either manual or from a string
  142. */
  143. XMLPUBFUN xmlExpNodePtr XMLCALL
  144. xmlExpParse (xmlExpCtxtPtr ctxt,
  145. const char *expr);
  146. XMLPUBFUN xmlExpNodePtr XMLCALL
  147. xmlExpNewAtom (xmlExpCtxtPtr ctxt,
  148. const xmlChar *name,
  149. int len);
  150. XMLPUBFUN xmlExpNodePtr XMLCALL
  151. xmlExpNewOr (xmlExpCtxtPtr ctxt,
  152. xmlExpNodePtr left,
  153. xmlExpNodePtr right);
  154. XMLPUBFUN xmlExpNodePtr XMLCALL
  155. xmlExpNewSeq (xmlExpCtxtPtr ctxt,
  156. xmlExpNodePtr left,
  157. xmlExpNodePtr right);
  158. XMLPUBFUN xmlExpNodePtr XMLCALL
  159. xmlExpNewRange (xmlExpCtxtPtr ctxt,
  160. xmlExpNodePtr subset,
  161. int min,
  162. int max);
  163. /*
  164. * The really interesting APIs
  165. */
  166. XMLPUBFUN int XMLCALL
  167. xmlExpIsNillable(xmlExpNodePtr expr);
  168. XMLPUBFUN int XMLCALL
  169. xmlExpMaxToken (xmlExpNodePtr expr);
  170. XMLPUBFUN int XMLCALL
  171. xmlExpGetLanguage(xmlExpCtxtPtr ctxt,
  172. xmlExpNodePtr expr,
  173. const xmlChar**langList,
  174. int len);
  175. XMLPUBFUN int XMLCALL
  176. xmlExpGetStart (xmlExpCtxtPtr ctxt,
  177. xmlExpNodePtr expr,
  178. const xmlChar**tokList,
  179. int len);
  180. XMLPUBFUN xmlExpNodePtr XMLCALL
  181. xmlExpStringDerive(xmlExpCtxtPtr ctxt,
  182. xmlExpNodePtr expr,
  183. const xmlChar *str,
  184. int len);
  185. XMLPUBFUN xmlExpNodePtr XMLCALL
  186. xmlExpExpDerive (xmlExpCtxtPtr ctxt,
  187. xmlExpNodePtr expr,
  188. xmlExpNodePtr sub);
  189. XMLPUBFUN int XMLCALL
  190. xmlExpSubsume (xmlExpCtxtPtr ctxt,
  191. xmlExpNodePtr expr,
  192. xmlExpNodePtr sub);
  193. XMLPUBFUN void XMLCALL
  194. xmlExpDump (xmlBufferPtr buf,
  195. xmlExpNodePtr expr);
  196. #endif /* LIBXML_EXPR_ENABLED */
  197. #ifdef __cplusplus
  198. }
  199. #endif
  200. #endif /* LIBXML_REGEXP_ENABLED */
  201. #endif /*__XML_REGEXP_H__ */