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
=== modified file 'src/api/serialization/serializer.cpp'
--- src/api/serialization/serializer.cpp 2012-04-24 12:39:38 +0000
+++ src/api/serialization/serializer.cpp 2012-04-25 12:02:26 +0000
@@ -100,7 +100,6 @@
100 }100 }
101}101}
102102
103
104////////////////////////////////////////////////////////////////////////////////103////////////////////////////////////////////////////////////////////////////////
105// //104// //
106// Default emitter //105// Default emitter //
@@ -194,7 +193,7 @@
194 unicode::code_point cp = utf8::next_char(temp);193 unicode::code_point cp = utf8::next_char(temp);
195194
196 // raise an error iff (1) the serialization format is XML 1.0 and (2) the given character is an invalid XML 1.0 character195 // raise an error iff (1) the serialization format is XML 1.0 and (2) the given character is an invalid XML 1.0 character
197 if (ser && ser->method == PARAMETER_VALUE_XML && ser->version == "1.0" && !xml::is_valid(cp))196 if (ser && ser->method == PARAMETER_VALUE_XML && ser->version == PARAMETER_VALUE_VERSION_1_0 && !xml::is_valid(cp))
198 throw XQUERY_EXCEPTION( err::FOCH0001, ERROR_PARAMS( cp ) );197 throw XQUERY_EXCEPTION( err::FOCH0001, ERROR_PARAMS( cp ) );
199198
200 if (cp >= 0x10000 && cp <= 0x10FFFF)199 if (cp >= 0x10000 && cp <= 0x10FFFF)
@@ -219,7 +218,7 @@
219218
220 // raise an error iff (1) the serialization format is XML 1.0 and (2) the given character is an invalid XML 1.0 character219 // raise an error iff (1) the serialization format is XML 1.0 and (2) the given character is an invalid XML 1.0 character
221 if (ser && ser->method == PARAMETER_VALUE_XML &&220 if (ser && ser->method == PARAMETER_VALUE_XML &&
222 ser->version == "1.0" && !xml::is_valid(static_cast<unsigned>(*chars)))221 ser->version == PARAMETER_VALUE_VERSION_1_0 && !xml::is_valid(static_cast<unsigned>(*chars)))
223 throw XQUERY_EXCEPTION(222 throw XQUERY_EXCEPTION(
224 err::XQST0090,223 err::XQST0090,
225 ERROR_PARAMS( static_cast<unsigned>( *chars ), xml::v1_0 )224 ERROR_PARAMS( static_cast<unsigned>( *chars ), xml::v1_0 )
@@ -431,7 +430,7 @@
431 }430 }
432 else if (item->getNodeKind() == store::StoreConsts::attributeNode)431 else if (item->getNodeKind() == store::StoreConsts::attributeNode)
433 {432 {
434 throw XQUERY_EXCEPTION(err::SENR0001, 433 throw XQUERY_EXCEPTION(err::SENR0001,
435 ERROR_PARAMS(item->getStringValue(), ZED(AttributeNode)));434 ERROR_PARAMS(item->getStringValue(), ZED(AttributeNode)));
436 }435 }
437 else436 else
@@ -858,7 +857,7 @@
858 emitter::emit_declaration();857 emitter::emit_declaration();
859858
860 if (ser->omit_xml_declaration == PARAMETER_VALUE_NO) {859 if (ser->omit_xml_declaration == PARAMETER_VALUE_NO) {
861 tr << "<?xml version=\"" << ser->version;860 tr << "<?xml version=\"" << ser->version_string;
862 switch (ser->encoding) {861 switch (ser->encoding) {
863 case PARAMETER_VALUE_UTF_8:862 case PARAMETER_VALUE_UTF_8:
864 case PARAMETER_VALUE_UTF_16:863 case PARAMETER_VALUE_UTF_16:
@@ -1218,7 +1217,7 @@
1218 // an element written as <br/> or <br></br> in an XSLT stylesheet MUST1217 // an element written as <br/> or <br></br> in an XSLT stylesheet MUST
1219 // be output as <br>.1218 // be output as <br>.
1220 if (is_html_empty_content_model_element(item) &&1219 if (is_html_empty_content_model_element(item) &&
1221 ztd::equals(ser->version, "4.0", 3))1220 ser->version == PARAMETER_VALUE_VERSION_4_0)
1222 tr << ">";1221 tr << ">";
1223 else1222 else
1224 tr << "/>";1223 tr << "/>";
@@ -2004,7 +2003,8 @@
20042003
2005 undeclare_prefixes = PARAMETER_VALUE_NO;2004 undeclare_prefixes = PARAMETER_VALUE_NO;
20062005
2007 version = "1.0";2006 version = PARAMETER_VALUE_VERSION_1_0;
2007 version_string = "1.0";
2008 version_has_default_value = true;2008 version_has_default_value = true;
20092009
2010 indent = PARAMETER_VALUE_NO;2010 indent = PARAMETER_VALUE_NO;
@@ -2119,8 +2119,18 @@
2119 }2119 }
2120 else if (!strcmp(aName, "version"))2120 else if (!strcmp(aName, "version"))
2121 {2121 {
2122 version = aValue;2122 version_string = aValue;
2123 version_has_default_value = false;2123 version_has_default_value = false;
2124 if (version_string == "1.0")
2125 version = PARAMETER_VALUE_VERSION_1_0;
2126 else if (version_string == "1.1")
2127 version = PARAMETER_VALUE_VERSION_1_1;
2128 else if (version_string == "4.0")
2129 version = PARAMETER_VALUE_VERSION_4_0;
2130 else if (version_string == "4.01")
2131 version = PARAMETER_VALUE_VERSION_4_01;
2132 else
2133 version = PARAMETER_VALUE_VERSION_OTHER;
2124 }2134 }
2125 else if (!strcmp(aName, "doctype-system"))2135 else if (!strcmp(aName, "doctype-system"))
2126 {2136 {
@@ -2156,51 +2166,52 @@
2156void2166void
2157serializer::validate_parameters(void)2167serializer::validate_parameters(void)
2158{2168{
2159 if (method == PARAMETER_VALUE_XML || method == PARAMETER_VALUE_XHTML) 2169 if (method == PARAMETER_VALUE_XML || method == PARAMETER_VALUE_XHTML)
2160 {2170 {
2161 // XML-only validation2171 // XML-only validation
2162 if (method == PARAMETER_VALUE_XML) 2172 if (method == PARAMETER_VALUE_XML)
2163 {2173 {
2164 if (version != "1.0" && version != "1.1")2174 if (version != PARAMETER_VALUE_VERSION_1_0 && version != PARAMETER_VALUE_VERSION_1_1)
2165 throw XQUERY_EXCEPTION(2175 throw XQUERY_EXCEPTION(
2166 err::SESU0013, ERROR_PARAMS( version, "XML", "\"1.0\", \"1.1\"" )2176 err::SESU0013, ERROR_PARAMS( version, "XML", "\"1.0\", \"1.1\"" )
2167 );2177 );
2168 }2178 }
21692179
2170 // XHTML-only validation2180 // XHTML-only validation
2171 if (method == PARAMETER_VALUE_XHTML) 2181 if (method == PARAMETER_VALUE_XHTML)
2172 {2182 {
2173 }2183 }
21742184
2175 // XML and XHTML validation2185 // XML and XHTML validation
21762186
2177 if (omit_xml_declaration == PARAMETER_VALUE_YES) 2187 if (omit_xml_declaration == PARAMETER_VALUE_YES)
2178 {2188 {
2179 if (standalone != PARAMETER_VALUE_OMIT)2189 if (standalone != PARAMETER_VALUE_OMIT)
2180 throw XQUERY_EXCEPTION(2190 throw XQUERY_EXCEPTION(
2181 err::SEPM0009, ERROR_PARAMS( ZED( SEPM0009_NotOmit ) )2191 err::SEPM0009, ERROR_PARAMS( ZED( SEPM0009_NotOmit ) )
2182 );2192 );
2183 if (version != "1.0" && !doctype_system.empty())2193 if (version != PARAMETER_VALUE_VERSION_1_0 && !doctype_system.empty())
2184 throw XQUERY_EXCEPTION(2194 throw XQUERY_EXCEPTION(
2185 err::SEPM0009, ERROR_PARAMS( ZED( SEPM0009_Not10 ) )2195 err::SEPM0009, ERROR_PARAMS( ZED( SEPM0009_Not10 ) )
2186 );2196 );
2187 }2197 }
21882198
2189 if (undeclare_prefixes == PARAMETER_VALUE_YES && version == "1.0")2199 if (undeclare_prefixes == PARAMETER_VALUE_YES && version == PARAMETER_VALUE_VERSION_1_0)
2190 throw XQUERY_EXCEPTION( err::SEPM0010 );2200 throw XQUERY_EXCEPTION( err::SEPM0010 );
2191 }2201 }
21922202
2193 if (method == PARAMETER_VALUE_HTML) 2203 if (method == PARAMETER_VALUE_HTML)
2194 {2204 {
2195 // Default value for "version" when method is HTML is "4.0"2205 // Default value for "version" when method is HTML is "4.0"
2196 if (version_has_default_value) 2206 if (version_has_default_value)
2197 {2207 {
2198 version = "4.0";2208 version = PARAMETER_VALUE_VERSION_4_0;
2209 version_string = "4.0";
2199 }2210 }
2200 else if (!(ztd::equals(version, "4.0", 3) || ztd::equals(version, "4.01", 4))) 2211 else if (version != PARAMETER_VALUE_VERSION_4_0 && version != PARAMETER_VALUE_VERSION_4_01)
2201 {2212 {
2202 throw XQUERY_EXCEPTION(2213 throw XQUERY_EXCEPTION(
2203 err::SESU0013, ERROR_PARAMS( version, "HTML", "\"4.0\", \"4.01\"" )2214 err::SESU0013, ERROR_PARAMS( version_string, "HTML", "\"4.0\", \"4.01\"" )
2204 );2215 );
2205 }2216 }
2206 }2217 }
@@ -2278,13 +2289,13 @@
22782289
2279 validate_parameters();2290 validate_parameters();
22802291
2281 if (!setup(aOStream)) 2292 if (!setup(aOStream))
2282 {2293 {
2283 return;2294 return;
2284 }2295 }
22852296
2286 // in case we use SAX event notifications2297 // in case we use SAX event notifications
2287 if (aHandler) 2298 if (aHandler)
2288 {2299 {
2289 // only allow XML-based methods for SAX notifications2300 // only allow XML-based methods for SAX notifications
2290 if (method != PARAMETER_VALUE_XML &&2301 if (method != PARAMETER_VALUE_XML &&
@@ -2303,10 +2314,10 @@
23032314
2304 store::Item_t lItem;2315 store::Item_t lItem;
2305 //+ aObject->open();2316 //+ aObject->open();
2306 while (aObject->next(lItem)) 2317 while (aObject->next(lItem))
2307 {2318 {
2308 // PUL's cannot be serialized2319 // PUL's cannot be serialized
2309 if (lItem->isPul()) 2320 if (lItem->isPul())
2310 {2321 {
2311 throw ZORBA_EXCEPTION(zerr::ZAPI0007_CANNOT_SERIALIZE_PUL);2322 throw ZORBA_EXCEPTION(zerr::ZAPI0007_CANNOT_SERIALIZE_PUL);
2312 }2323 }
@@ -2329,7 +2340,7 @@
2329{2340{
2330 validate_parameters();2341 validate_parameters();
23312342
2332 if (!setup(stream)) 2343 if (!setup(stream))
2333 {2344 {
2334 return;2345 return;
2335 }2346 }
@@ -2338,27 +2349,27 @@
23382349
2339 store::Item_t lItem;2350 store::Item_t lItem;
2340 //object->open();2351 //object->open();
2341 while (object->next(lItem)) 2352 while (object->next(lItem))
2342 {2353 {
2343 Zorba_SerializerOptions_t* lSerParams = aHandler(aHandlerData);2354 Zorba_SerializerOptions_t* lSerParams = aHandler(aHandlerData);
2344 if (lSerParams) 2355 if (lSerParams)
2345 {2356 {
2346 SerializerImpl::setSerializationParameters(*this, *lSerParams);2357 SerializerImpl::setSerializationParameters(*this, *lSerParams);
2347 if (!setup(stream)) 2358 if (!setup(stream))
2348 {2359 {
2349 return;2360 return;
2350 }2361 }
2351 }2362 }
23522363
2353 // PUL's cannot be serialized2364 // PUL's cannot be serialized
2354 if (lItem->isPul()) 2365 if (lItem->isPul())
2355 {2366 {
2356 throw ZORBA_EXCEPTION(zerr::ZAPI0007_CANNOT_SERIALIZE_PUL);2367 throw ZORBA_EXCEPTION(zerr::ZAPI0007_CANNOT_SERIALIZE_PUL);
2357 }2368 }
23582369
2359 e->emit_item(&*lItem);2370 e->emit_item(&*lItem);
2360 }2371 }
2361 2372
2362 //object->close();2373 //object->close();
2363 e->emit_declaration_end();2374 e->emit_declaration_end();
2364}2375}
23652376
=== modified file 'src/api/serialization/serializer.h'
--- src/api/serialization/serializer.h 2012-04-24 12:39:38 +0000
+++ src/api/serialization/serializer.h 2012-04-25 12:02:26 +0000
@@ -71,7 +71,15 @@
71 PARAMETER_VALUE_BINARY,71 PARAMETER_VALUE_BINARY,
7272
73 PARAMETER_VALUE_UTF_8,73 PARAMETER_VALUE_UTF_8,
74 PARAMETER_VALUE_UTF_1674 PARAMETER_VALUE_UTF_16,
75
76 // Values for the XML/HTML version
77 PARAMETER_VALUE_VERSION_1_0, // used for XML 1.0
78 PARAMETER_VALUE_VERSION_1_1, // used for XML 1.1
79 PARAMETER_VALUE_VERSION_4_0, // used for HTML 4.0
80 PARAMETER_VALUE_VERSION_4_01, // used for HTML 4.01
81 PARAMETER_VALUE_VERSION_OTHER // given by the version string
82
75 } PARAMETER_VALUE_TYPE;83 } PARAMETER_VALUE_TYPE;
7684
77protected:85protected:
@@ -98,7 +106,8 @@
98 short int standalone; // implemented106 short int standalone; // implemented
99 short int undeclare_prefixes; // "yes" or "no", implemented107 short int undeclare_prefixes; // "yes" or "no", implemented
100 void* use_character_maps; // TODO: list of pairs108 void* use_character_maps; // TODO: list of pairs
101 zstring version; // "1.0"109 short int version; // "1.0"
110 zstring version_string; // this the version as a string
102 short int indent; // "yes" or "no", implemented111 short int indent; // "yes" or "no", implemented
103 bool version_has_default_value; // Used during validation to set version to112 bool version_has_default_value; // Used during validation to set version to
104 // "4.0" when output method is "html"113 // "4.0" when output method is "html"
@@ -251,7 +260,7 @@
251260
252 /**261 /**
253 * Serializes the given string, performing character expansion262 * Serializes the given string, performing character expansion
254 * if necessary. 263 * if necessary.
255 *264 *
256 * @return returns the number of bytes that have not been written. This265 * @return returns the number of bytes that have not been written. This
257 * info is used only for streamable items expansion.266 * info is used only for streamable items expansion.
258267
=== added file 'test/rbkt/ExpQueryResults/zorba/parsing_and_serializing/parse-xml-fragment-19.xml.res'
--- test/rbkt/ExpQueryResults/zorba/parsing_and_serializing/parse-xml-fragment-19.xml.res 1970-01-01 00:00:00 +0000
+++ test/rbkt/ExpQueryResults/zorba/parsing_and_serializing/parse-xml-fragment-19.xml.res 2012-04-25 12:02:26 +0000
@@ -0,0 +1,4 @@
1<?xml version="1.0" encoding="UTF-8"?>
2<from1>Jani</from1>
3<from2>Jani</from2>
4<from3>Jani</from3>
0\ No newline at end of file5\ No newline at end of file
16
=== added file 'test/rbkt/Queries/zorba/parsing_and_serializing/parse-xml-fragment-19.xq'
--- test/rbkt/Queries/zorba/parsing_and_serializing/parse-xml-fragment-19.xq 1970-01-01 00:00:00 +0000
+++ test/rbkt/Queries/zorba/parsing_and_serializing/parse-xml-fragment-19.xq 2012-04-25 12:02:26 +0000
@@ -0,0 +1,9 @@
1(:
2 Test that the backwards-compatible parse-xml-fragment() function works.
3:)
4import module namespace z = "http://www.zorba-xquery.com/modules/xml";
5
6z:parse-xml-fragment("<from1>Jani</from1>
7<from2>Jani</from2>
8<from3>Jani</from3>",
9"e")

Subscribers

People subscribed via source and target branches