Merge lp:~nbrinza/zorba/parse-fragment into lp:zorba

Proposed by Nicolae Brinza
Status: Superseded
Proposed branch: lp:~nbrinza/zorba/parse-fragment
Merge into: lp:zorba
Diff against target: 286 lines (+66/-33)
4 files modified
src/api/serialization/serializer.cpp (+41/-30)
src/api/serialization/serializer.h (+12/-3)
test/rbkt/ExpQueryResults/zorba/parsing_and_serializing/parse-xml-fragment-19.xml.res (+4/-0)
test/rbkt/Queries/zorba/parsing_and_serializing/parse-xml-fragment-19.xq (+9/-0)
To merge this branch: bzr merge lp:~nbrinza/zorba/parse-fragment
Reviewer Review Type Date Requested Status
David Graf (community) Approve
Review via email: mp+103453@code.launchpad.net

This proposal has been superseded by a proposal from 2012-04-26.

Description of the change

Small optimization in the serializer to avoid a repeated string comparison

To post a comment you must log in.
Revision history for this message
David Graf (davidagraf) :
review: Approve
lp:~nbrinza/zorba/parse-fragment updated
10522. By Nicolae Brinza

Merged with Zorba trunk

10523. By Nicolae Brinza

Documentation fixes.

10524. By Nicolae Brinza

Reverted a change in the parse fragment module to fix the regressions

10525. By Nicolae Brinza

Improved documentation of the parse-fragment module

10526. By Nicolae Brinza

Merged with Zorba trunk

10527. By Nicolae Brinza

Fixed the type of options parameter to the parse-fragment() function.

10528. By Nicolae Brinza

Fixed the quantity of the options parameter from ONE to QUESTION.

10529. By Nicolae Brinza

Merged with Zorba trunk

10530. By Nicolae Brinza

The parse-fragment function now allows a DOCTYPE declaration in the input.

10531. By Nicolae Brinza

Merged with Zorba trunk

10532. By Nicolae Brinza

Updated the Changelog with the parse-fragment info

10533. By Nicolae Brinza

Updated Changelog with the resolution of bug #1016606

10534. By Nicolae Brinza

Merged with Zorba trunk

10535. By Nicolae Brinza

Fixed parse-fragment not handling correctly the streammable streams lifetime.

10536. By Nicolae Brinza

The input buffer of parse-fragment can grow if libxml is not able to parse the current chunk. Fixes bug #1027270

10537. By Nicolae Brinza

Merged with Zorba trunk

10538. By Nicolae Brinza

Merged with Zorba trunk

10539. By Nicolae Brinza

Updated the Changelog with fixes for bugs #1016606 and #1024033

10540. By Nicolae Brinza

Updated the Changelog with the fix for the bug #1023170

10541. By Nicolae Brinza

Merged with Zorba trunk

10542. By Nicolae Brinza

Fix for bug #1099535 endless loop in xml:parse()

10543. By Nicolae Brinza

Merged with Zorba trunk

10544. By Nicolae Brinza

Updated Changelog to mention fix for bug #1099535

10545. By Nicolae Brinza

Merged with Zorba trunk

10546. By Nicolae Brinza

Fixed bug #1099648 -- XML parsing failures on Red Hat

10547. By Nicolae Brinza

Updated Changelog to mention the fix for bug #1099648

10548. By Nicolae Brinza

Merged with Zorba trunk

Unmerged revisions

10548. By Nicolae Brinza

Merged with Zorba trunk

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/api/serialization/serializer.cpp'
2--- src/api/serialization/serializer.cpp 2012-04-24 12:39:38 +0000
3+++ src/api/serialization/serializer.cpp 2012-04-25 12:02:26 +0000
4@@ -100,7 +100,6 @@
5 }
6 }
7
8-
9 ////////////////////////////////////////////////////////////////////////////////
10 // //
11 // Default emitter //
12@@ -194,7 +193,7 @@
13 unicode::code_point cp = utf8::next_char(temp);
14
15 // raise an error iff (1) the serialization format is XML 1.0 and (2) the given character is an invalid XML 1.0 character
16- if (ser && ser->method == PARAMETER_VALUE_XML && ser->version == "1.0" && !xml::is_valid(cp))
17+ if (ser && ser->method == PARAMETER_VALUE_XML && ser->version == PARAMETER_VALUE_VERSION_1_0 && !xml::is_valid(cp))
18 throw XQUERY_EXCEPTION( err::FOCH0001, ERROR_PARAMS( cp ) );
19
20 if (cp >= 0x10000 && cp <= 0x10FFFF)
21@@ -219,7 +218,7 @@
22
23 // raise an error iff (1) the serialization format is XML 1.0 and (2) the given character is an invalid XML 1.0 character
24 if (ser && ser->method == PARAMETER_VALUE_XML &&
25- ser->version == "1.0" && !xml::is_valid(static_cast<unsigned>(*chars)))
26+ ser->version == PARAMETER_VALUE_VERSION_1_0 && !xml::is_valid(static_cast<unsigned>(*chars)))
27 throw XQUERY_EXCEPTION(
28 err::XQST0090,
29 ERROR_PARAMS( static_cast<unsigned>( *chars ), xml::v1_0 )
30@@ -431,7 +430,7 @@
31 }
32 else if (item->getNodeKind() == store::StoreConsts::attributeNode)
33 {
34- throw XQUERY_EXCEPTION(err::SENR0001,
35+ throw XQUERY_EXCEPTION(err::SENR0001,
36 ERROR_PARAMS(item->getStringValue(), ZED(AttributeNode)));
37 }
38 else
39@@ -858,7 +857,7 @@
40 emitter::emit_declaration();
41
42 if (ser->omit_xml_declaration == PARAMETER_VALUE_NO) {
43- tr << "<?xml version=\"" << ser->version;
44+ tr << "<?xml version=\"" << ser->version_string;
45 switch (ser->encoding) {
46 case PARAMETER_VALUE_UTF_8:
47 case PARAMETER_VALUE_UTF_16:
48@@ -1218,7 +1217,7 @@
49 // an element written as <br/> or <br></br> in an XSLT stylesheet MUST
50 // be output as <br>.
51 if (is_html_empty_content_model_element(item) &&
52- ztd::equals(ser->version, "4.0", 3))
53+ ser->version == PARAMETER_VALUE_VERSION_4_0)
54 tr << ">";
55 else
56 tr << "/>";
57@@ -2004,7 +2003,8 @@
58
59 undeclare_prefixes = PARAMETER_VALUE_NO;
60
61- version = "1.0";
62+ version = PARAMETER_VALUE_VERSION_1_0;
63+ version_string = "1.0";
64 version_has_default_value = true;
65
66 indent = PARAMETER_VALUE_NO;
67@@ -2119,8 +2119,18 @@
68 }
69 else if (!strcmp(aName, "version"))
70 {
71- version = aValue;
72+ version_string = aValue;
73 version_has_default_value = false;
74+ if (version_string == "1.0")
75+ version = PARAMETER_VALUE_VERSION_1_0;
76+ else if (version_string == "1.1")
77+ version = PARAMETER_VALUE_VERSION_1_1;
78+ else if (version_string == "4.0")
79+ version = PARAMETER_VALUE_VERSION_4_0;
80+ else if (version_string == "4.01")
81+ version = PARAMETER_VALUE_VERSION_4_01;
82+ else
83+ version = PARAMETER_VALUE_VERSION_OTHER;
84 }
85 else if (!strcmp(aName, "doctype-system"))
86 {
87@@ -2156,51 +2166,52 @@
88 void
89 serializer::validate_parameters(void)
90 {
91- if (method == PARAMETER_VALUE_XML || method == PARAMETER_VALUE_XHTML)
92+ if (method == PARAMETER_VALUE_XML || method == PARAMETER_VALUE_XHTML)
93 {
94 // XML-only validation
95- if (method == PARAMETER_VALUE_XML)
96+ if (method == PARAMETER_VALUE_XML)
97 {
98- if (version != "1.0" && version != "1.1")
99+ if (version != PARAMETER_VALUE_VERSION_1_0 && version != PARAMETER_VALUE_VERSION_1_1)
100 throw XQUERY_EXCEPTION(
101 err::SESU0013, ERROR_PARAMS( version, "XML", "\"1.0\", \"1.1\"" )
102 );
103 }
104
105 // XHTML-only validation
106- if (method == PARAMETER_VALUE_XHTML)
107+ if (method == PARAMETER_VALUE_XHTML)
108 {
109 }
110
111 // XML and XHTML validation
112
113- if (omit_xml_declaration == PARAMETER_VALUE_YES)
114+ if (omit_xml_declaration == PARAMETER_VALUE_YES)
115 {
116 if (standalone != PARAMETER_VALUE_OMIT)
117 throw XQUERY_EXCEPTION(
118 err::SEPM0009, ERROR_PARAMS( ZED( SEPM0009_NotOmit ) )
119 );
120- if (version != "1.0" && !doctype_system.empty())
121+ if (version != PARAMETER_VALUE_VERSION_1_0 && !doctype_system.empty())
122 throw XQUERY_EXCEPTION(
123 err::SEPM0009, ERROR_PARAMS( ZED( SEPM0009_Not10 ) )
124 );
125 }
126
127- if (undeclare_prefixes == PARAMETER_VALUE_YES && version == "1.0")
128+ if (undeclare_prefixes == PARAMETER_VALUE_YES && version == PARAMETER_VALUE_VERSION_1_0)
129 throw XQUERY_EXCEPTION( err::SEPM0010 );
130 }
131
132- if (method == PARAMETER_VALUE_HTML)
133+ if (method == PARAMETER_VALUE_HTML)
134 {
135 // Default value for "version" when method is HTML is "4.0"
136- if (version_has_default_value)
137+ if (version_has_default_value)
138 {
139- version = "4.0";
140+ version = PARAMETER_VALUE_VERSION_4_0;
141+ version_string = "4.0";
142 }
143- else if (!(ztd::equals(version, "4.0", 3) || ztd::equals(version, "4.01", 4)))
144+ else if (version != PARAMETER_VALUE_VERSION_4_0 && version != PARAMETER_VALUE_VERSION_4_01)
145 {
146 throw XQUERY_EXCEPTION(
147- err::SESU0013, ERROR_PARAMS( version, "HTML", "\"4.0\", \"4.01\"" )
148+ err::SESU0013, ERROR_PARAMS( version_string, "HTML", "\"4.0\", \"4.01\"" )
149 );
150 }
151 }
152@@ -2278,13 +2289,13 @@
153
154 validate_parameters();
155
156- if (!setup(aOStream))
157+ if (!setup(aOStream))
158 {
159 return;
160 }
161
162 // in case we use SAX event notifications
163- if (aHandler)
164+ if (aHandler)
165 {
166 // only allow XML-based methods for SAX notifications
167 if (method != PARAMETER_VALUE_XML &&
168@@ -2303,10 +2314,10 @@
169
170 store::Item_t lItem;
171 //+ aObject->open();
172- while (aObject->next(lItem))
173+ while (aObject->next(lItem))
174 {
175 // PUL's cannot be serialized
176- if (lItem->isPul())
177+ if (lItem->isPul())
178 {
179 throw ZORBA_EXCEPTION(zerr::ZAPI0007_CANNOT_SERIALIZE_PUL);
180 }
181@@ -2329,7 +2340,7 @@
182 {
183 validate_parameters();
184
185- if (!setup(stream))
186+ if (!setup(stream))
187 {
188 return;
189 }
190@@ -2338,27 +2349,27 @@
191
192 store::Item_t lItem;
193 //object->open();
194- while (object->next(lItem))
195+ while (object->next(lItem))
196 {
197 Zorba_SerializerOptions_t* lSerParams = aHandler(aHandlerData);
198- if (lSerParams)
199+ if (lSerParams)
200 {
201 SerializerImpl::setSerializationParameters(*this, *lSerParams);
202- if (!setup(stream))
203+ if (!setup(stream))
204 {
205 return;
206 }
207 }
208
209 // PUL's cannot be serialized
210- if (lItem->isPul())
211+ if (lItem->isPul())
212 {
213 throw ZORBA_EXCEPTION(zerr::ZAPI0007_CANNOT_SERIALIZE_PUL);
214 }
215
216 e->emit_item(&*lItem);
217 }
218-
219+
220 //object->close();
221 e->emit_declaration_end();
222 }
223
224=== modified file 'src/api/serialization/serializer.h'
225--- src/api/serialization/serializer.h 2012-04-24 12:39:38 +0000
226+++ src/api/serialization/serializer.h 2012-04-25 12:02:26 +0000
227@@ -71,7 +71,15 @@
228 PARAMETER_VALUE_BINARY,
229
230 PARAMETER_VALUE_UTF_8,
231- PARAMETER_VALUE_UTF_16
232+ PARAMETER_VALUE_UTF_16,
233+
234+ // Values for the XML/HTML version
235+ PARAMETER_VALUE_VERSION_1_0, // used for XML 1.0
236+ PARAMETER_VALUE_VERSION_1_1, // used for XML 1.1
237+ PARAMETER_VALUE_VERSION_4_0, // used for HTML 4.0
238+ PARAMETER_VALUE_VERSION_4_01, // used for HTML 4.01
239+ PARAMETER_VALUE_VERSION_OTHER // given by the version string
240+
241 } PARAMETER_VALUE_TYPE;
242
243 protected:
244@@ -98,7 +106,8 @@
245 short int standalone; // implemented
246 short int undeclare_prefixes; // "yes" or "no", implemented
247 void* use_character_maps; // TODO: list of pairs
248- zstring version; // "1.0"
249+ short int version; // "1.0"
250+ zstring version_string; // this the version as a string
251 short int indent; // "yes" or "no", implemented
252 bool version_has_default_value; // Used during validation to set version to
253 // "4.0" when output method is "html"
254@@ -251,7 +260,7 @@
255
256 /**
257 * Serializes the given string, performing character expansion
258- * if necessary.
259+ * if necessary.
260 *
261 * @return returns the number of bytes that have not been written. This
262 * info is used only for streamable items expansion.
263
264=== added file 'test/rbkt/ExpQueryResults/zorba/parsing_and_serializing/parse-xml-fragment-19.xml.res'
265--- test/rbkt/ExpQueryResults/zorba/parsing_and_serializing/parse-xml-fragment-19.xml.res 1970-01-01 00:00:00 +0000
266+++ test/rbkt/ExpQueryResults/zorba/parsing_and_serializing/parse-xml-fragment-19.xml.res 2012-04-25 12:02:26 +0000
267@@ -0,0 +1,4 @@
268+<?xml version="1.0" encoding="UTF-8"?>
269+<from1>Jani</from1>
270+<from2>Jani</from2>
271+<from3>Jani</from3>
272\ No newline at end of file
273
274=== added file 'test/rbkt/Queries/zorba/parsing_and_serializing/parse-xml-fragment-19.xq'
275--- test/rbkt/Queries/zorba/parsing_and_serializing/parse-xml-fragment-19.xq 1970-01-01 00:00:00 +0000
276+++ test/rbkt/Queries/zorba/parsing_and_serializing/parse-xml-fragment-19.xq 2012-04-25 12:02:26 +0000
277@@ -0,0 +1,9 @@
278+(:
279+ Test that the backwards-compatible parse-xml-fragment() function works.
280+:)
281+import module namespace z = "http://www.zorba-xquery.com/modules/xml";
282+
283+z:parse-xml-fragment("<from1>Jani</from1>
284+<from2>Jani</from2>
285+<from3>Jani</from3>",
286+"e")

Subscribers

People subscribed via source and target branches