| OLD | NEW |
| 1 /* | 1 /* |
| 2 * regexp.c: generic and extensible Regular Expression engine | 2 * regexp.c: generic and extensible Regular Expression engine |
| 3 * | 3 * |
| 4 * Basically designed with the purpose of compiling regexps for | 4 * Basically designed with the purpose of compiling regexps for |
| 5 * the variety of validation/shemas mechanisms now available in | 5 * the variety of validation/shemas mechanisms now available in |
| 6 * XML related specifications these include: | 6 * XML related specifications these include: |
| 7 * - XML-1.0 DTD validation | 7 * - XML-1.0 DTD validation |
| 8 * - XML Schemas structure part 1 | 8 * - XML Schemas structure part 1 |
| 9 * - XML Schemas Datatypes part 2 especially Appendix F | 9 * - XML Schemas Datatypes part 2 especially Appendix F |
| 10 * - RELAX-NG/TREX i.e. the counter proposal | 10 * - RELAX-NG/TREX i.e. the counter proposal |
| (...skipping 1526 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1537 * @from: the from state | 1537 * @from: the from state |
| 1538 * @to: the target state or NULL for building a new one | 1538 * @to: the target state or NULL for building a new one |
| 1539 * @atom: the atom generating the transition | 1539 * @atom: the atom generating the transition |
| 1540 * | 1540 * |
| 1541 * Returns 0 if success and -1 in case of error. | 1541 * Returns 0 if success and -1 in case of error. |
| 1542 */ | 1542 */ |
| 1543 static int | 1543 static int |
| 1544 xmlFAGenerateTransitions(xmlRegParserCtxtPtr ctxt, xmlRegStatePtr from, | 1544 xmlFAGenerateTransitions(xmlRegParserCtxtPtr ctxt, xmlRegStatePtr from, |
| 1545 xmlRegStatePtr to, xmlRegAtomPtr atom) { | 1545 xmlRegStatePtr to, xmlRegAtomPtr atom) { |
| 1546 xmlRegStatePtr end; | 1546 xmlRegStatePtr end; |
| 1547 int nullable = 0; |
| 1547 | 1548 |
| 1548 if (atom == NULL) { | 1549 if (atom == NULL) { |
| 1549 ERROR("genrate transition: atom == NULL"); | 1550 ERROR("genrate transition: atom == NULL"); |
| 1550 return(-1); | 1551 return(-1); |
| 1551 } | 1552 } |
| 1552 if (atom->type == XML_REGEXP_SUBREG) { | 1553 if (atom->type == XML_REGEXP_SUBREG) { |
| 1553 /* | 1554 /* |
| 1554 * this is a subexpression handling one should not need to | 1555 * this is a subexpression handling one should not need to |
| 1555 * create a new node except for XML_REGEXP_QUANT_RANGE. | 1556 * create a new node except for XML_REGEXP_QUANT_RANGE. |
| 1556 */ | 1557 */ |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1723 xmlRegStatePush(ctxt, tmp); | 1724 xmlRegStatePush(ctxt, tmp); |
| 1724 else { | 1725 else { |
| 1725 return(-1); | 1726 return(-1); |
| 1726 } | 1727 } |
| 1727 xmlFAGenerateEpsilonTransition(ctxt, tmp, to); | 1728 xmlFAGenerateEpsilonTransition(ctxt, tmp, to); |
| 1728 to = tmp; | 1729 to = tmp; |
| 1729 } | 1730 } |
| 1730 if (xmlRegAtomPush(ctxt, atom) < 0) { | 1731 if (xmlRegAtomPush(ctxt, atom) < 0) { |
| 1731 return(-1); | 1732 return(-1); |
| 1732 } | 1733 } |
| 1734 if ((atom->quant == XML_REGEXP_QUANT_RANGE) && |
| 1735 (atom->min == 0) && (atom->max > 0)) { |
| 1736 nullable = 1; |
| 1737 atom->min = 1; |
| 1738 if (atom->max == 1) |
| 1739 atom->quant = XML_REGEXP_QUANT_OPT; |
| 1740 } |
| 1733 xmlRegStateAddTrans(ctxt, from, atom, to, -1, -1); | 1741 xmlRegStateAddTrans(ctxt, from, atom, to, -1, -1); |
| 1734 ctxt->state = end; | 1742 ctxt->state = end; |
| 1735 switch (atom->quant) { | 1743 switch (atom->quant) { |
| 1736 case XML_REGEXP_QUANT_OPT: | 1744 case XML_REGEXP_QUANT_OPT: |
| 1737 atom->quant = XML_REGEXP_QUANT_ONCE; | 1745 atom->quant = XML_REGEXP_QUANT_ONCE; |
| 1738 xmlFAGenerateEpsilonTransition(ctxt, from, to); | 1746 xmlFAGenerateEpsilonTransition(ctxt, from, to); |
| 1739 break; | 1747 break; |
| 1740 case XML_REGEXP_QUANT_MULT: | 1748 case XML_REGEXP_QUANT_MULT: |
| 1741 atom->quant = XML_REGEXP_QUANT_ONCE; | 1749 atom->quant = XML_REGEXP_QUANT_ONCE; |
| 1742 xmlFAGenerateEpsilonTransition(ctxt, from, to); | 1750 xmlFAGenerateEpsilonTransition(ctxt, from, to); |
| 1743 xmlRegStateAddTrans(ctxt, to, atom, to, -1, -1); | 1751 xmlRegStateAddTrans(ctxt, to, atom, to, -1, -1); |
| 1744 break; | 1752 break; |
| 1745 case XML_REGEXP_QUANT_PLUS: | 1753 case XML_REGEXP_QUANT_PLUS: |
| 1746 atom->quant = XML_REGEXP_QUANT_ONCE; | 1754 atom->quant = XML_REGEXP_QUANT_ONCE; |
| 1747 xmlRegStateAddTrans(ctxt, to, atom, to, -1, -1); | 1755 xmlRegStateAddTrans(ctxt, to, atom, to, -1, -1); |
| 1748 break; | 1756 break; |
| 1749 case XML_REGEXP_QUANT_RANGE: | 1757 case XML_REGEXP_QUANT_RANGE: |
| 1750 #if DV_test | 1758 » if (nullable) |
| 1751 » if (atom->min == 0) { | |
| 1752 xmlFAGenerateEpsilonTransition(ctxt, from, to); | 1759 xmlFAGenerateEpsilonTransition(ctxt, from, to); |
| 1753 } | |
| 1754 #endif | |
| 1755 break; | 1760 break; |
| 1756 default: | 1761 default: |
| 1757 break; | 1762 break; |
| 1758 } | 1763 } |
| 1759 return(0); | 1764 return(0); |
| 1760 } | 1765 } |
| 1761 | 1766 |
| 1762 /** | 1767 /** |
| 1763 * xmlFAReduceEpsilonTransitions: | 1768 * xmlFAReduceEpsilonTransitions: |
| 1764 * @ctxt: a regexp parser context | 1769 * @ctxt: a regexp parser context |
| (...skipping 4573 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6338 int maxNodes; | 6343 int maxNodes; |
| 6339 const char *expr; | 6344 const char *expr; |
| 6340 const char *cur; | 6345 const char *cur; |
| 6341 int nb_cons; | 6346 int nb_cons; |
| 6342 int tabSize; | 6347 int tabSize; |
| 6343 }; | 6348 }; |
| 6344 | 6349 |
| 6345 /** | 6350 /** |
| 6346 * xmlExpNewCtxt: | 6351 * xmlExpNewCtxt: |
| 6347 * @maxNodes: the maximum number of nodes | 6352 * @maxNodes: the maximum number of nodes |
| 6348 * @dict: optional dictionnary to use internally | 6353 * @dict: optional dictionary to use internally |
| 6349 * | 6354 * |
| 6350 * Creates a new context for manipulating expressions | 6355 * Creates a new context for manipulating expressions |
| 6351 * | 6356 * |
| 6352 * Returns the context or NULL in case of error | 6357 * Returns the context or NULL in case of error |
| 6353 */ | 6358 */ |
| 6354 xmlExpCtxtPtr | 6359 xmlExpCtxtPtr |
| 6355 xmlExpNewCtxt(int maxNodes, xmlDictPtr dict) { | 6360 xmlExpNewCtxt(int maxNodes, xmlDictPtr dict) { |
| 6356 xmlExpCtxtPtr ret; | 6361 xmlExpCtxtPtr ret; |
| 6357 int size = 256; | 6362 int size = 256; |
| 6358 | 6363 |
| (...skipping 838 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7197 */ | 7202 */ |
| 7198 xmlExpNodePtr | 7203 xmlExpNodePtr |
| 7199 xmlExpStringDerive(xmlExpCtxtPtr ctxt, xmlExpNodePtr exp, | 7204 xmlExpStringDerive(xmlExpCtxtPtr ctxt, xmlExpNodePtr exp, |
| 7200 const xmlChar *str, int len) { | 7205 const xmlChar *str, int len) { |
| 7201 const xmlChar *input; | 7206 const xmlChar *input; |
| 7202 | 7207 |
| 7203 if ((exp == NULL) || (ctxt == NULL) || (str == NULL)) { | 7208 if ((exp == NULL) || (ctxt == NULL) || (str == NULL)) { |
| 7204 return(NULL); | 7209 return(NULL); |
| 7205 } | 7210 } |
| 7206 /* | 7211 /* |
| 7207 * check the string is in the dictionnary, if yes use an interned | 7212 * check the string is in the dictionary, if yes use an interned |
| 7208 * copy, otherwise we know it's not an acceptable input | 7213 * copy, otherwise we know it's not an acceptable input |
| 7209 */ | 7214 */ |
| 7210 input = xmlDictExists(ctxt->dict, str, len); | 7215 input = xmlDictExists(ctxt->dict, str, len); |
| 7211 if (input == NULL) { | 7216 if (input == NULL) { |
| 7212 return(forbiddenExp); | 7217 return(forbiddenExp); |
| 7213 } | 7218 } |
| 7214 return(xmlExpStringDeriveInt(ctxt, exp, input)); | 7219 return(xmlExpStringDeriveInt(ctxt, exp, input)); |
| 7215 } | 7220 } |
| 7216 | 7221 |
| 7217 static int | 7222 static int |
| (...skipping 940 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8158 xmlExpCtxtNbCons(xmlExpCtxtPtr ctxt) { | 8163 xmlExpCtxtNbCons(xmlExpCtxtPtr ctxt) { |
| 8159 if (ctxt == NULL) | 8164 if (ctxt == NULL) |
| 8160 return(-1); | 8165 return(-1); |
| 8161 return(ctxt->nb_cons); | 8166 return(ctxt->nb_cons); |
| 8162 } | 8167 } |
| 8163 | 8168 |
| 8164 #endif /* LIBXML_EXPR_ENABLED */ | 8169 #endif /* LIBXML_EXPR_ENABLED */ |
| 8165 #define bottom_xmlregexp | 8170 #define bottom_xmlregexp |
| 8166 #include "elfgcchack.h" | 8171 #include "elfgcchack.h" |
| 8167 #endif /* LIBXML_REGEXP_ENABLED */ | 8172 #endif /* LIBXML_REGEXP_ENABLED */ |
| OLD | NEW |