aboutsummaryrefslogtreecommitdiffstats
path: root/src/xml.c
diff options
context:
space:
mode:
authorStefan Monnier2010-10-15 17:55:33 -0400
committerStefan Monnier2010-10-15 17:55:33 -0400
commit0c747cb143fa227e78f350ac353d703f489209df (patch)
tree5b434055c797bd75eaa1e3d9d0773e586d44daee /src/xml.c
parenta01a7932080e8a6e7bc8472c58cefabcc2c37df3 (diff)
parentaa095b2db98ae149737f8de00ee733b1d257ed33 (diff)
downloademacs-0c747cb143fa227e78f350ac353d703f489209df.tar.gz
emacs-0c747cb143fa227e78f350ac353d703f489209df.zip
Merge from trunk
Diffstat (limited to 'src/xml.c')
-rw-r--r--src/xml.c62
1 files changed, 37 insertions, 25 deletions
diff --git a/src/xml.c b/src/xml.c
index 5829f1da538..a686e55f0b0 100644
--- a/src/xml.c
+++ b/src/xml.c
@@ -74,17 +74,24 @@ Lisp_Object make_dom (xmlNode *node)
74} 74}
75 75
76static Lisp_Object 76static Lisp_Object
77parse_string (Lisp_Object string, Lisp_Object base_url, int htmlp) 77parse_region (Lisp_Object start, Lisp_Object end, Lisp_Object base_url, int htmlp)
78{ 78{
79 xmlDoc *doc; 79 xmlDoc *doc;
80 xmlNode *node; 80 xmlNode *node;
81 Lisp_Object result = Qnil; 81 Lisp_Object result = Qnil;
82 int ibeg, iend; 82 const char *burl = "";
83 char *burl = ""; 83 EMACS_INT bytes;
84 EMACS_INT istart, iend;
84 85
85 LIBXML_TEST_VERSION; 86 LIBXML_TEST_VERSION;
86 87
87 CHECK_STRING (string); 88 validate_region (&start, &end);
89
90 istart = XINT (start);
91 iend = XINT (end);
92
93 if (istart < GPT && GPT < iend)
94 move_gap (iend);
88 95
89 if (! NILP (base_url)) 96 if (! NILP (base_url))
90 { 97 {
@@ -92,13 +99,18 @@ parse_string (Lisp_Object string, Lisp_Object base_url, int htmlp)
92 burl = SDATA (base_url); 99 burl = SDATA (base_url);
93 } 100 }
94 101
95 doc = htmlp 102 bytes = CHAR_TO_BYTE (iend) - CHAR_TO_BYTE (istart);
96 ? htmlReadMemory (SDATA (string), SBYTES (string), burl, "utf-8", 103
97 HTML_PARSE_RECOVER|HTML_PARSE_NONET| 104 if (htmlp)
98 HTML_PARSE_NOWARNING|HTML_PARSE_NOERROR) 105 doc = htmlReadMemory (BYTE_POS_ADDR (CHAR_TO_BYTE (istart)),
99 : xmlReadMemory (SDATA (string), SBYTES (string), burl, "utf-8", 106 bytes, burl, "utf-8",
100 XML_PARSE_NONET|XML_PARSE_NOWARNING| 107 HTML_PARSE_RECOVER|HTML_PARSE_NONET|
101 XML_PARSE_NOERROR); 108 HTML_PARSE_NOWARNING|HTML_PARSE_NOERROR);
109 else
110 doc = xmlReadMemory (BYTE_POS_ADDR (CHAR_TO_BYTE (istart)),
111 bytes, burl, "utf-8",
112 XML_PARSE_NONET|XML_PARSE_NOWARNING|
113 XML_PARSE_NOERROR);
102 114
103 if (doc != NULL) 115 if (doc != NULL)
104 { 116 {
@@ -112,24 +124,24 @@ parse_string (Lisp_Object string, Lisp_Object base_url, int htmlp)
112 return result; 124 return result;
113} 125}
114 126
115DEFUN ("xml-parse-html-string-internal", Fxml_parse_html_string_internal, 127DEFUN ("libxml-parse-html-region", Flibxml_parse_html_region,
116 Sxml_parse_html_string_internal, 128 Slibxml_parse_html_region,
117 1, 2, 0, 129 2, 3, 0,
118 doc: /* Parse STRING as an HTML document and return the parse tree. 130 doc: /* Parse the region as an HTML document and return the parse tree.
119If BASE-URL is non-nil, it is used to expand relative URLs. */) 131If BASE-URL is non-nil, it is used to expand relative URLs. */)
120 (Lisp_Object string, Lisp_Object base_url) 132 (Lisp_Object start, Lisp_Object end, Lisp_Object base_url)
121{ 133{
122 return parse_string (string, base_url, 1); 134 return parse_region (start, end, base_url, 1);
123} 135}
124 136
125DEFUN ("xml-parse-string-internal", Fxml_parse_string_internal, 137DEFUN ("libxml-parse-xml-region", Flibxml_parse_xml_region,
126 Sxml_parse_string_internal, 138 Slibxml_parse_xml_region,
127 1, 2, 0, 139 2, 3, 0,
128 doc: /* Parse STRING as an XML document and return the parse tree. 140 doc: /* Parse the region as an XML document and return the parse tree.
129If BASE-URL is non-nil, it is used to expand relative URLs. */) 141If BASE-URL is non-nil, it is used to expand relative URLs. */)
130 (Lisp_Object string, Lisp_Object base_url) 142 (Lisp_Object start, Lisp_Object end, Lisp_Object base_url)
131{ 143{
132 return parse_string (string, base_url, 0); 144 return parse_region (start, end, base_url, 0);
133} 145}
134 146
135 147
@@ -139,8 +151,8 @@ If BASE-URL is non-nil, it is used to expand relative URLs. */)
139void 151void
140syms_of_xml (void) 152syms_of_xml (void)
141{ 153{
142 defsubr (&Sxml_parse_html_string_internal); 154 defsubr (&Slibxml_parse_html_region);
143 defsubr (&Sxml_parse_string_internal); 155 defsubr (&Slibxml_parse_xml_region);
144} 156}
145 157
146#endif /* HAVE_LIBXML2 */ 158#endif /* HAVE_LIBXML2 */