xmlregexp.h 5.0 KB

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