Merge lp:~zorba-coders/zorba/bug-1158052 into lp:zorba

Proposed by Paul J. Lucas
Status: Merged
Merged at revision: 11545
Proposed branch: lp:~zorba-coders/zorba/bug-1158052
Merge into: lp:zorba
Diff against target: 1611 lines (+342/-569)
16 files modified
ChangeLog (+2/-1)
include/zorba/item_factory.h (+7/-14)
modules/ExternalModules.conf (+2/-2)
modules/com/zorba-xquery/www/modules/http-client.xq.src/http_response_parser.cpp (+1/-1)
src/api/itemfactoryimpl.cpp (+91/-109)
src/api/itemfactoryimpl.h (+1/-4)
src/store/naive/atomic_items.cpp (+3/-3)
src/store/naive/simple_item_factory.cpp (+2/-2)
src/types/casting.cpp (+3/-11)
src/zorbaserialization/serialize_zorba_types.cpp (+6/-26)
src/zorbatypes/binary.cpp (+88/-260)
src/zorbatypes/binary.h (+126/-116)
swig/ItemFactory.h (+4/-11)
swig/ItemFactory.i (+2/-5)
swig/xqj/ZorbaXQConnection.java (+2/-2)
test/api/itemfactory.cpp (+2/-2)
To merge this branch: bzr merge lp:~zorba-coders/zorba/bug-1158052
Reviewer Review Type Date Requested Status
Chris Hillery Approve
Paul J. Lucas Approve
Review via email: mp+170725@code.launchpad.net

Commit message

Cleaned up both public and internal API.

To post a comment you must log in.
Revision history for this message
Paul J. Lucas (paul-lucas) :
review: Approve
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :

The attempt to merge lp:~zorba-coders/zorba/bug-1158052 into lp:zorba failed. Below is the output from the failed tests.

CMake Error at /home/ceej/zo/testing/zorbatest/tester/TarmacLander.cmake:281 (message):
  Validation queue job bug-1158052-2013-06-21T01-46-49.193Z is finished. The
  final status was:

  No tests were run - build or configure step must have failed.

  Not commiting changes.

Error in read script: /home/ceej/zo/testing/zorbatest/tester/TarmacLander.cmake

Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :

There are additional revisions which have not been approved in review. Please seek review and approval of these new revisions.

Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :

The attempt to merge lp:~zorba-coders/zorba/bug-1158052 into lp:zorba failed. Below is the output from the failed tests.

CMake Error at /home/ceej/zo/testing/zorbatest/tester/TarmacLander.cmake:281 (message):
  Validation queue job bug-1158052-2013-06-21T03-54-45.43Z is finished. The
  final status was:

  No tests were run - build or configure step must have failed.

  Not commiting changes.

Error in read script: /home/ceej/zo/testing/zorbatest/tester/TarmacLander.cmake

Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :

The attempt to merge lp:~zorba-coders/zorba/bug-1158052 into lp:zorba failed. Below is the output from the failed tests.

CMake Error at /home/ceej/zo/testing/zorbatest/tester/TarmacLander.cmake:281 (message):
  Validation queue job bug-1158052-2013-06-21T04-31-56.775Z is finished. The
  final status was:

  No tests were run - build or configure step must have failed.

  Not commiting changes.

Error in read script: /home/ceej/zo/testing/zorbatest/tester/TarmacLander.cmake

Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :

The attempt to merge lp:~zorba-coders/zorba/bug-1158052 into lp:zorba failed. Below is the output from the failed tests.

CMake Error at /home/ceej/zo/testing/zorbatest/tester/TarmacLander.cmake:281 (message):
  Validation queue job bug-1158052-2013-06-21T14-07-53.658Z is finished. The
  final status was:

  5 tests did not succeed - changes not commited.

Error in read script: /home/ceej/zo/testing/zorbatest/tester/TarmacLander.cmake

Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :

Validation queue job bug-1158052-2013-06-21T20-56-53.491Z is finished. The final status was:

All tests succeeded!

Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :

Voting does not meet specified criteria. Required: Approve > 1, Disapprove < 1, Needs Fixing < 1, Pending < 1, Needs Information < 1, Resubmit < 1. Got: 1 Approve.

lp:~zorba-coders/zorba/bug-1158052 updated
11538. By Paul J. Lucas

Merge from trunk.

11539. By Paul J. Lucas

Merge from trunk.

11540. By Paul J. Lucas

Merge from trunk.

11541. By Chris Hillery

Revert to non-core modules from trunks.

Revision history for this message
Chris Hillery (ceejatec) :
review: Approve
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :

Validation queue succeeded!

Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote :

Validation queue succeeded - proposal merged!

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'ChangeLog'
2--- ChangeLog 2013-06-28 02:33:07 +0000
3+++ ChangeLog 2013-06-28 04:21:28 +0000
4@@ -32,10 +32,11 @@
5 * Fixed bug #1189798 (Update core module "errors")
6 * Fixed bug #1187537 (Eliminate (or at least reduce) use of MAX_PATH)
7 * Fixed bug #1180220 (Consolidate redundant path/file public APIs)
8+ * Fixed bug #1158052 (createBase64Binary() API too subtle)
9 * Fixed bug #1103115 (Timezone units as hours are wrong)
10 * Fixed bug #1188280 (casting xs:id to xs:ncname)
11 * Fixed bug in casting to xs:NCName
12- * Check that namespace uri used in default namespace declaration is a valid one
13+ * Check that the namespace URI used in default namespace declaration is valid
14 * Fixed bug in error conditions for computed PI constructor
15 * Fixed implementation of fn:deep-equal according to latest W3C spec.
16 * Must apply document ordering on the domain expression of a FOR clause, if
17
18=== modified file 'include/zorba/item_factory.h'
19--- include/zorba/item_factory.h 2013-06-18 23:53:59 +0000
20+++ include/zorba/item_factory.h 2013-06-28 04:21:28 +0000
21@@ -141,32 +141,25 @@
22 /** \brief Creates a Base64Binary Item
23 * see [http://www.w3.org/TR/xmlschema-2/#base64Binary]
24 *
25- * @param aBinData a pointer to the base64 encoded data. The data is copied from aBinData.
26- * @param aLength the length of the base64 encoded data.
27+ * @param aData a pointer to the data.
28+ * @param aLength the length of the data (in bytes).
29+ * @param aIsBase64 If \c true, \a aData is already Base-64 encoded; if
30+ * \c false, \a aData is binary data that will first be Base-64 encoded.
31 * @return The Base64Binary Item.
32 */
33 virtual Item
34- createBase64Binary(const char* aBinData, size_t aLength) = 0;
35+ createBase64Binary(const char* aData, size_t aLength, bool aIsBase64) = 0;
36
37 /** \brief Creates a Base64Binary Item
38 * see [http://www.w3.org/TR/xmlschema-2/#base64Binary]
39 *
40- * @param aStream A stream containing the Base64 encoded data. The data is copied from aStream imediately.
41+ * @param aStream A stream containing the Base64 encoded data.
42+ * The data is copied from aStream immediately.
43 * @return the Base64Binary Item.
44 */
45 virtual Item
46 createBase64Binary(std::istream& aStream) = 0;
47
48- /** \brief Creates a Base64Binary Item
49- * see [http://www.w3.org/TR/xmlschema-2/#base64Binary]
50- *
51- * @param aBinData the data in binary form (not encoded). The data is copied from aBinData.
52- * @param aLength the length of the binary data
53- * @return the Base64Binary Item.
54- */
55- virtual Item
56- createBase64Binary(const unsigned char* aBinData, size_t aLength) = 0;
57-
58 /** \brief Creates a streamable Base64Binary Item
59 * see [http://www.w3.org/TR/xmlschema-2/#base64Binary]
60 *
61
62=== modified file 'modules/ExternalModules.conf'
63--- modules/ExternalModules.conf 2013-06-28 00:31:51 +0000
64+++ modules/ExternalModules.conf 2013-06-28 04:21:28 +0000
65@@ -32,14 +32,14 @@
66 data-formatting bzr lp:zorba/data-formatting-module
67 excel bzr lp:zorba/excel-module zorba-2.9
68 info-extraction bzr lp:zorba/info-extraction-module zorba-2.9
69-geo bzr lp:zorba/geo-module zorba-2.9
70+geo bzr lp:zorba/geo-module
71 geoproj bzr lp:zorba/geoproj-module zorba-2.9
72 graphviz bzr lp:zorba/graphviz-module zorba-2.9
73 html bzr lp:zorba/html-module zorba-2.9
74 http-client bzr lp:zorba/http-client-module zorba-2.9
75 image bzr lp:zorba/image-module
76 jdbc bzr lp:zorba/jdbc-module
77-languages bzr lp:zorba/languages-module zorba-2.9
78+languages bzr lp:zorba/languages-module
79 oracle-nosql-db bzr lp:zorba/oracle-nosql-db-module
80 oauth bzr lp:zorba/oauth-module zorba-2.9
81 process bzr lp:zorba/process-module
82
83=== modified file 'modules/com/zorba-xquery/www/modules/http-client.xq.src/http_response_parser.cpp'
84--- modules/com/zorba-xquery/www/modules/http-client.xq.src/http_response_parser.cpp 2013-06-25 03:55:20 +0000
85+++ modules/com/zorba-xquery/www/modules/http-client.xq.src/http_response_parser.cpp 2013-06-28 04:21:28 +0000
86@@ -329,7 +329,7 @@
87 // changed. This required a Base64 encoding stream since the item factory
88 // work only builds base64binary and assumes the data is already encoded.
89 String lEncoded = base64::encode(aStream);
90- return lFactory->createBase64Binary(lEncoded.data(), lEncoded.size());
91+ return lFactory->createBase64Binary(lEncoded.data(), lEncoded.size(), true);
92 }
93
94 zorba::Item HttpResponseParser::createXmlItem( std::istream& aStream )
95
96=== modified file 'src/api/itemfactoryimpl.cpp'
97--- src/api/itemfactoryimpl.cpp 2013-06-18 23:53:59 +0000
98+++ src/api/itemfactoryimpl.cpp 2013-06-28 04:21:28 +0000
99@@ -1,12 +1,12 @@
100 /*
101 * Copyright 2006-2008 The FLWOR Foundation.
102- *
103+ *
104 * Licensed under the Apache License, Version 2.0 (the "License");
105 * you may not use this file except in compliance with the License.
106 * You may obtain a copy of the License at
107- *
108+ *
109 * http://www.apache.org/licenses/LICENSE-2.0
110- *
111+ *
112 * Unless required by applicable law or agreed to in writing, software
113 * distributed under the License is distributed on an "AS IS" BASIS,
114 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
115@@ -45,25 +45,25 @@
116
117
118 namespace zorba {
119-
120+
121 ItemFactoryImpl::ItemFactoryImpl()
122 {
123 theItemFactory = GENV_ITEMFACTORY;
124 }
125
126
127-ItemFactoryImpl::~ItemFactoryImpl()
128+ItemFactoryImpl::~ItemFactoryImpl()
129 {
130 }
131
132
133 Item ItemFactoryImpl::createString(const String& aString)
134 {
135- zstring lString = Unmarshaller::getInternalString(aString);
136+ zstring lString = Unmarshaller::getInternalString(aString);
137 store::Item_t lItem;
138-
139+
140 theItemFactory->createString(lItem, lString);
141-
142+
143 return &*lItem;
144 }
145
146@@ -94,14 +94,14 @@
147 Item ItemFactoryImpl::createAnyURI(const String& aURI)
148 {
149 zstring lString = Unmarshaller::getInternalString(aURI);
150-
151+
152 store::Item_t lItem;
153 theItemFactory->createAnyURI(lItem, lString);
154-
155+
156 return &*lItem;
157 }
158
159-
160+
161 Item ItemFactoryImpl::createDate( const String& aDateValue )
162 {
163 zstring const &lString = Unmarshaller::getInternalString( aDateValue );
164@@ -133,19 +133,19 @@
165 zstring const &lNamespace = Unmarshaller::getInternalString( aNamespace );
166 zstring const &lPrefix = Unmarshaller::getInternalString( aPrefix );
167 zstring const &lLocalname = Unmarshaller::getInternalString( aLocalname );
168-
169+
170 if (!GenericCast::instance()->castableToNCName(lLocalname.c_str()))
171 {
172- RAISE_ERROR_NO_LOC(err::FORG0001,
173+ RAISE_ERROR_NO_LOC(err::FORG0001,
174 ERROR_PARAMS(ZED(FORG0001_LocalNotNCName_2), lLocalname));
175 }
176
177 if (lPrefix.size() && !GenericCast::instance()->castableToNCName(lPrefix.c_str()))
178 {
179- RAISE_ERROR_NO_LOC(err::FORG0001,
180+ RAISE_ERROR_NO_LOC(err::FORG0001,
181 ERROR_PARAMS(ZED(FORG0001_PrefixNotNCName_2), lPrefix));
182 }
183-
184+
185 store::Item_t lItem;
186 theItemFactory->createQName(lItem, lNamespace, lPrefix, lLocalname);
187 return &*lItem;
188@@ -161,15 +161,15 @@
189
190 if (!GenericCast::instance()->castableToNCName(lLocalname.c_str()))
191 {
192- RAISE_ERROR_NO_LOC(err::FORG0001,
193+ RAISE_ERROR_NO_LOC(err::FORG0001,
194 ERROR_PARAMS(ZED(FORG0001_LocalNotNCName_2), lLocalname));
195 }
196-
197+
198 store::Item_t lItem;
199 theItemFactory->createQName(lItem, lNamespace, zstring(), lLocalname);
200 return &*lItem;
201 }
202-
203+
204
205 Item
206 ItemFactoryImpl::createQName(const String& aQNameString)
207@@ -180,7 +180,7 @@
208 size_t lOpen = lQNameString.find("{");
209 size_t lClose = lQNameString.find("}");
210
211- if (lOpen == 0 && lClose != std::string::npos)
212+ if (lOpen == 0 && lClose != std::string::npos)
213 {
214 zstring const &lNamespace = lQNameString.substr(1, lClose - 1);
215 zstring const &lLocalname = lQNameString.substr(lClose+1);
216@@ -188,7 +188,7 @@
217
218 if (!GenericCast::instance()->castableToNCName(lLocalname.c_str()))
219 {
220- RAISE_ERROR_NO_LOC(err::FORG0001,
221+ RAISE_ERROR_NO_LOC(err::FORG0001,
222 ERROR_PARAMS(ZED(FORG0001_LocalNotNCName_2), lLocalname));
223 }
224 }
225@@ -205,54 +205,36 @@
226 RAISE_ERROR_NO_LOC(err::FORG0001,
227 ERROR_PARAMS(ZED(FORG0001_NameNotNCName_2), lString));
228 }
229-
230+
231 store::Item_t lItem;
232 theItemFactory->createNCName(lItem, lString);
233 return &*lItem;
234 }
235
236-
237-Item ItemFactoryImpl::createBase64Binary(const char* aBinData, size_t aLength)
238-{
239- store::Item_t lItem;
240- xs_base64Binary n;
241- std::string lMessage;
242- if (xs_base64Binary::parseString(aBinData, aLength, n, lMessage))
243- {
244- theItemFactory->createBase64Binary(lItem, n);
245- }
246- else
247- {
248- throw ZORBA_EXCEPTION(zerr::ZSTR0040_TYPE_ERROR, ERROR_PARAMS(lMessage));
249- }
250- return &*lItem;
251-}
252-
253-
254-Item ItemFactoryImpl::createBase64Binary(const unsigned char* aBinData, size_t aLength)
255-{
256- store::Item_t lItem;
257- xs_base64Binary n;
258- std::string lMessage;
259- xs_base64Binary::encode(aBinData, aLength, n);
260- theItemFactory->createBase64Binary(lItem, n);
261- return &*lItem;
262+
263+Item ItemFactoryImpl::createBase64Binary(const char* aData, size_t aLength,
264+ bool aIsBase64)
265+{
266+ try {
267+ store::Item_t result;
268+ xs_base64Binary b64( aData, aLength, aIsBase64 );
269+ theItemFactory->createBase64Binary( result, b64 );
270+ return &*result;
271+ }
272+ catch ( std::exception const &e ) {
273+ throw ZORBA_EXCEPTION(
274+ zerr::ZSTR0040_TYPE_ERROR, ERROR_PARAMS( e.what() )
275+ );
276+ }
277 }
278
279
280 Item ItemFactoryImpl::createBase64Binary(std::istream& aEncodedStream)
281 {
282- std::stringstream lSs;
283- while (aEncodedStream.good())
284- {
285- char c = aEncodedStream.get();
286- if (aEncodedStream.good())
287- {
288- lSs.put(c);
289- }
290- }
291- std::string lContent = lSs.str();
292- return createBase64Binary(lContent.c_str(), lContent.size());
293+ std::ostringstream oss;
294+ oss << aEncodedStream.rdbuf();
295+ std::string const temp( oss.str() );
296+ return createBase64Binary( temp.data(), temp.size(), true );
297 }
298
299
300@@ -265,8 +247,8 @@
301 {
302 store::Item_t lItem;
303 theItemFactory->createStreamableBase64Binary(
304- lItem, stream, streamReleaser, seekable, encoded
305- );
306+ lItem, stream, streamReleaser, seekable, encoded
307+ );
308 return &*lItem;
309 }
310
311@@ -281,8 +263,8 @@
312 {
313 store::Item_t lItem;
314 theItemFactory->createStreamableBase64Binary(
315- lItem, stream, streamReleaser, uri, seekable, encoded
316- );
317+ lItem, stream, streamReleaser, uri, seekable, encoded
318+ );
319 return &*lItem;
320 }
321
322@@ -293,8 +275,8 @@
323 theItemFactory->createBoolean(lItem, aValue);
324 return &*lItem;
325 }
326-
327-
328+
329+
330 Item ItemFactoryImpl::createDecimalFromLong (unsigned long aValue)
331 {
332 store::Item_t lItem;
333@@ -302,8 +284,8 @@
334 theItemFactory->createDecimal(lItem, lDecimal);
335 return &*lItem;
336 }
337-
338-
339+
340+
341 Item ItemFactoryImpl::createDecimalFromDouble (double aValue)
342 {
343 store::Item_t lItem;
344@@ -357,7 +339,7 @@
345 }
346 return &*lItem;
347 }
348-
349+
350
351 Item ItemFactoryImpl::createLong ( long long aLong )
352 {
353@@ -366,7 +348,7 @@
354 theItemFactory->createLong(lItem, aLong);
355 return &*lItem;
356 }
357-
358+
359
360 Item ItemFactoryImpl::createInt ( int aInt )
361 {
362@@ -378,7 +360,7 @@
363
364 return &*lItem;
365 }
366-
367+
368
369 Item ItemFactoryImpl::createShort ( short aShort )
370 {
371@@ -388,8 +370,8 @@
372
373 return &*lItem;
374 }
375-
376-
377+
378+
379 Item ItemFactoryImpl::createByte ( char aValue )
380 {
381 store::Item_t lItem;
382@@ -398,8 +380,8 @@
383
384 return &*lItem;
385 }
386-
387-
388+
389+
390 Item ItemFactoryImpl::createDateTime(short aYear, short aMonth, short aDay,
391 short aHour, short aMinute, double aSecond,
392 int aTimezone)
393@@ -468,7 +450,7 @@
394 return &*lItem;
395 }
396
397-
398+
399 Item ItemFactoryImpl::createDouble ( const String& aValue )
400 {
401 zstring lString = Unmarshaller::getInternalString( aValue );
402@@ -498,17 +480,17 @@
403 Item ItemFactoryImpl::createDuration(
404 short aYears,
405 short aMonths,
406- short aDays,
407+ short aDays,
408 short aHours,
409 short aMinutes,
410 double aSeconds )
411 {
412 store::Item_t lItem;
413-
414+
415 theItemFactory->createDuration(lItem,
416 aYears, aMonths, aDays,
417 aHours, aMinutes, aSeconds);
418-
419+
420 return &*lItem;
421 }
422
423@@ -551,7 +533,7 @@
424 try {
425 xs_float const lFloat(lString);
426 theItemFactory->createFloat(lItem, lFloat);
427- }
428+ }
429 catch ( std::exception const& ) {
430 // ignore
431 }
432@@ -567,7 +549,7 @@
433 return &*lItem;
434 }
435
436-
437+
438 Item ItemFactoryImpl::createHexBinary( const char* aHexData, size_t aSize,
439 bool aIsEncoded )
440 {
441@@ -586,7 +568,7 @@
442 }
443 return &*lItem;
444 }
445-
446+
447
448 Item ItemFactoryImpl::createNonNegativeInteger ( unsigned long long aValue )
449 {
450@@ -623,41 +605,41 @@
451 store::Item_t lItem;
452
453 theItemFactory->createGDay(lItem, lString.c_str(), lString.size());
454-
455+
456 return &*lItem;
457 }
458-
459+
460
461 Item ItemFactoryImpl::createGDay ( short aDay )
462 {
463 store::Item_t lItem;
464
465 theItemFactory->createGDay(lItem, aDay );
466-
467+
468 return &*lItem;
469 }
470-
471-
472+
473+
474 Item ItemFactoryImpl::createGMonth ( short aMonth )
475 {
476 store::Item_t lItem;
477
478 theItemFactory->createGMonth(lItem, aMonth );
479-
480+
481 return &*lItem;
482 }
483
484-
485+
486 Item ItemFactoryImpl::createGMonth ( const String& aValue )
487 {
488 zstring lString = Unmarshaller::getInternalString(aValue);
489 store::Item_t lItem;
490-
491+
492 theItemFactory->createGMonth(lItem, lString.c_str(), lString.size());
493-
494+
495 return &*lItem;
496 }
497-
498+
499
500 Item ItemFactoryImpl::createGMonthDay(const String& aValue)
501 {
502@@ -665,7 +647,7 @@
503 store::Item_t lItem;
504
505 theItemFactory->createGMonthDay(lItem, lString.c_str(), lString.size());
506-
507+
508 return &*lItem;
509 }
510
511@@ -675,10 +657,10 @@
512 store::Item_t lItem;
513
514 theItemFactory->createGMonthDay(lItem, aMonth, aDay );
515-
516+
517 return &*lItem;
518 }
519-
520+
521
522 Item ItemFactoryImpl::createGYear(const String& aValue)
523 {
524@@ -686,7 +668,7 @@
525 store::Item_t lItem;
526
527 theItemFactory->createGYear(lItem, lString.c_str(), lString.size() );
528-
529+
530 return &*lItem;
531 }
532
533@@ -696,10 +678,10 @@
534 store::Item_t lItem;
535
536 theItemFactory->createGYear(lItem, aYear );
537-
538+
539 return &*lItem;
540 }
541-
542+
543
544 Item ItemFactoryImpl::createGYearMonth ( const String& aValue )
545 {
546@@ -707,17 +689,17 @@
547 store::Item_t lItem;
548
549 theItemFactory->createGYearMonth(lItem, lString.c_str(), lString.size());
550-
551+
552 return &*lItem;
553 }
554
555-
556+
557 Item ItemFactoryImpl::createGYearMonth ( short aYear, short aMonth )
558 {
559 store::Item_t lItem;
560
561 theItemFactory->createGYearMonth(lItem, aYear, aMonth );
562-
563+
564 return &*lItem;
565 }
566
567@@ -728,17 +710,17 @@
568 store::Item_t lItem;
569
570 theItemFactory->createTime(lItem, lString.c_str(), lString.size() );
571-
572+
573 return &*lItem;
574 }
575-
576+
577
578 Item ItemFactoryImpl::createTime ( short aHour, short aMinute, double aSecond )
579 {
580 store::Item_t lItem;
581
582 theItemFactory->createTime(lItem, aHour, aMinute, aSecond );
583-
584+
585 return &*lItem;
586 }
587
588@@ -753,7 +735,7 @@
589 theItemFactory->createTime(lItem, aHour, aMinute, aSecond, aTimezone );
590 return &*lItem;
591 }
592-
593+
594
595 Item ItemFactoryImpl::createUnsignedByte(const unsigned char aValue)
596 {
597@@ -761,19 +743,19 @@
598 theItemFactory->createUnsignedByte(lItem, aValue);
599 return &*lItem;
600 }
601-
602+
603
604 Item ItemFactoryImpl::createUnsignedInt(unsigned int aValue)
605 {
606 store::Item_t lItem;
607-
608+
609 if ( aValue <= UINT32_MAX ) {
610 theItemFactory->createUnsignedInt(lItem, aValue);
611 }
612
613 return &*lItem;
614 }
615-
616+
617
618 Item ItemFactoryImpl::createUnsignedLong(unsigned long long aValue)
619 {
620@@ -781,7 +763,7 @@
621 theItemFactory->createUnsignedLong(lItem, aValue);
622 return &*lItem;
623 }
624-
625+
626
627 Item ItemFactoryImpl::createUnsignedShort(unsigned short aValue)
628 {
629@@ -973,7 +955,7 @@
630
631 std::vector<std::pair<Item, Item> >::iterator i = aPairs.begin();
632 std::vector<std::pair<Item, Item> >::iterator end = aPairs.end();
633- for (; i != end; i++)
634+ for (; i != end; i++)
635 {
636 names.push_back(Unmarshaller::getInternalItem((*i).first));
637 values.push_back(Unmarshaller::getInternalItem((*i).second));
638@@ -1001,7 +983,7 @@
639 items.reserve(numItems);
640 std::vector<Item>::iterator ite = aItems.begin();
641 std::vector<Item>::iterator end = aItems.end();
642- for (; ite != end; ++ite)
643+ for (; ite != end; ++ite)
644 {
645 items.push_back(Unmarshaller::getInternalItem(*ite));
646 }
647
648=== modified file 'src/api/itemfactoryimpl.h'
649--- src/api/itemfactoryimpl.h 2013-06-18 23:53:59 +0000
650+++ src/api/itemfactoryimpl.h 2013-06-28 04:21:28 +0000
651@@ -67,14 +67,11 @@
652 createNCName(const String& aValue);
653
654 virtual Item
655- createBase64Binary(const char* aBinData, size_t aLength);
656+ createBase64Binary(const char* aBinData, size_t aLength, bool aIsBase64);
657
658 virtual Item
659 createBase64Binary(std::istream& aStream);
660
661- virtual Item
662- createBase64Binary(const unsigned char* aBinData, size_t aLength);
663-
664 virtual Item
665 createStreamableBase64Binary(
666 std::istream &stream,
667
668=== modified file 'src/store/naive/atomic_items.cpp'
669--- src/store/naive/atomic_items.cpp 2013-06-18 23:53:59 +0000
670+++ src/store/naive/atomic_items.cpp 2013-06-28 04:21:28 +0000
671@@ -45,6 +45,7 @@
672 #include "tree_id.h"
673
674 #include "util/ascii_util.h"
675+#include "util/base64_util.h"
676 #include "util/mem_sizeof.h"
677 #include "util/string_util.h"
678 #include "util/utf8_util.h"
679@@ -3516,8 +3517,7 @@
680 else
681 {
682 std::vector<char> encoded;
683- encoded.reserve(theValue.size());
684- Base64::encode(theValue, encoded);
685+ base64::encode( &theValue[0], theValue.size(), &encoded );
686 buf.insert(buf.size(), &encoded[0], encoded.size());
687 }
688 }
689@@ -3778,7 +3778,7 @@
690 buf.insert(buf.size(), &theValue[0], theValue.size());
691 else
692 {
693- std::vector<char> encoded;
694+ Base16::value_type encoded;
695 Base16::encode(theValue, encoded);
696 buf.insert(buf.size(), &encoded[0], encoded.size());
697 }
698
699=== modified file 'src/store/naive/simple_item_factory.cpp'
700--- src/store/naive/simple_item_factory.cpp 2013-06-18 23:53:59 +0000
701+++ src/store/naive/simple_item_factory.cpp 2013-06-28 04:21:28 +0000
702@@ -1128,7 +1128,7 @@
703 store::Item_t& result,
704 xs_base64Binary const &value)
705 {
706- const std::vector<char>& data = value.getData();
707+ const std::vector<char>& data = value.data();
708 result = new Base64BinaryItem(store::XS_BASE64BINARY,
709 data.size() != 0 ? &data[0] : 0,
710 data.size(),
711@@ -1184,7 +1184,7 @@
712 bool BasicItemFactory::createHexBinary(store::Item_t& result,
713 xs_hexBinary const &value)
714 {
715- std::vector<char> const &data = value.getData();
716+ std::vector<char> const &data = value.data();
717 result = new HexBinaryItem(
718 store::XS_HEXBINARY, data.empty() ? 0 : &data[0], data.size(), true
719 );
720
721=== modified file 'src/types/casting.cpp'
722--- src/types/casting.cpp 2013-06-19 22:18:54 +0000
723+++ src/types/casting.cpp 2013-06-28 04:21:28 +0000
724@@ -1539,12 +1539,8 @@
725 T1_TO_T2(b64, hxB)
726 {
727 size_t s;
728- const char* c = aItem->getBase64BinaryValue(s);
729- xs_base64Binary tmp;
730- if (aItem->isEncoded())
731- xs_base64Binary::parseString(c, s, tmp);
732- else
733- xs_base64Binary::encode(c, s, tmp);
734+ char const *const c = aItem->getBase64BinaryValue(s);
735+ xs_base64Binary tmp( c, s, aItem->isEncoded() );
736 aFactory->createHexBinary(result, xs_hexBinary(tmp));
737 }
738
739@@ -1567,11 +1563,7 @@
740 {
741 size_t s;
742 char const *const c = aItem->getHexBinaryValue(s);
743- xs_hexBinary tmp;
744- if (aItem->isEncoded())
745- xs_hexBinary::parseString(c, s, tmp);
746- else
747- xs_hexBinary::encode(c, s, tmp);
748+ xs_hexBinary tmp( c, s, aItem->isEncoded() );
749 aFactory->createBase64Binary(result, xs_base64Binary(tmp));
750 }
751
752
753=== modified file 'src/zorbaserialization/serialize_zorba_types.cpp'
754--- src/zorbaserialization/serialize_zorba_types.cpp 2013-06-15 02:57:08 +0000
755+++ src/zorbaserialization/serialize_zorba_types.cpp 2013-06-28 04:21:28 +0000
756@@ -160,7 +160,7 @@
757 ********************************************************************************/
758 void operator&(Archiver& ar, Base64& obj)
759 {
760- ar & obj.theData;
761+ ar & obj.data_;
762 }
763
764
765@@ -169,7 +169,7 @@
766 ********************************************************************************/
767 void operator&(Archiver& ar, Base16& obj)
768 {
769- ar & obj.theData;
770+ ar & obj.data_;
771 }
772
773
774@@ -722,18 +722,8 @@
775
776 size_t s;
777 const char* c = obj->getHexBinaryValue(s);
778- if (obj->isEncoded())
779- {
780- Base16 tmp;
781- Base16::parseString(c, s, tmp);
782- ar & tmp;
783- }
784- else
785- {
786- Base16 tmp(c, s);
787- ar & tmp;
788- }
789-
790+ Base16 tmp( c, s, obj->isEncoded() );
791+ ar & tmp;
792 ar.set_is_temp_field(false);
793
794 break;
795@@ -744,18 +734,8 @@
796
797 size_t s;
798 const char* c = obj->getBase64BinaryValue(s);
799- if (obj->isEncoded())
800- {
801- Base64 tmp;
802- Base64::parseString(c, s, tmp);
803- ar & tmp;
804- }
805- else
806- {
807- Base64 tmp(c, s);
808- ar & tmp;
809- }
810-
811+ Base64 tmp( c, s, obj->isEncoded() );
812+ ar & tmp;
813 ar.set_is_temp_field(false);
814
815 break;
816
817=== modified file 'src/zorbatypes/binary.cpp'
818--- src/zorbatypes/binary.cpp 2013-05-08 01:05:04 +0000
819+++ src/zorbatypes/binary.cpp 2013-06-28 04:21:28 +0000
820@@ -36,18 +36,6 @@
821
822 ///////////////////////////////////////////////////////////////////////////////
823
824-#define CATCH_BASE64_EXCEPTION() \
825- catch (const base64::exception& e) \
826- { \
827- throw XQUERY_EXCEPTION(err::FORG0001, \
828- ERROR_PARAMS(ZED(FORG0001_Base64BadChar_2), e.invalid_char())); \
829- } \
830- catch (const std::invalid_argument&) \
831- { \
832- throw XQUERY_EXCEPTION(err::FORG0001, \
833- ERROR_PARAMS(ZED(FORG0001_Base64Multiple4))); \
834- }
835-
836 static size_t copy_without_ws( char const *from, size_t from_len, char *to ) {
837 char const *const to_orig = to;
838 for ( char const *const from_end = from + from_len; from < from_end; ++from )
839@@ -56,106 +44,26 @@
840 return to - to_orig;
841 }
842
843-
844-bool Base64::parseString(char const *s, size_t len, Base64& aBase64)
845-{
846- if ( len ) {
847- try
848- {
849- base64::validate( s, len, base64::dopt_ignore_ws );
850- aBase64.theData.resize( len );
851- aBase64.theData.resize(
852- copy_without_ws( s, len, &aBase64.theData[0] )
853- );
854- }
855- catch (...)
856- {
857- return false;
858- }
859- } else
860- aBase64.theData.clear();
861- return true;
862-}
863-
864-
865-bool Base64::parseString( char const *s, size_t len, Base64 &aBase64,
866- string &lErrorMessage )
867-{
868- if ( len ) {
869- try
870- {
871- base64::validate( s, len, base64::dopt_ignore_ws );
872- aBase64.theData.resize( len );
873- aBase64.theData.resize(
874- copy_without_ws( s, len, &aBase64.theData[0] )
875- );
876- }
877- catch (ZorbaException const& e)
878- {
879- lErrorMessage = e.what();
880- return false;
881- }
882- } else
883- aBase64.theData.clear();
884- return true;
885-}
886-
887-
888-void Base64::encode( zstring const &s, Base64 &to )
889-{
890- base64::encode( s.data(), s.size(), &to.theData );
891-}
892-
893-
894-void Base64::encode( istream &is, Base64 &to )
895-{
896- base64::encode( is, &to.theData );
897-}
898-
899-
900-zstring Base64::encode( istream &is )
901-{
902- zstring result;
903- base64::encode( is, &result );
904- return result;
905-}
906-
907-
908-void Base64::encode( vector<char> const &from, vector<char> &to )
909-{
910- if ( !from.empty() )
911- base64::encode( &from[0], from.size(), &to );
912-}
913-
914-
915-void Base64::encode( char const *from, size_t from_len, Base64 &to )
916-{
917- base64::encode( from, from_len, &to.theData );
918-}
919-
920-
921-void Base64::decode( istream &is, zstring *to )
922-{
923+///////////////////////////////////////////////////////////////////////////////
924+
925+#define CATCH_BASE64_EXCEPTION() \
926+ catch ( base64::exception const &e ) { \
927+ throw XQUERY_EXCEPTION( err::FORG0001, \
928+ ERROR_PARAMS( ZED(FORG0001_Base64BadChar_2), e.invalid_char() ) ); \
929+ } \
930+ catch ( std::invalid_argument const& ) { \
931+ throw XQUERY_EXCEPTION( err::FORG0001, \
932+ ERROR_PARAMS( ZED(FORG0001_Base64Multiple4) ) ); \
933+ }
934+
935+void Base64::decode( istream &is, zstring *to ) {
936 try {
937 base64::decode( is, to, base64::dopt_any_len | base64::dopt_ignore_ws );
938 }
939 CATCH_BASE64_EXCEPTION()
940 }
941
942-void Base64::decode(vector<char> const &from, vector<char> &to )
943-{
944- if ( !from.empty() ) {
945- try {
946- base64::decode(
947- &from[0], from.size(), &to,
948- base64::dopt_any_len | base64::dopt_ignore_ws
949- );
950- }
951- CATCH_BASE64_EXCEPTION()
952- }
953-}
954-
955-void Base64::decode( char const *from, size_t from_len, zstring *to ) {
956+void Base64::decode( char const *from, size_type from_len, zstring *to ) {
957 try {
958 base64::decode(
959 from, from_len, to, base64::dopt_any_len | base64::dopt_ignore_ws
960@@ -164,150 +72,96 @@
961 CATCH_BASE64_EXCEPTION()
962 }
963
964-
965-Base64::Base64( Base16 const &aBase16 )
966-{
967- vector<char> tmp;
968- Base16::decode( aBase16.getData(), tmp );
969- Base64::encode( tmp, theData );
970+Base64::Base64( Base16 const &b16 ) {
971+ value_type tmp;
972+ hexbinary::decode( &b16.data()[0], b16.size(), &tmp );
973+ base64::encode( &tmp[0], tmp.size(), &data_ );
974 }
975
976-
977-Base64::Base64( char const *bin_data, size_t len )
978-{
979+Base64& Base64::assign( char const *data, size_type size, bool is_encoded ) {
980 try {
981- base64::encode( bin_data, len, &theData );
982+ if ( is_encoded ) {
983+ base64::validate( data, size, base64::dopt_ignore_ws );
984+ data_.resize( size );
985+ data_.resize( copy_without_ws( data, size, &data_[0] ) );
986+ } else
987+ base64::encode( data, size, &data_ );
988+ return *this;
989 }
990 CATCH_BASE64_EXCEPTION()
991 }
992
993-
994-
995-bool Base64::equal( Base64 const &aBase64 ) const
996-{
997- if ( size() != aBase64.size() )
998- return false;
999- return ::strncmp( &theData[0], &aBase64.theData[0], size() ) == 0;
1000-}
1001-
1002-
1003-zstring Base64::str() const
1004-{
1005- zstring result;
1006- if ( theData.size() )
1007- result.assign( &theData[0], theData.size() );
1008- return result;
1009-}
1010-
1011-
1012-zstring Base64::decode() const
1013-{
1014- zstring result;
1015- if ( !theData.empty() )
1016- base64::decode( &theData[0], theData.size(), &result );
1017- return result;
1018-}
1019-
1020-
1021-void Base64::decode( vector<char> &to )
1022-{
1023- if ( !theData.empty() )
1024- base64::decode( &theData[0], theData.size(), &to );
1025-}
1026-
1027-
1028-uint32_t Base64::hash() const
1029-{
1030- return theData.size() ? ztd::hash_bytes( &theData[0], theData.size() ) : 0;
1031-}
1032-
1033-
1034-ostream& operator<<(ostream& os, const Base64& aBase64)
1035-{
1036- if ( aBase64.size() )
1037- os.write( &aBase64.getData()[0], aBase64.size() );
1038- return os;
1039+uint32_t Base64::hash() const {
1040+ return data_.size() ? ztd::hash_bytes( &data_[0], data_.size() ) : 0;
1041+}
1042+
1043+bool Base64::parseString( char const *s, size_type size, Base64 &b64 ) {
1044+ if ( size ) {
1045+ try {
1046+ base64::validate( s, size, base64::dopt_ignore_ws );
1047+ b64.data_.resize( size );
1048+ b64.data_.resize( copy_without_ws( s, size, &b64.data_[0] ) );
1049+ }
1050+ catch ( std::exception const& ) {
1051+ return false;
1052+ }
1053+ } else
1054+ b64.data_.clear();
1055+ return true;
1056 }
1057
1058 ///////////////////////////////////////////////////////////////////////////////
1059
1060 #define CATCH_HEXBINARY_EXCEPTION() \
1061- catch (const hexbinary::exception& e) \
1062- { \
1063- throw XQUERY_EXCEPTION(err::FORG0001, \
1064- ERROR_PARAMS(ZED(FORG0001_BadHexDigit_2), e.invalid_char())); \
1065+ catch ( hexbinary::exception const &e ) { \
1066+ throw XQUERY_EXCEPTION( err::FORG0001, \
1067+ ERROR_PARAMS( ZED(FORG0001_BadHexDigit_2), e.invalid_char() ) ); \
1068 } \
1069- catch (const std::invalid_argument&) \
1070- { \
1071- throw XQUERY_EXCEPTION(err::FORG0001, \
1072- ERROR_PARAMS(ZED(FORG0001_HexBinaryMustBeEven))); \
1073- }
1074-
1075-Base16::Base16( char const *bin_data, size_t len )
1076-{
1077- try {
1078- hexbinary::encode( bin_data, len, &theData );
1079- }
1080- CATCH_HEXBINARY_EXCEPTION()
1081-}
1082-
1083-Base16::Base16(Base64 const &aBase64)
1084-{
1085- vector<char> lOrig;
1086- Base64::decode(aBase64.getData(), lOrig);
1087- Base16::encode(lOrig, theData);
1088-}
1089-
1090-
1091-bool Base16::parseString(char const *s, size_t len, Base16& aBase16)
1092-{
1093- if ( len ) {
1094- try
1095- {
1096- hexbinary::validate( s, len, hexbinary::dopt_ignore_ws );
1097- aBase16.theData.resize( len );
1098- aBase16.theData.resize(
1099- copy_without_ws( s, len, &aBase16.theData[0] )
1100- );
1101- }
1102- catch (...)
1103- {
1104+ catch ( std::invalid_argument const& ) { \
1105+ throw XQUERY_EXCEPTION( err::FORG0001, \
1106+ ERROR_PARAMS(ZED(FORG0001_HexBinaryMustBeEven) ) ); \
1107+ }
1108+
1109+Base16::Base16( Base64 const &b64 ) {
1110+ value_type temp;
1111+ base64::decode( &b64.data()[0], b64.size(), &temp );
1112+ assign( &temp[0], temp.size(), false );
1113+}
1114+
1115+Base16& Base16::assign( char const *data, size_type size, bool is_encoded ) {
1116+ if ( !size )
1117+ data_.clear();
1118+ else {
1119+ try {
1120+ if ( is_encoded ) {
1121+ hexbinary::validate( data, size, hexbinary::dopt_ignore_ws );
1122+ data_.resize( size );
1123+ data_.resize( copy_without_ws( data, size, &data_[0] ) );
1124+ } else
1125+ hexbinary::encode( data, size, &data_ );
1126+ }
1127+ CATCH_HEXBINARY_EXCEPTION()
1128+ }
1129+ return *this;
1130+}
1131+
1132+bool Base16::parseString( char const *data, size_type size, Base16 &b16 ) {
1133+ if ( !size )
1134+ b16.data_.clear();
1135+ else {
1136+ try {
1137+ hexbinary::validate( data, size, hexbinary::dopt_ignore_ws );
1138+ b16.data_.resize( size );
1139+ b16.data_.resize( copy_without_ws( data, size, &b16.data_[0] ) );
1140+ }
1141+ catch ( std::exception const& ) {
1142 return false;
1143 }
1144- } else
1145- aBase16.theData.clear();
1146+ }
1147 return true;
1148 }
1149
1150-
1151-void Base16::insertData(char const *s, size_t len)
1152-{
1153- s = ascii::trim_space( s, &len );
1154- try {
1155- hexbinary::encode( s, len, &theData );
1156- }
1157- CATCH_HEXBINARY_EXCEPTION()
1158-}
1159-
1160-
1161-bool Base16::equal( Base16 const &other ) const
1162-{
1163- if ( size() != other.size() )
1164- return false;
1165- return ::strncmp( &theData[0], &other.theData[0], theData.size() ) == 0;
1166-}
1167-
1168-
1169-zstring Base16::str() const
1170-{
1171- if ( size() )
1172- return zstring( &theData[0], size() );
1173- return zstring();
1174-}
1175-
1176-
1177-void Base16::encode( vector<char> const &from, vector<char> &to )
1178-{
1179+void Base16::encode( value_type const &from, value_type &to ) {
1180 if ( !from.empty() ) {
1181 try {
1182 hexbinary::encode( &from[0], from.size(), &to );
1183@@ -316,34 +170,8 @@
1184 }
1185 }
1186
1187-void Base16::encode( char const *from, size_t from_len, Base16 &to )
1188-{
1189- hexbinary::encode( from, from_len, &to.theData );
1190-}
1191-
1192-void Base16::decode( vector<char> const &from, vector<char> &to )
1193-{
1194- if ( !from.empty() ) {
1195- try {
1196- hexbinary::decode(
1197- &from[0], from.size(), &to, hexbinary::dopt_ignore_ws
1198- );
1199- }
1200- CATCH_HEXBINARY_EXCEPTION()
1201- }
1202-}
1203-
1204-uint32_t Base16::hash() const
1205-{
1206- return theData.size() ? ztd::hash_bytes( &theData[0], theData.size() ) : 0;
1207-}
1208-
1209-
1210-ostream& operator<<( ostream &os, Base16 const &b16 )
1211-{
1212- if ( b16.size() )
1213- os.write( &b16.getData()[0], b16.size() );
1214- return os;
1215+uint32_t Base16::hash() const {
1216+ return data_.size() ? ztd::hash_bytes( &data_[0], data_.size() ) : 0;
1217 }
1218
1219 ///////////////////////////////////////////////////////////////////////////////
1220
1221=== modified file 'src/zorbatypes/binary.h'
1222--- src/zorbatypes/binary.h 2013-03-17 04:02:46 +0000
1223+++ src/zorbatypes/binary.h 2013-06-28 04:21:28 +0000
1224@@ -26,160 +26,170 @@
1225
1226 namespace zorba {
1227
1228-
1229 class Base16;
1230 class Base64;
1231
1232-namespace serialization
1233-{
1234+namespace serialization {
1235 class Archiver;
1236- void operator&(Archiver& ar, Base64& obj);
1237- void operator&(Archiver& ar, Base16& obj);
1238+ void operator&( Archiver&, Base64& );
1239+ void operator&( Archiver&, Base16& );
1240 }
1241
1242 ///////////////////////////////////////////////////////////////////////////////
1243
1244-class Base64
1245-{
1246- friend void serialization::operator&(serialization::Archiver&, Base64&);
1247-
1248-private:
1249- std::vector<char> theData; // stored encoded
1250-
1251+class Base64 {
1252 public:
1253- static bool parseString( zstring const &s, Base64 &to )
1254- {
1255+ typedef std::vector<char> value_type;
1256+ typedef value_type::size_type size_type;
1257+
1258+ static bool parseString( char const *data, size_type size, Base64 &to );
1259+
1260+ static bool parseString( zstring const &s, Base64 &to ) {
1261 return parseString( s.data(), s.size(), to );
1262 }
1263
1264- static bool parseString(char const *s, size_t aLength, Base64& to);
1265-
1266- static bool parseString(
1267- const char* aString,
1268- size_t aLength,
1269- Base64& aBase64,
1270- std::string& lErrorMessage);
1271-
1272- static zstring encode(std::istream& aStream);
1273-
1274- static void encode(std::istream& aStream, Base64& to);
1275-
1276- static void encode(const zstring& aString, Base64&);
1277-
1278- static void encode(const std::vector<char>&, std::vector<char>&);
1279-
1280- static void encode(char const *from, size_t from_len, Base64 &to);
1281-
1282- static void encode(unsigned char const *from, size_t from_len, Base64& to) {
1283- return encode( (char const*)from, from_len, to );
1284- }
1285-
1286- static void decode(const std::vector<char>&, std::vector<char>&);
1287-
1288- static void decode(std::istream& aStream, zstring*);
1289-
1290- static void decode(char const*, size_t, zstring*);
1291+ static void decode( std::istream&, zstring* );
1292+
1293+ static void decode( char const*, size_type, zstring* );
1294
1295 public:
1296- Base64(const Base64& aBase64)
1297- {
1298- theData = aBase64.theData;
1299- }
1300-
1301- explicit Base64(const Base16& aBase16);
1302-
1303- Base64(char const *bin_data, size_t len);
1304-
1305- Base64() { }
1306-
1307- const std::vector<char>& getData() const { return theData; }
1308-
1309- size_t size() const { return theData.size(); }
1310-
1311- bool equal(const Base64& aBase64) const;
1312-
1313+ Base64();
1314+ Base64( Base64 const &b64 );
1315+ Base64( const char *data, size_type size, bool is_encoded );
1316+ explicit Base64( Base16 const &b16 );
1317+
1318+ size_t alloc_size() const;
1319+ Base64& assign( char const *data, size_type size, bool is_encoded );
1320+ value_type const& data() const;
1321+ uint32_t hash() const;
1322+ size_type size() const;
1323 zstring str() const;
1324
1325- zstring decode() const;
1326-
1327- void decode(std::vector<char>&);
1328-
1329- uint32_t hash() const;
1330-
1331- size_t alloc_size() const {
1332- return ztd::alloc_sizeof( theData );
1333- }
1334+private:
1335+ value_type data_; // stored encoded
1336+
1337+ friend void serialization::operator&( serialization::Archiver&, Base64& );
1338 };
1339
1340+///////////////////////////////////////////////////////////////////////////////
1341+
1342+inline Base64::Base64() {
1343+}
1344+
1345+inline Base64::Base64( Base64 const &b64 ) : data_( b64.data_ ) {
1346+}
1347+
1348+inline Base64::Base64( const char *data, size_type size, bool is_encoded ) {
1349+ assign( data, size, is_encoded );
1350+}
1351+
1352+inline size_t Base64::alloc_size() const {
1353+ return ztd::alloc_sizeof( data_ );
1354+}
1355+
1356+inline Base64::value_type const& Base64::data() const {
1357+ return data_;
1358+}
1359+
1360+inline Base64::size_type Base64::size() const {
1361+ return data_.size();
1362+}
1363+
1364+inline zstring Base64::str() const {
1365+ return size() ? zstring( &data_[0], size() ) : zstring();
1366+}
1367+
1368 inline bool operator==( Base64 const &a, Base64 const &b ) {
1369- return a.equal( b );
1370+ return a.size() == b.size()
1371+ && std::strncmp( &a.data()[0], &b.data()[0], a.size() ) == 0;
1372 }
1373
1374 inline bool operator!=( Base64 const &a, Base64 const &b ) {
1375 return !(a == b);
1376 }
1377
1378-std::ostream& operator<<( std::ostream&, Base64 const& );
1379+inline std::ostream& operator<<( std::ostream &o, Base64 const &b64 ) {
1380+ if ( b64.size() )
1381+ o.write( &b64.data()[0], b64.size() );
1382+ return o;
1383+}
1384
1385 ///////////////////////////////////////////////////////////////////////////////
1386
1387-class Base16
1388-{
1389+class Base16 {
1390+public:
1391+ typedef std::vector<char> value_type;
1392+ typedef value_type::size_type size_type;
1393+
1394+ static bool parseString( char const *data, size_type size, Base16 &to );
1395+
1396+ static bool parseString( zstring const &s, Base16 &to ) {
1397+ return parseString( s.data(), s.size(), to );
1398+ }
1399+
1400+ static void encode( value_type const&, value_type& );
1401+
1402+public:
1403+ Base16();
1404+ Base16( Base16 const &from );
1405+ Base16( char const *data, size_type size, bool is_encoded );
1406+ explicit Base16( Base64 const& );
1407+
1408+ size_t alloc_size() const;
1409+ Base16& assign( char const *data, size_type size, bool is_encoded );
1410+ value_type const& data() const;
1411+ uint32_t hash() const;
1412+ size_type size() const;
1413+ zstring str() const;
1414+
1415+private:
1416+ value_type data_; // stored encoded
1417+
1418 friend void serialization::operator&(serialization::Archiver&, Base16&);
1419-
1420-private:
1421- std::vector<char> theData; // stored encoded
1422-
1423-public:
1424- static bool parseString( zstring const &s, Base16 &to )
1425- {
1426- return parseString( s.data(), s.size(), to );
1427- }
1428-
1429- static bool parseString( char const *from, size_t from_len, Base16 &to );
1430-
1431- static void encode( std::vector<char> const&, std::vector<char>& );
1432-
1433- static void encode( char const *from, size_t from_len, Base16 &to );
1434-
1435- static void decode( std::vector<char> const&, std::vector<char>& );
1436-
1437-public:
1438- Base16() { }
1439-
1440- Base16( Base16 const &from ) : theData( from.theData ) { }
1441-
1442- Base16( char const *bin_data, size_t len );
1443-
1444- explicit Base16( Base64 const& );
1445-
1446- const std::vector<char>& getData() const { return theData; }
1447-
1448- size_t size() const { return theData.size(); }
1449-
1450- bool equal( Base16 const& ) const;
1451-
1452- zstring str() const;
1453-
1454- uint32_t hash() const;
1455-
1456- size_t alloc_size() const {
1457- return ztd::alloc_sizeof( theData );
1458- }
1459-
1460-private:
1461- void insertData( char const *from, size_t len );
1462 };
1463
1464+///////////////////////////////////////////////////////////////////////////////
1465+
1466+inline Base16::Base16() {
1467+}
1468+
1469+inline Base16::Base16( Base16 const &b16 ) : data_( b16.data_ ) {
1470+}
1471+
1472+inline Base16::Base16( char const *data, size_type size, bool is_encoded ) {
1473+ assign( data, size, is_encoded );
1474+}
1475+
1476+inline size_t Base16::alloc_size() const {
1477+ return ztd::alloc_sizeof( data_ );
1478+}
1479+
1480+inline Base16::value_type const& Base16::data() const {
1481+ return data_;
1482+}
1483+
1484+inline Base16::size_type Base16::size() const {
1485+ return data_.size();
1486+}
1487+
1488+inline zstring Base16::str() const {
1489+ return size() ? zstring( &data_[0], size() ) : zstring();
1490+}
1491+
1492 inline bool operator==( Base16 const &a, Base16 const &b ) {
1493- return a.equal( b );
1494+ return a.size() == b.size()
1495+ && std::strncmp( &a.data()[0], &b.data()[0], a.size() ) == 0;
1496 }
1497
1498 inline bool operator!=( Base16 const &a, Base16 const &b ) {
1499 return !(a == b);
1500 }
1501
1502-std::ostream& operator<<(std::ostream&s, const Base16& );
1503+inline std::ostream& operator<<( std::ostream &o, Base16 const &b16 ) {
1504+ if ( b16.size() )
1505+ o.write( &b16.data()[0], b16.size() );
1506+ return o;
1507+}
1508
1509 ///////////////////////////////////////////////////////////////////////////////
1510
1511
1512=== modified file 'swig/ItemFactory.h'
1513--- swig/ItemFactory.h 2013-06-18 23:53:59 +0000
1514+++ swig/ItemFactory.h 2013-06-28 04:21:28 +0000
1515@@ -64,11 +64,13 @@
1516 /** \brief Creates a Base64Binary Item
1517 * see [http://www.w3.org/TR/xmlschema-2/#base64Binary]
1518 *
1519- * @param aBinData a pointer to the base64 binary data.
1520+ * @param aData a pointer to the base64 binary data.
1521 * @param aLength the length of the base64 binary data.
1522+ * @param aIsBase64 if \c true, \a aData is already Base-64 encoded; if
1523+ * \c false, \a aData is raw binary data to be encoded.
1524 * @return The Base64Binary Item.
1525 */
1526- Item createBase64Binary (const char *aBinData, size_t aLength);
1527+ Item createBase64Binary (const char *aData, size_t aLength, bool aIsBase64);
1528
1529 /** \brief Creates a Base64Binary Item
1530 * see [http://www.w3.org/TR/xmlschema-2/#base64Binary]
1531@@ -78,15 +80,6 @@
1532 */
1533 Item createBase64Binary (std::istream &aStream);
1534
1535- /** \brief Creates a Base64Binary Item
1536- * see [http://www.w3.org/TR/xmlschema-2/#base64Binary]
1537- *
1538- * @param aBinData the data in binary form. The data is copied from aBinData.
1539- * @param aLength the length of the data
1540- * @return the Base64Binary Item.
1541- */
1542- Item createBase64Binary (const unsigned char *aBinData, size_t aLength);
1543-
1544 /** \brief Creates a Boolean Item
1545 * see [http://www.w3.org/TR/xmlschema-2/#bool]
1546 *
1547
1548=== modified file 'swig/ItemFactory.i'
1549--- swig/ItemFactory.i 2013-06-18 23:53:59 +0000
1550+++ swig/ItemFactory.i 2013-06-28 04:21:28 +0000
1551@@ -22,15 +22,12 @@
1552 return Item( theItemFactory->createAttributeNode (aParent.theItem, aNodeName.theItem, aTypeName.theItem, typedValue ));
1553 }
1554
1555- Item ItemFactory::createBase64Binary (const char *aBinData, size_t aLength){
1556- return Item( theItemFactory->createBase64Binary(aBinData, aLength));
1557+ Item ItemFactory::createBase64Binary (const char *aData, size_t aLength, bool aIsBase64){
1558+ return Item( theItemFactory->createBase64Binary(aData, aLength, aIsBase64));
1559 }
1560 Item ItemFactory::createBase64Binary (std::istream &aStream){
1561 return Item( theItemFactory->createBase64Binary(aStream));
1562 }
1563- Item ItemFactory::createBase64Binary (const unsigned char *aBinData, size_t aLength){
1564- return Item( theItemFactory->createBase64Binary(aBinData, aLength));
1565- }
1566 Item ItemFactory::createBoolean (bool aValue){
1567 return Item( theItemFactory->createBoolean(aValue));
1568 }
1569
1570=== modified file 'swig/xqj/ZorbaXQConnection.java'
1571--- swig/xqj/ZorbaXQConnection.java 2013-02-07 17:24:36 +0000
1572+++ swig/xqj/ZorbaXQConnection.java 2013-06-28 04:21:28 +0000
1573@@ -522,7 +522,7 @@
1574 item = new org.zorbaxquery.api.xqj.ZorbaXQItem(itemFactory.createAnyURI(value), type);
1575 break;
1576 case XQItemType.XQBASETYPE_BASE64BINARY:
1577- item = new org.zorbaxquery.api.xqj.ZorbaXQItem(itemFactory.createBase64Binary(value, value.length()), type);
1578+ item = new org.zorbaxquery.api.xqj.ZorbaXQItem(itemFactory.createBase64Binary(value, value.length(), true), type);
1579 break;
1580 case XQItemType.XQBASETYPE_BYTE:
1581 item = new org.zorbaxquery.api.xqj.ZorbaXQItem(itemFactory.createByte(value.charAt(0)), type);
1582@@ -947,7 +947,7 @@
1583 item = new org.zorbaxquery.api.xqj.ZorbaXQItem(itemFactory.createAnyURI(value.toString()), type);
1584 break;
1585 case XQItemType.XQBASETYPE_BASE64BINARY:
1586- item = new org.zorbaxquery.api.xqj.ZorbaXQItem(itemFactory.createBase64Binary(value.toString(), (value.toString()).length()), type);
1587+ item = new org.zorbaxquery.api.xqj.ZorbaXQItem(itemFactory.createBase64Binary(value.toString(), (value.toString()).length(), true), type);
1588 break;
1589 case XQItemType.XQBASETYPE_BYTE:
1590 if (value instanceof Byte) {
1591
1592=== modified file 'test/api/itemfactory.cpp'
1593--- test/api/itemfactory.cpp 2013-05-22 16:12:01 +0000
1594+++ test/api/itemfactory.cpp 2013-06-28 04:21:28 +0000
1595@@ -168,14 +168,14 @@
1596 CHECK_NOT_IMPLEMENTED (lItem, getBooleanValue() );
1597
1598 /** Base64Binary */
1599- lItem = lFactory->createBase64Binary("", 0);
1600+ lItem = lFactory->createBase64Binary("", 0, false);
1601 UNIT_ASSERT ( checkType(lItem.getType(), "base64Binary") );
1602 UNIT_ASSERT ( lItem.isAtomic() );
1603 UNIT_ASSERT ( lItem.getStringValue() == "" );
1604 UNIT_ASSERT ( lItem.getStringValue().length() == 0 );
1605 UNIT_ASSERT ( !lItem.getAtomizationValue().isNull() );
1606
1607- lItem = lFactory->createBase64Binary("cmxjZ3R4c3JidnllcmVuZG91aWpsbXV5Z2NhamxpcmJkaWFhbmFob2VsYXVwZmJ1Z2dmanl2eHlzYmhheXFtZXR0anV2dG1q", 96);
1608+ lItem = lFactory->createBase64Binary("cmxjZ3R4c3JidnllcmVuZG91aWpsbXV5Z2NhamxpcmJkaWFhbmFob2VsYXVwZmJ1Z2dmanl2eHlzYmhheXFtZXR0anV2dG1q", 96, true);
1609 UNIT_ASSERT ( checkType(lItem.getType(), "base64Binary") );
1610 UNIT_ASSERT ( lItem.isAtomic() );
1611 UNIT_ASSERT ( lItem.getStringValue() == "cmxjZ3R4c3JidnllcmVuZG91aWpsbXV5Z2NhamxpcmJkaWFhbmFob2VsYXVwZmJ1Z2dmanl2eHlzYmhheXFtZXR0anV2dG1q" );

Subscribers

People subscribed via source and target branches