OLD | NEW |
1 /* | 1 /* |
2 * xpointer.c : Code to handle XML Pointer | 2 * xpointer.c : Code to handle XML Pointer |
3 * | 3 * |
4 * Base implementation was made accordingly to | 4 * Base implementation was made accordingly to |
5 * W3C Candidate Recommendation 7 June 2000 | 5 * W3C Candidate Recommendation 7 June 2000 |
6 * http://www.w3.org/TR/2000/CR-xptr-20000607 | 6 * http://www.w3.org/TR/2000/CR-xptr-20000607 |
7 * | 7 * |
8 * Added support for the element() scheme described in: | 8 * Added support for the element() scheme described in: |
9 * W3C Proposed Recommendation 13 November 2002 | 9 * W3C Proposed Recommendation 13 November 2002 |
10 * http://www.w3.org/TR/2002/PR-xptr-element-20021113/ | 10 * http://www.w3.org/TR/2002/PR-xptr-element-20021113/ |
(...skipping 1134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1145 * Parse and evaluate a Full XPtr i.e. possibly a cascade of XPath based | 1145 * Parse and evaluate a Full XPtr i.e. possibly a cascade of XPath based |
1146 * expressions or other schemes. | 1146 * expressions or other schemes. |
1147 */ | 1147 */ |
1148 static void | 1148 static void |
1149 xmlXPtrEvalFullXPtr(xmlXPathParserContextPtr ctxt, xmlChar *name) { | 1149 xmlXPtrEvalFullXPtr(xmlXPathParserContextPtr ctxt, xmlChar *name) { |
1150 if (name == NULL) | 1150 if (name == NULL) |
1151 name = xmlXPathParseName(ctxt); | 1151 name = xmlXPathParseName(ctxt); |
1152 if (name == NULL) | 1152 if (name == NULL) |
1153 XP_ERROR(XPATH_EXPR_ERROR); | 1153 XP_ERROR(XPATH_EXPR_ERROR); |
1154 while (name != NULL) { | 1154 while (name != NULL) { |
| 1155 ctxt->error = XPATH_EXPRESSION_OK; |
1155 xmlXPtrEvalXPtrPart(ctxt, name); | 1156 xmlXPtrEvalXPtrPart(ctxt, name); |
1156 | 1157 |
1157 /* in case of syntax error, break here */ | 1158 /* in case of syntax error, break here */ |
1158 » if (ctxt->error != XPATH_EXPRESSION_OK) | 1159 » if ((ctxt->error != XPATH_EXPRESSION_OK) && |
| 1160 (ctxt->error != XML_XPTR_UNKNOWN_SCHEME)) |
1159 return; | 1161 return; |
1160 | 1162 |
1161 /* | 1163 /* |
1162 * If the returned value is a non-empty nodeset | 1164 * If the returned value is a non-empty nodeset |
1163 * or location set, return here. | 1165 * or location set, return here. |
1164 */ | 1166 */ |
1165 if (ctxt->value != NULL) { | 1167 if (ctxt->value != NULL) { |
1166 xmlXPathObjectPtr obj = ctxt->value; | 1168 xmlXPathObjectPtr obj = ctxt->value; |
1167 | 1169 |
1168 switch (obj->type) { | 1170 switch (obj->type) { |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1292 XP_ERROR(XPATH_EXPR_ERROR); | 1294 XP_ERROR(XPATH_EXPR_ERROR); |
1293 } | 1295 } |
1294 | 1296 |
1295 | 1297 |
1296 /************************************************************************ | 1298 /************************************************************************ |
1297 * * | 1299 * * |
1298 * General routines * | 1300 * General routines * |
1299 * * | 1301 * * |
1300 ************************************************************************/ | 1302 ************************************************************************/ |
1301 | 1303 |
| 1304 static |
1302 void xmlXPtrStringRangeFunction(xmlXPathParserContextPtr ctxt, int nargs); | 1305 void xmlXPtrStringRangeFunction(xmlXPathParserContextPtr ctxt, int nargs); |
| 1306 static |
1303 void xmlXPtrStartPointFunction(xmlXPathParserContextPtr ctxt, int nargs); | 1307 void xmlXPtrStartPointFunction(xmlXPathParserContextPtr ctxt, int nargs); |
| 1308 static |
1304 void xmlXPtrEndPointFunction(xmlXPathParserContextPtr ctxt, int nargs); | 1309 void xmlXPtrEndPointFunction(xmlXPathParserContextPtr ctxt, int nargs); |
| 1310 static |
1305 void xmlXPtrHereFunction(xmlXPathParserContextPtr ctxt, int nargs); | 1311 void xmlXPtrHereFunction(xmlXPathParserContextPtr ctxt, int nargs); |
| 1312 static |
1306 void xmlXPtrOriginFunction(xmlXPathParserContextPtr ctxt, int nargs); | 1313 void xmlXPtrOriginFunction(xmlXPathParserContextPtr ctxt, int nargs); |
| 1314 static |
1307 void xmlXPtrRangeInsideFunction(xmlXPathParserContextPtr ctxt, int nargs); | 1315 void xmlXPtrRangeInsideFunction(xmlXPathParserContextPtr ctxt, int nargs); |
| 1316 static |
1308 void xmlXPtrRangeFunction(xmlXPathParserContextPtr ctxt, int nargs); | 1317 void xmlXPtrRangeFunction(xmlXPathParserContextPtr ctxt, int nargs); |
1309 | 1318 |
1310 /** | 1319 /** |
1311 * xmlXPtrNewContext: | 1320 * xmlXPtrNewContext: |
1312 * @doc: the XML document | 1321 * @doc: the XML document |
1313 * @here: the node that directly contains the XPointer being evaluated or NULL | 1322 * @here: the node that directly contains the XPointer being evaluated or NULL |
1314 * @origin: the element from which a user or program initiated traversal of | 1323 * @origin: the element from which a user or program initiated traversal of |
1315 * the link, or NULL. | 1324 * the link, or NULL. |
1316 * | 1325 * |
1317 * Create a new XPointer context | 1326 * Create a new XPointer context |
(...skipping 407 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1725 } | 1734 } |
1726 | 1735 |
1727 /** | 1736 /** |
1728 * xmlXPtrHereFunction: | 1737 * xmlXPtrHereFunction: |
1729 * @ctxt: the XPointer Parser context | 1738 * @ctxt: the XPointer Parser context |
1730 * @nargs: the number of args | 1739 * @nargs: the number of args |
1731 * | 1740 * |
1732 * Function implementing here() operation | 1741 * Function implementing here() operation |
1733 * as described in 5.4.3 | 1742 * as described in 5.4.3 |
1734 */ | 1743 */ |
1735 void | 1744 static void |
1736 xmlXPtrHereFunction(xmlXPathParserContextPtr ctxt, int nargs) { | 1745 xmlXPtrHereFunction(xmlXPathParserContextPtr ctxt, int nargs) { |
1737 CHECK_ARITY(0); | 1746 CHECK_ARITY(0); |
1738 | 1747 |
1739 if (ctxt->context->here == NULL) | 1748 if (ctxt->context->here == NULL) |
1740 XP_ERROR(XPTR_SYNTAX_ERROR); | 1749 XP_ERROR(XPTR_SYNTAX_ERROR); |
1741 | 1750 |
1742 valuePush(ctxt, xmlXPtrNewLocationSetNodes(ctxt->context->here, NULL)); | 1751 valuePush(ctxt, xmlXPtrNewLocationSetNodes(ctxt->context->here, NULL)); |
1743 } | 1752 } |
1744 | 1753 |
1745 /** | 1754 /** |
1746 * xmlXPtrOriginFunction: | 1755 * xmlXPtrOriginFunction: |
1747 * @ctxt: the XPointer Parser context | 1756 * @ctxt: the XPointer Parser context |
1748 * @nargs: the number of args | 1757 * @nargs: the number of args |
1749 * | 1758 * |
1750 * Function implementing origin() operation | 1759 * Function implementing origin() operation |
1751 * as described in 5.4.3 | 1760 * as described in 5.4.3 |
1752 */ | 1761 */ |
1753 void | 1762 static void |
1754 xmlXPtrOriginFunction(xmlXPathParserContextPtr ctxt, int nargs) { | 1763 xmlXPtrOriginFunction(xmlXPathParserContextPtr ctxt, int nargs) { |
1755 CHECK_ARITY(0); | 1764 CHECK_ARITY(0); |
1756 | 1765 |
1757 if (ctxt->context->origin == NULL) | 1766 if (ctxt->context->origin == NULL) |
1758 XP_ERROR(XPTR_SYNTAX_ERROR); | 1767 XP_ERROR(XPTR_SYNTAX_ERROR); |
1759 | 1768 |
1760 valuePush(ctxt, xmlXPtrNewLocationSetNodes(ctxt->context->origin, NULL)); | 1769 valuePush(ctxt, xmlXPtrNewLocationSetNodes(ctxt->context->origin, NULL)); |
1761 } | 1770 } |
1762 | 1771 |
1763 /** | 1772 /** |
(...skipping 12 matching lines...) Expand all Loading... |
1776 * | 1785 * |
1777 * - If x is of type point, the start point is x. | 1786 * - If x is of type point, the start point is x. |
1778 * - If x is of type range, the start point is the start point of x. | 1787 * - If x is of type range, the start point is the start point of x. |
1779 * - If x is of type root, element, text, comment, or processing instruction, | 1788 * - If x is of type root, element, text, comment, or processing instruction, |
1780 * - the container node of the start point is x and the index is 0. | 1789 * - the container node of the start point is x and the index is 0. |
1781 * - If x is of type attribute or namespace, the function must signal a | 1790 * - If x is of type attribute or namespace, the function must signal a |
1782 * syntax error. | 1791 * syntax error. |
1783 * ---------------- | 1792 * ---------------- |
1784 * | 1793 * |
1785 */ | 1794 */ |
1786 void | 1795 static void |
1787 xmlXPtrStartPointFunction(xmlXPathParserContextPtr ctxt, int nargs) { | 1796 xmlXPtrStartPointFunction(xmlXPathParserContextPtr ctxt, int nargs) { |
1788 xmlXPathObjectPtr tmp, obj, point; | 1797 xmlXPathObjectPtr tmp, obj, point; |
1789 xmlLocationSetPtr newset = NULL; | 1798 xmlLocationSetPtr newset = NULL; |
1790 xmlLocationSetPtr oldset = NULL; | 1799 xmlLocationSetPtr oldset = NULL; |
1791 | 1800 |
1792 CHECK_ARITY(1); | 1801 CHECK_ARITY(1); |
1793 if ((ctxt->value == NULL) || | 1802 if ((ctxt->value == NULL) || |
1794 ((ctxt->value->type != XPATH_LOCATIONSET) && | 1803 ((ctxt->value->type != XPATH_LOCATIONSET) && |
1795 (ctxt->value->type != XPATH_NODESET))) | 1804 (ctxt->value->type != XPATH_NODESET))) |
1796 XP_ERROR(XPATH_INVALID_TYPE) | 1805 XP_ERROR(XPATH_INVALID_TYPE) |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1870 * - If x is of type range, the resulting point is the end point of x. | 1879 * - If x is of type range, the resulting point is the end point of x. |
1871 * - If x is of type root or element, the container node of the resulting | 1880 * - If x is of type root or element, the container node of the resulting |
1872 * point is x and the index is the number of location children of x. | 1881 * point is x and the index is the number of location children of x. |
1873 * - If x is of type text, comment, or processing instruction, the container | 1882 * - If x is of type text, comment, or processing instruction, the container |
1874 * node of the resulting point is x and the index is the length of the | 1883 * node of the resulting point is x and the index is the length of the |
1875 * string-value of x. | 1884 * string-value of x. |
1876 * - If x is of type attribute or namespace, the function must signal a | 1885 * - If x is of type attribute or namespace, the function must signal a |
1877 * syntax error. | 1886 * syntax error. |
1878 * ---------------------------- | 1887 * ---------------------------- |
1879 */ | 1888 */ |
1880 void | 1889 static void |
1881 xmlXPtrEndPointFunction(xmlXPathParserContextPtr ctxt, int nargs) { | 1890 xmlXPtrEndPointFunction(xmlXPathParserContextPtr ctxt, int nargs) { |
1882 xmlXPathObjectPtr tmp, obj, point; | 1891 xmlXPathObjectPtr tmp, obj, point; |
1883 xmlLocationSetPtr newset = NULL; | 1892 xmlLocationSetPtr newset = NULL; |
1884 xmlLocationSetPtr oldset = NULL; | 1893 xmlLocationSetPtr oldset = NULL; |
1885 | 1894 |
1886 CHECK_ARITY(1); | 1895 CHECK_ARITY(1); |
1887 if ((ctxt->value == NULL) || | 1896 if ((ctxt->value == NULL) || |
1888 ((ctxt->value->type != XPATH_LOCATIONSET) && | 1897 ((ctxt->value->type != XPATH_LOCATIONSET) && |
1889 (ctxt->value->type != XPATH_NODESET))) | 1898 (ctxt->value->type != XPATH_NODESET))) |
1890 XP_ERROR(XPATH_INVALID_TYPE) | 1899 XP_ERROR(XPATH_INVALID_TYPE) |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2015 * @nargs: the number of args | 2024 * @nargs: the number of args |
2016 * | 2025 * |
2017 * Function implementing the range() function 5.4.3 | 2026 * Function implementing the range() function 5.4.3 |
2018 * location-set range(location-set ) | 2027 * location-set range(location-set ) |
2019 * | 2028 * |
2020 * The range function returns ranges covering the locations in | 2029 * The range function returns ranges covering the locations in |
2021 * the argument location-set. For each location x in the argument | 2030 * the argument location-set. For each location x in the argument |
2022 * location-set, a range location representing the covering range of | 2031 * location-set, a range location representing the covering range of |
2023 * x is added to the result location-set. | 2032 * x is added to the result location-set. |
2024 */ | 2033 */ |
2025 void | 2034 static void |
2026 xmlXPtrRangeFunction(xmlXPathParserContextPtr ctxt, int nargs) { | 2035 xmlXPtrRangeFunction(xmlXPathParserContextPtr ctxt, int nargs) { |
2027 int i; | 2036 int i; |
2028 xmlXPathObjectPtr set; | 2037 xmlXPathObjectPtr set; |
2029 xmlLocationSetPtr oldset; | 2038 xmlLocationSetPtr oldset; |
2030 xmlLocationSetPtr newset; | 2039 xmlLocationSetPtr newset; |
2031 | 2040 |
2032 CHECK_ARITY(1); | 2041 CHECK_ARITY(1); |
2033 if ((ctxt->value == NULL) || | 2042 if ((ctxt->value == NULL) || |
2034 ((ctxt->value->type != XPATH_LOCATIONSET) && | 2043 ((ctxt->value->type != XPATH_LOCATIONSET) && |
2035 (ctxt->value->type != XPATH_NODESET))) | 2044 (ctxt->value->type != XPATH_NODESET))) |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2161 * the argument location-set, a range location is added to the result | 2170 * the argument location-set, a range location is added to the result |
2162 * location-set. If x is a range location, then x is added to the | 2171 * location-set. If x is a range location, then x is added to the |
2163 * result location-set. If x is not a range location, then x is used | 2172 * result location-set. If x is not a range location, then x is used |
2164 * as the container location of the start and end points of the range | 2173 * as the container location of the start and end points of the range |
2165 * location to be added; the index of the start point of the range is | 2174 * location to be added; the index of the start point of the range is |
2166 * zero; if the end point is a character point then its index is the | 2175 * zero; if the end point is a character point then its index is the |
2167 * length of the string-value of x, and otherwise is the number of | 2176 * length of the string-value of x, and otherwise is the number of |
2168 * location children of x. | 2177 * location children of x. |
2169 * | 2178 * |
2170 */ | 2179 */ |
2171 void | 2180 static void |
2172 xmlXPtrRangeInsideFunction(xmlXPathParserContextPtr ctxt, int nargs) { | 2181 xmlXPtrRangeInsideFunction(xmlXPathParserContextPtr ctxt, int nargs) { |
2173 int i; | 2182 int i; |
2174 xmlXPathObjectPtr set; | 2183 xmlXPathObjectPtr set; |
2175 xmlLocationSetPtr oldset; | 2184 xmlLocationSetPtr oldset; |
2176 xmlLocationSetPtr newset; | 2185 xmlLocationSetPtr newset; |
2177 | 2186 |
2178 CHECK_ARITY(1); | 2187 CHECK_ARITY(1); |
2179 if ((ctxt->value == NULL) || | 2188 if ((ctxt->value == NULL) || |
2180 ((ctxt->value->type != XPATH_LOCATIONSET) && | 2189 ((ctxt->value->type != XPATH_LOCATIONSET) && |
2181 (ctxt->value->type != XPATH_NODESET))) | 2190 (ctxt->value->type != XPATH_NODESET))) |
(...skipping 433 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2615 xmlNodePtr cur; | 2624 xmlNodePtr cur; |
2616 int pos, len = 0; | 2625 int pos, len = 0; |
2617 | 2626 |
2618 if ((node == NULL) || (indx == NULL)) | 2627 if ((node == NULL) || (indx == NULL)) |
2619 return(-1); | 2628 return(-1); |
2620 cur = *node; | 2629 cur = *node; |
2621 pos = *indx; | 2630 pos = *indx; |
2622 | 2631 |
2623 if (cur == NULL) | 2632 if (cur == NULL) |
2624 return(-1); | 2633 return(-1); |
2625 | 2634 |
2626 if ((cur->type == XML_ELEMENT_NODE) || | 2635 if ((cur->type == XML_ELEMENT_NODE) || |
2627 (cur->type == XML_DOCUMENT_NODE) || | 2636 (cur->type == XML_DOCUMENT_NODE) || |
2628 (cur->type == XML_HTML_DOCUMENT_NODE)) { | 2637 (cur->type == XML_HTML_DOCUMENT_NODE)) { |
2629 if (pos > 0) { | 2638 if (pos > 0) { |
2630 cur = xmlXPtrGetNthChild(cur, pos); | 2639 cur = xmlXPtrGetNthChild(cur, pos); |
2631 pos = 0; | |
2632 } | 2640 } |
2633 } | 2641 } |
2634 while (cur != NULL) { | 2642 while (cur != NULL) { |
2635 if (cur->last != NULL) | 2643 if (cur->last != NULL) |
2636 cur = cur->last; | 2644 cur = cur->last; |
2637 else if ((cur->type != XML_ELEMENT_NODE) && | 2645 else if ((cur->type != XML_ELEMENT_NODE) && |
2638 (cur->content != NULL)) { | 2646 (cur->content != NULL)) { |
2639 len = xmlStrlen(cur->content); | 2647 len = xmlStrlen(cur->content); |
2640 break; | 2648 break; |
2641 } else { | 2649 } else { |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2750 * | 2758 * |
2751 * If the string in the second argument is not found in the string-value | 2759 * If the string in the second argument is not found in the string-value |
2752 * of the location, or if a value in the third or fourth argument indicates | 2760 * of the location, or if a value in the third or fourth argument indicates |
2753 * a string that is beyond the beginning or end of the document, the | 2761 * a string that is beyond the beginning or end of the document, the |
2754 * expression fails. | 2762 * expression fails. |
2755 * | 2763 * |
2756 * The points of the range-locations in the returned location-set will | 2764 * The points of the range-locations in the returned location-set will |
2757 * all be character points. | 2765 * all be character points. |
2758 * ------------------------------ | 2766 * ------------------------------ |
2759 */ | 2767 */ |
2760 void | 2768 static void |
2761 xmlXPtrStringRangeFunction(xmlXPathParserContextPtr ctxt, int nargs) { | 2769 xmlXPtrStringRangeFunction(xmlXPathParserContextPtr ctxt, int nargs) { |
2762 int i, startindex, endindex = 0, fendindex; | 2770 int i, startindex, endindex = 0, fendindex; |
2763 xmlNodePtr start, end = 0, fend; | 2771 xmlNodePtr start, end = 0, fend; |
2764 xmlXPathObjectPtr set; | 2772 xmlXPathObjectPtr set; |
2765 xmlLocationSetPtr oldset; | 2773 xmlLocationSetPtr oldset; |
2766 xmlLocationSetPtr newset; | 2774 xmlLocationSetPtr newset; |
2767 xmlXPathObjectPtr string; | 2775 xmlXPathObjectPtr string; |
2768 xmlXPathObjectPtr position = NULL; | 2776 xmlXPathObjectPtr position = NULL; |
2769 xmlXPathObjectPtr number = NULL; | 2777 xmlXPathObjectPtr number = NULL; |
2770 int found, pos = 0, num = 0; | 2778 int found, pos = 0, num = 0; |
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2994 } | 3002 } |
2995 | 3003 |
2996 NEXT; | 3004 NEXT; |
2997 SKIP_BLANKS; | 3005 SKIP_BLANKS; |
2998 } | 3006 } |
2999 | 3007 |
3000 #define bottom_xpointer | 3008 #define bottom_xpointer |
3001 #include "elfgcchack.h" | 3009 #include "elfgcchack.h" |
3002 #endif | 3010 #endif |
3003 | 3011 |
OLD | NEW |