Merge lp:~paul-lucas/zorba/pjl-misc into lp:zorba
- pjl-misc
- Merge into trunk
Proposed by
Paul J. Lucas
Status: | Merged |
---|---|
Approved by: | Matthias Brantner |
Approved revision: | 10953 |
Merged at revision: | 10952 |
Proposed branch: | lp:~paul-lucas/zorba/pjl-misc |
Merge into: | lp:zorba |
Diff against target: |
802 lines (+147/-319) 8 files modified
include/zorba/transcode_stream.h (+14/-0) src/api/serialization/serializer.cpp (+110/-98) src/api/serialization/serializer.h (+13/-15) src/util/json_parser.cpp (+3/-3) src/util/xml_util.h (+7/-3) src/zorbatypes/CMakeLists.txt (+0/-1) src/zorbatypes/transcoder.cpp (+0/-86) src/zorbatypes/transcoder.h (+0/-113) |
To merge this branch: | bzr merge lp:~paul-lucas/zorba/pjl-misc |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Matthias Brantner | Approve | ||
Paul J. Lucas | Approve | ||
Review via email: mp+116566@code.launchpad.net |
Commit message
Removed zorbatypes/
Description of the change
Removed zorbatypes/
To post a comment you must log in.
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 pjl-misc-
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. Got: 1 Pending.
Revision history for this message
Paul J. Lucas (paul-lucas) : | # |
review:
Approve
Revision history for this message
Matthias Brantner (matthias-brantner) : | # |
review:
Approve
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote : | # |
Validation queue starting for merge proposal.
Log at: http://
Revision history for this message
Zorba Build Bot (zorba-buildbot) wrote : | # |
Validation queue job pjl-misc-
All tests succeeded!
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'include/zorba/transcode_stream.h' |
2 | --- include/zorba/transcode_stream.h 2012-07-24 08:48:48 +0000 |
3 | +++ include/zorba/transcode_stream.h 2012-07-24 23:15:27 +0000 |
4 | @@ -189,6 +189,20 @@ |
5 | } |
6 | |
7 | /** |
8 | + * Gets the original streambuf of the given iostream. |
9 | + * |
10 | + * @param ios The stream to get the original streambuf of. |
11 | + * @return the original streambuf. |
12 | + */ |
13 | +template<typename charT,typename Traits> inline |
14 | +std::streambuf* orig_streambuf( std::basic_ios<charT,Traits> &ios ) { |
15 | + std::streambuf *const buf = ios.rdbuf(); |
16 | + if ( streambuf *const tbuf = dynamic_cast<streambuf*>( buf ) ) |
17 | + return tbuf->orig_streambuf(); |
18 | + return buf; |
19 | +} |
20 | + |
21 | +/** |
22 | * A %transcode::auto_attach is a class that attaches a transcode::streambuf to |
23 | * a stream and automatically detaches it when the %auto_attach object is |
24 | * destroyed. |
25 | |
26 | === modified file 'src/api/serialization/serializer.cpp' |
27 | --- src/api/serialization/serializer.cpp 2012-07-24 08:48:48 +0000 |
28 | +++ src/api/serialization/serializer.cpp 2012-07-24 23:15:27 +0000 |
29 | @@ -19,8 +19,8 @@ |
30 | #include <iomanip> |
31 | |
32 | #include <zorba/zorba_string.h> |
33 | -#include <zorbamisc/ns_consts.h> |
34 | -#include "zorbatypes/numconversions.h" |
35 | +#include <zorba/transcode_stream.h> |
36 | + |
37 | #include "diagnostics/xquery_diagnostics.h" |
38 | #include "diagnostics/assert.h" |
39 | |
40 | @@ -38,12 +38,14 @@ |
41 | #include "util/xml_util.h" |
42 | |
43 | #include "system/globalenv.h" |
44 | +#include "zorbamisc/ns_consts.h" |
45 | +#include "zorbatypes/numconversions.h" |
46 | |
47 | #include "store/api/iterator.h" |
48 | #include "store/api/iterator_factory.h" |
49 | #include "store/api/item.h" |
50 | -#include <store/api/item_factory.h> |
51 | -#include <store/api/copymode.h> |
52 | +#include "store/api/item_factory.h" |
53 | +#include "store/api/copymode.h" |
54 | |
55 | namespace zorba { |
56 | |
57 | @@ -116,11 +118,11 @@ |
58 | ********************************************************************************/ |
59 | serializer::emitter::emitter( |
60 | serializer* the_serializer, |
61 | - transcoder& the_transcoder, |
62 | + std::ostream& the_stream, |
63 | bool aEmitAttributes) |
64 | : |
65 | ser(the_serializer), |
66 | - tr(the_transcoder), |
67 | + tr(the_stream), |
68 | previous_item(INVALID_ITEM), |
69 | theChildIters(8), |
70 | theFirstFreeChildIter(0), |
71 | @@ -341,13 +343,12 @@ |
72 | { |
73 | if (ser->encoding == PARAMETER_VALUE_UTF_8 ) |
74 | { |
75 | - tr << (char)0xEF << (char)0xBB << (char)0xBF; |
76 | + transcode::orig_streambuf( tr )->sputn( "\xEF\xBB\xBF", 3 ); |
77 | } |
78 | else if (ser->encoding == PARAMETER_VALUE_UTF_16) |
79 | { |
80 | // Little-endian |
81 | - tr.verbatim((char)0xFF); |
82 | - tr.verbatim((char)0xFE); |
83 | + transcode::orig_streambuf( tr )->sputn( "\xFF\xFE", 2 ); |
84 | } |
85 | } |
86 | } |
87 | @@ -862,10 +863,10 @@ |
88 | ********************************************************************************/ |
89 | serializer::xml_emitter::xml_emitter( |
90 | serializer* the_serializer, |
91 | - transcoder& the_transcoder, |
92 | + std::ostream& the_stream, |
93 | bool aEmitAttributes) |
94 | : |
95 | - emitter(the_serializer, the_transcoder, aEmitAttributes) |
96 | + emitter(the_serializer, the_stream, aEmitAttributes) |
97 | { |
98 | } |
99 | |
100 | @@ -947,8 +948,8 @@ |
101 | |
102 | serializer::json_emitter::json_emitter( |
103 | serializer* the_serializer, |
104 | - transcoder& the_transcoder) |
105 | - : emitter(the_serializer, the_transcoder), |
106 | + std::ostream& the_stream) |
107 | + : emitter(the_serializer, the_stream), |
108 | theXMLStringStream(nullptr), |
109 | theMultipleItems(false) |
110 | { |
111 | @@ -1174,8 +1175,8 @@ |
112 | // and output it as a "JSONiq XDM node". |
113 | if (!theXMLEmitter) { |
114 | theXMLStringStream = new std::stringstream(); |
115 | - theXMLTranscoder = ser->create_transcoder(*theXMLStringStream); |
116 | - theXMLEmitter = new serializer::xml_emitter(ser, *theXMLTranscoder); |
117 | + ser->attach_transcoder(*theXMLStringStream); |
118 | + theXMLEmitter = new serializer::xml_emitter(ser, *theXMLStringStream); |
119 | } |
120 | theXMLEmitter->emit_item(item); |
121 | zstring xml(theXMLStringStream->str()); |
122 | @@ -1259,12 +1260,12 @@ |
123 | |
124 | serializer::jsoniq_emitter::jsoniq_emitter( |
125 | serializer* the_serializer, |
126 | - transcoder& the_transcoder) |
127 | + std::ostream& the_stream) |
128 | : |
129 | - emitter(the_serializer, the_transcoder), |
130 | + emitter(the_serializer, the_stream), |
131 | theEmitterState(JESTATE_UNDETERMINED), |
132 | - theXMLEmitter(new xml_emitter(the_serializer, the_transcoder)), |
133 | - theJSONEmitter(new json_emitter(the_serializer, the_transcoder)) |
134 | + theXMLEmitter(new xml_emitter(the_serializer, the_stream)), |
135 | + theJSONEmitter(new json_emitter(the_serializer, the_stream)) |
136 | { |
137 | } |
138 | |
139 | @@ -1458,9 +1459,9 @@ |
140 | ********************************************************************************/ |
141 | serializer::html_emitter::html_emitter( |
142 | serializer* the_serializer, |
143 | - transcoder& the_transcoder) |
144 | + std::ostream& the_stream) |
145 | : |
146 | - emitter(the_serializer, the_transcoder) |
147 | + emitter(the_serializer, the_stream) |
148 | { |
149 | } |
150 | |
151 | @@ -1720,9 +1721,9 @@ |
152 | ********************************************************************************/ |
153 | serializer::xhtml_emitter::xhtml_emitter( |
154 | serializer* the_serializer, |
155 | - transcoder& the_transcoder) |
156 | + std::ostream& the_stream) |
157 | : |
158 | - xml_emitter(the_serializer, the_transcoder) |
159 | + xml_emitter(the_serializer, the_stream) |
160 | { |
161 | } |
162 | |
163 | @@ -1856,11 +1857,11 @@ |
164 | ********************************************************************************/ |
165 | serializer::sax2_emitter::sax2_emitter( |
166 | serializer* the_serializer, |
167 | - transcoder& the_transcoder, |
168 | + std::ostream& the_stream, |
169 | std::stringstream& aSStream, |
170 | SAX2_ContentHandler * aSAX2ContentHandler ) |
171 | : |
172 | - emitter(the_serializer, the_transcoder), |
173 | + emitter(the_serializer, the_stream), |
174 | theSAX2ContentHandler( aSAX2ContentHandler ), |
175 | theSAX2LexicalHandler( 0 ), |
176 | theSStream(aSStream) |
177 | @@ -2122,9 +2123,9 @@ |
178 | ********************************************************************************/ |
179 | serializer::text_emitter::text_emitter( |
180 | serializer* the_serializer, |
181 | - transcoder& the_transcoder) |
182 | + std::ostream& the_stream) |
183 | : |
184 | - emitter(the_serializer, the_transcoder) |
185 | + emitter(the_serializer, the_stream) |
186 | { |
187 | } |
188 | |
189 | @@ -2296,9 +2297,9 @@ |
190 | ********************************************************************************/ |
191 | serializer::binary_emitter::binary_emitter( |
192 | serializer* the_serializer, |
193 | - transcoder& the_transcoder) |
194 | + std::ostream& the_stream) |
195 | : |
196 | - emitter(the_serializer, the_transcoder) |
197 | + emitter(the_serializer, the_stream) |
198 | { |
199 | } |
200 | |
201 | @@ -2692,10 +2693,7 @@ |
202 | ********************************************************************************/ |
203 | bool serializer::setup(std::ostream& os, bool aEmitAttributes) |
204 | { |
205 | - tr = create_transcoder(os); |
206 | - if (!tr) { |
207 | - return false; |
208 | - } |
209 | + tr = &os; |
210 | if (method == PARAMETER_VALUE_XML) |
211 | e = new xml_emitter(this, *tr, aEmitAttributes); |
212 | else if (method == PARAMETER_VALUE_HTML) |
213 | @@ -2730,22 +2728,21 @@ |
214 | return true; |
215 | } |
216 | |
217 | -transcoder* serializer::create_transcoder(std::ostream &os) |
218 | +void serializer::attach_transcoder(std::ostream &os) |
219 | { |
220 | if (encoding == PARAMETER_VALUE_UTF_8) |
221 | { |
222 | - return new transcoder(os, false); |
223 | + // do nothing |
224 | } |
225 | #ifndef ZORBA_NO_UNICODE |
226 | else if (encoding == PARAMETER_VALUE_UTF_16) |
227 | { |
228 | - return new transcoder(os, true); |
229 | + transcode::attach( os, "UTF-16LE" ); |
230 | } |
231 | #endif |
232 | else |
233 | { |
234 | ZORBA_ASSERT(0); |
235 | - return nullptr; |
236 | } |
237 | } |
238 | |
239 | @@ -2780,44 +2777,52 @@ |
240 | return; |
241 | } |
242 | |
243 | - // in case we use SAX event notifications |
244 | - if (aHandler) |
245 | - { |
246 | - // only allow XML-based methods for SAX notifications. For now at least, |
247 | - // the "JSONIQ" method is consider "XML-based", although you will certainly |
248 | - // get errors if you attempt to serialize JDM this way. |
249 | - if (method != PARAMETER_VALUE_XML && |
250 | - method != PARAMETER_VALUE_XHTML |
251 | + try { |
252 | + |
253 | + // in case we use SAX event notifications |
254 | + if (aHandler) |
255 | + { |
256 | + // Only allow XML-based methods for SAX notifications. For now at least, |
257 | + // the "JSONIQ" method is consider "XML-based", although you will |
258 | + // certainly get errors if you attempt to serialize JDM this way. |
259 | + if (method != PARAMETER_VALUE_XML && |
260 | + method != PARAMETER_VALUE_XHTML |
261 | #ifdef ZORBA_WITH_JSON |
262 | - && method != PARAMETER_VALUE_JSONIQ |
263 | + && method != PARAMETER_VALUE_JSONIQ |
264 | #endif |
265 | - ) { |
266 | - throw ZORBA_EXCEPTION( |
267 | - zerr::ZAPI0070_INVALID_SERIALIZATION_METHOD_FOR_SAX, |
268 | - ERROR_PARAMS( method ) |
269 | - ); |
270 | + ) { |
271 | + throw ZORBA_EXCEPTION( |
272 | + zerr::ZAPI0070_INVALID_SERIALIZATION_METHOD_FOR_SAX, |
273 | + ERROR_PARAMS( method ) |
274 | + ); |
275 | + } |
276 | + // it's OK now, build a SAX emmiter |
277 | + tr = &temp_sstream; |
278 | + e = new sax2_emitter(this, *tr, temp_sstream, aHandler); |
279 | } |
280 | - // it's OK now, build a SAX emmiter |
281 | - tr = new transcoder(temp_sstream, false); |
282 | - e = new sax2_emitter(this, *tr, temp_sstream, aHandler); |
283 | - } |
284 | - |
285 | - e->emit_declaration(); |
286 | - |
287 | - store::Item_t lItem; |
288 | - //+ aObject->open(); |
289 | - while (aObject->next(lItem)) |
290 | - { |
291 | - // PUL's cannot be serialized |
292 | - if (lItem->isPul()) |
293 | + |
294 | + e->emit_declaration(); |
295 | + |
296 | + store::Item_t lItem; |
297 | + //+ aObject->open(); |
298 | + while (aObject->next(lItem)) |
299 | { |
300 | - throw ZORBA_EXCEPTION(zerr::ZAPI0007_CANNOT_SERIALIZE_PUL); |
301 | + // PUL's cannot be serialized |
302 | + if (lItem->isPul()) |
303 | + { |
304 | + throw ZORBA_EXCEPTION(zerr::ZAPI0007_CANNOT_SERIALIZE_PUL); |
305 | + } |
306 | + |
307 | + e->emit_item(&*lItem); |
308 | } |
309 | - |
310 | - e->emit_item(&*lItem); |
311 | - } |
312 | -//+ aObject->close(); |
313 | - e->emit_end(); |
314 | + //+ aObject->close(); |
315 | + e->emit_end(); |
316 | + transcode::detach( aOStream ); |
317 | + } |
318 | + catch ( ... ) { |
319 | + transcode::detach( aOStream ); |
320 | + throw; |
321 | + } |
322 | } |
323 | |
324 | |
325 | @@ -2825,7 +2830,7 @@ |
326 | |
327 | ********************************************************************************/ |
328 | void serializer::serialize( |
329 | - store::Iterator_t object, |
330 | + store::Iterator_t object, |
331 | std::ostream& stream, |
332 | itemHandler aHandler, |
333 | void* aHandlerData) |
334 | @@ -2837,33 +2842,40 @@ |
335 | return; |
336 | } |
337 | |
338 | - e->emit_declaration(); |
339 | - |
340 | - store::Item_t lItem; |
341 | - //object->open(); |
342 | - while (object->next(lItem)) |
343 | - { |
344 | - Zorba_SerializerOptions_t* lSerParams = aHandler(aHandlerData); |
345 | - if (lSerParams) |
346 | - { |
347 | - SerializerImpl::setSerializationParameters(*this, *lSerParams); |
348 | - if (!setup(stream)) |
349 | - { |
350 | - return; |
351 | - } |
352 | - } |
353 | - |
354 | - // PUL's cannot be serialized |
355 | - if (lItem->isPul()) |
356 | - { |
357 | - throw ZORBA_EXCEPTION(zerr::ZAPI0007_CANNOT_SERIALIZE_PUL); |
358 | - } |
359 | - |
360 | - e->emit_item(&*lItem); |
361 | - } |
362 | - |
363 | - //object->close(); |
364 | - e->emit_end(); |
365 | + try { |
366 | + e->emit_declaration(); |
367 | + |
368 | + store::Item_t lItem; |
369 | + //object->open(); |
370 | + while (object->next(lItem)) |
371 | + { |
372 | + Zorba_SerializerOptions_t* lSerParams = aHandler(aHandlerData); |
373 | + if (lSerParams) |
374 | + { |
375 | + SerializerImpl::setSerializationParameters(*this, *lSerParams); |
376 | + if (!setup(stream)) |
377 | + { |
378 | + return; |
379 | + } |
380 | + } |
381 | + |
382 | + // PUL's cannot be serialized |
383 | + if (lItem->isPul()) |
384 | + { |
385 | + throw ZORBA_EXCEPTION(zerr::ZAPI0007_CANNOT_SERIALIZE_PUL); |
386 | + } |
387 | + |
388 | + e->emit_item(&*lItem); |
389 | + } |
390 | + |
391 | + //object->close(); |
392 | + e->emit_end(); |
393 | + transcode::detach( stream ); |
394 | + } |
395 | + catch ( ... ) { |
396 | + transcode::detach( stream ); |
397 | + throw; |
398 | + } |
399 | } |
400 | |
401 | } // namespace zorba |
402 | |
403 | === modified file 'src/api/serialization/serializer.h' |
404 | --- src/api/serialization/serializer.h 2012-07-24 08:48:48 +0000 |
405 | +++ src/api/serialization/serializer.h 2012-07-24 23:15:27 +0000 |
406 | @@ -23,7 +23,6 @@ |
407 | #include <zorba/options.h> |
408 | |
409 | #include "zorbatypes/schema_types.h" |
410 | -#include "zorbatypes/transcoder.h" |
411 | |
412 | #include "common/shared_types.h" |
413 | |
414 | @@ -124,7 +123,7 @@ |
415 | bool version_has_default_value; // Used during validation to set version to |
416 | // "4.0" when output method is "html" |
417 | rchandle<emitter> e; |
418 | - rchandle<transcoder> tr; |
419 | + std::ostream *tr; |
420 | |
421 | // Used to hold the QNames of the cdata section elements after they have been tokenized |
422 | std::vector<zstring> cdata_section_elements_tokens; |
423 | @@ -193,7 +192,7 @@ |
424 | |
425 | bool setup(std::ostream& os, bool aEmitAttributes = false); |
426 | |
427 | - transcoder* create_transcoder(std::ostream& os); |
428 | + void attach_transcoder(std::ostream& os); |
429 | |
430 | /////////////////////////////////////////////////////////// |
431 | // // |
432 | @@ -210,12 +209,12 @@ |
433 | * Creates a new emitter object. |
434 | * |
435 | * @param the_serializer The parent serializer object. |
436 | - * @param output_stream Target output stream. |
437 | + * @param the_stream Target output stream. |
438 | * @param aEmitAttributes If true, attributes are emitted. |
439 | */ |
440 | emitter( |
441 | serializer* the_serializer, |
442 | - transcoder& the_transcoder, |
443 | + std::ostream& the_stream, |
444 | bool aEmitAttributes = false); |
445 | |
446 | /** |
447 | @@ -319,7 +318,7 @@ |
448 | |
449 | protected: |
450 | serializer * ser; |
451 | - transcoder & tr; |
452 | + std::ostream & tr; |
453 | std::vector<store::NsBindings> theBindings; |
454 | |
455 | enum ItemState |
456 | @@ -349,7 +348,7 @@ |
457 | public: |
458 | xml_emitter( |
459 | serializer* the_serializer, |
460 | - transcoder& the_transcoder, |
461 | + std::ostream& the_stream, |
462 | bool aEmitAttributes = false |
463 | ); |
464 | |
465 | @@ -373,7 +372,7 @@ |
466 | class json_emitter : public emitter |
467 | { |
468 | public: |
469 | - json_emitter(serializer* the_serializer, transcoder& the_transcoder); |
470 | + json_emitter(serializer* the_serializer, std::ostream& the_stream); |
471 | |
472 | virtual ~json_emitter(); |
473 | |
474 | @@ -410,7 +409,6 @@ |
475 | store::Item_t theJSONiqXDMNodeName; |
476 | |
477 | rchandle<emitter> theXMLEmitter; |
478 | - rchandle<transcoder> theXMLTranscoder; |
479 | std::stringstream* theXMLStringStream; |
480 | bool theMultipleItems; |
481 | }; |
482 | @@ -425,7 +423,7 @@ |
483 | class jsoniq_emitter : public emitter |
484 | { |
485 | public: |
486 | - jsoniq_emitter(serializer* the_serializer, transcoder& the_transcoder); |
487 | + jsoniq_emitter(serializer* the_serializer, std::ostream& the_stream); |
488 | |
489 | virtual ~jsoniq_emitter(); |
490 | |
491 | @@ -459,7 +457,7 @@ |
492 | class xhtml_emitter : public xml_emitter |
493 | { |
494 | public: |
495 | - xhtml_emitter(serializer* the_serializer, transcoder& the_transcoder); |
496 | + xhtml_emitter(serializer* the_serializer, std::ostream& the_stream); |
497 | |
498 | protected: |
499 | virtual void emit_node(const store::Item* item, int depth); |
500 | @@ -475,7 +473,7 @@ |
501 | class html_emitter : public emitter |
502 | { |
503 | public: |
504 | - html_emitter(serializer* the_serializer, transcoder& the_transcoder); |
505 | + html_emitter(serializer* the_serializer, std::ostream& the_stream); |
506 | |
507 | virtual void emit_declaration(); |
508 | virtual void emit_end(); |
509 | @@ -495,7 +493,7 @@ |
510 | class text_emitter : public emitter |
511 | { |
512 | public: |
513 | - text_emitter(serializer* the_serializer, transcoder& the_transcoder); |
514 | + text_emitter(serializer* the_serializer, std::ostream& the_stream); |
515 | |
516 | virtual void emit_declaration(); |
517 | |
518 | @@ -530,7 +528,7 @@ |
519 | public: |
520 | sax2_emitter( |
521 | serializer* the_serializer, |
522 | - transcoder& the_transcoder, |
523 | + std::ostream& the_stream, |
524 | std::stringstream& aSStream, |
525 | SAX2_ContentHandler* aSAX2ContentHandler); |
526 | |
527 | @@ -574,7 +572,7 @@ |
528 | class binary_emitter : public emitter |
529 | { |
530 | public: |
531 | - binary_emitter(serializer* the_serializer, transcoder& the_transcoder); |
532 | + binary_emitter(serializer* the_serializer, std::ostream& the_stream); |
533 | |
534 | void emit_item(store::Item* item); |
535 | }; |
536 | |
537 | === modified file 'src/util/json_parser.cpp' |
538 | --- src/util/json_parser.cpp 2012-07-24 08:48:48 +0000 |
539 | +++ src/util/json_parser.cpp 2012-07-24 23:15:27 +0000 |
540 | @@ -235,9 +235,9 @@ |
541 | t->loc_ = cur_loc_; |
542 | parse_number( c, &t->value_ ); |
543 | return true; |
544 | - case 'f': |
545 | - case 'n': |
546 | - case 't': |
547 | + case 'f': // false |
548 | + case 'n': // null |
549 | + case 't': // true |
550 | t->type_ = parse_literal( c, &t->value_ ); |
551 | t->loc_ = cur_loc_; |
552 | return true; |
553 | |
554 | === modified file 'src/util/xml_util.h' |
555 | --- src/util/xml_util.h 2012-07-24 08:48:48 +0000 |
556 | +++ src/util/xml_util.h 2012-07-24 23:15:27 +0000 |
557 | @@ -19,6 +19,8 @@ |
558 | |
559 | #include <iostream> |
560 | |
561 | +#include <zorba/internal/ztd.h> |
562 | + |
563 | #include "unicode_util.h" |
564 | #include "utf8_util.h" |
565 | |
566 | @@ -120,10 +122,12 @@ |
567 | * @param v The XML version to use. |
568 | * @return Returns \c true only if the code-point is valid. |
569 | */ |
570 | -template<class CodePointType> |
571 | -inline bool is_valid( CodePointType c, version v = v1_0 ) { |
572 | +template<typename CodePointType> inline |
573 | +typename std::enable_if<ZORBA_TR1_NS::is_integral<CodePointType>::value, |
574 | + bool>::type |
575 | +is_valid( CodePointType c, version v = v1_0 ) { |
576 | // |
577 | - // See "Extensible Markup Language (XML) 1.0 (Fifth Edition)", and |
578 | + // See "Extensible Markup Language (XML) 1.0 (Fifth Edition)" and |
579 | // "Extensible Markup Language (XML) 1.1 (Second Edition)", section 2.2, |
580 | // "Characters", [2] Char. |
581 | // |
582 | |
583 | === modified file 'src/zorbatypes/CMakeLists.txt' |
584 | --- src/zorbatypes/CMakeLists.txt 2012-07-24 08:48:48 +0000 |
585 | +++ src/zorbatypes/CMakeLists.txt 2012-07-24 23:15:27 +0000 |
586 | @@ -19,7 +19,6 @@ |
587 | numconversions.cpp |
588 | binary.cpp |
589 | URI.cpp |
590 | - transcoder.cpp |
591 | collation_manager.cpp |
592 | chartype.cpp |
593 | rchandle.cpp) |
594 | |
595 | === removed file 'src/zorbatypes/transcoder.cpp' |
596 | --- src/zorbatypes/transcoder.cpp 2012-07-24 08:48:48 +0000 |
597 | +++ src/zorbatypes/transcoder.cpp 1970-01-01 00:00:00 +0000 |
598 | @@ -1,86 +0,0 @@ |
599 | -/* |
600 | - * Copyright 2006-2008 The FLWOR Foundation. |
601 | - * |
602 | - * Licensed under the Apache License, Version 2.0 (the "License"); |
603 | - * you may not use this file except in compliance with the License. |
604 | - * You may obtain a copy of the License at |
605 | - * |
606 | - * http://www.apache.org/licenses/LICENSE-2.0 |
607 | - * |
608 | - * Unless required by applicable law or agreed to in writing, software |
609 | - * distributed under the License is distributed on an "AS IS" BASIS, |
610 | - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
611 | - * See the License for the specific language governing permissions and |
612 | - * limitations under the License. |
613 | - */ |
614 | -#include "stdafx.h" |
615 | - |
616 | -#include <stdexcept> |
617 | - |
618 | -#include "diagnostics/assert.h" |
619 | -#include "util/unicode_util.h" |
620 | -#include "util/utf8_util.h" |
621 | - |
622 | -#include "transcoder.h" |
623 | - |
624 | -namespace zorba { |
625 | - |
626 | -/////////////////////////////////////////////////////////////////////////////// |
627 | - |
628 | -transcoder::transcoder( std::ostream& output_stream, bool in_utf16 ) : |
629 | - os( output_stream ), |
630 | - utf16( in_utf16 ) |
631 | -{ |
632 | -#ifndef ZORBA_NO_ICU |
633 | - utf8_buf_len_ = 0; |
634 | - utf8_char_len_ = 1; |
635 | -#endif /* ZORBA_NO_ICU */ |
636 | -} |
637 | - |
638 | -#ifndef ZORBA_NO_ICU |
639 | - |
640 | -void transcoder::write_utf16( char const *s, std::streamsize len ) { |
641 | - unicode::char_type *u_s; |
642 | - unicode::size_type u_len; |
643 | - if ( !unicode::to_string( s, len, &u_s, &u_len ) ) |
644 | - throw std::runtime_error( "unicode::to_string() failed" ); |
645 | - |
646 | - char const *const byte = reinterpret_cast<char const*>( u_s ); |
647 | - for ( int i = 0; i < u_len * (int)sizeof( unicode::char_type ); ++i ) |
648 | - os << byte[i]; |
649 | - |
650 | - delete[] u_s; |
651 | -} |
652 | - |
653 | -void transcoder::write_utf16_char( char ch ) { |
654 | - if ( utf8::is_start_byte( ch ) ) { |
655 | - if ( utf8_char_len_ > 1 ) |
656 | - throw std::runtime_error( "incomplete UTF-8 character" ); |
657 | - utf8_char_len_ = utf8::char_length( ch ); |
658 | - } else if ( utf8::is_continuation_byte( ch ) ) { |
659 | - if ( !utf8_buf_len_ ) |
660 | - throw std::runtime_error( "invalid UTF-8 byte" ); |
661 | - } |
662 | - |
663 | - utf8_buf_[ utf8_buf_len_++ ] = ch; |
664 | - |
665 | - if ( utf8_buf_len_ == utf8_char_len_ ) { |
666 | - unicode::char_type u_ch; |
667 | - if ( !unicode::to_char( utf8_buf_, &u_ch ) ) |
668 | - throw std::runtime_error( "unicode::to_char() failed" ); |
669 | - |
670 | - char const *const byte = reinterpret_cast<char const*>( &u_ch ); |
671 | - for ( int i = 0; i < (int)sizeof( unicode::char_type ); ++i ) |
672 | - os << byte[i]; |
673 | - |
674 | - utf8_buf_len_ = 0; |
675 | - utf8_char_len_ = 1; |
676 | - } |
677 | -} |
678 | - |
679 | -#endif /* ZORBA_NO_ICU */ |
680 | - |
681 | -/////////////////////////////////////////////////////////////////////////////// |
682 | - |
683 | -} // namespace zorba |
684 | -/* vim:set et sw=2 ts=2: */ |
685 | |
686 | === removed file 'src/zorbatypes/transcoder.h' |
687 | --- src/zorbatypes/transcoder.h 2012-07-24 08:48:48 +0000 |
688 | +++ src/zorbatypes/transcoder.h 1970-01-01 00:00:00 +0000 |
689 | @@ -1,113 +0,0 @@ |
690 | -/* |
691 | - * Copyright 2006-2008 The FLWOR Foundation. |
692 | - * |
693 | - * Licensed under the Apache License, Version 2.0 (the "License"); |
694 | - * you may not use this file except in compliance with the License. |
695 | - * You may obtain a copy of the License at |
696 | - * |
697 | - * http://www.apache.org/licenses/LICENSE-2.0 |
698 | - * |
699 | - * Unless required by applicable law or agreed to in writing, software |
700 | - * distributed under the License is distributed on an "AS IS" BASIS, |
701 | - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
702 | - * See the License for the specific language governing permissions and |
703 | - * limitations under the License. |
704 | - */ |
705 | -#pragma once |
706 | -#ifndef ZORBA_TRANSCODER_H |
707 | -#define ZORBA_TRANSCODER_H |
708 | - |
709 | -#include <cstring> |
710 | -#include <ostream> |
711 | - |
712 | -#include <zorba/config.h> |
713 | - |
714 | -#include "util/utf8_util.h" |
715 | -#include "zorbatypes/rchandle.h" |
716 | -#include "zorbatypes/zstring.h" |
717 | - |
718 | - |
719 | -namespace zorba { |
720 | - |
721 | -/////////////////////////////////////////////////////////// |
722 | -// // |
723 | -// class transcoder // |
724 | -// // |
725 | -/////////////////////////////////////////////////////////// |
726 | - |
727 | -class ZORBA_DLL_PUBLIC transcoder : public SimpleRCObject { |
728 | -protected: |
729 | - std::ostream &os; |
730 | - bool const utf16; |
731 | - |
732 | -#ifndef ZORBA_NO_ICU |
733 | - utf8::encoded_char_type utf8_buf_; |
734 | - int utf8_buf_len_; |
735 | - int utf8_char_len_; |
736 | -#endif /* ZORBA_NO_ICU */ |
737 | - |
738 | -public: |
739 | - transcoder(std::ostream& output_stream, bool in_utf16); |
740 | - |
741 | - transcoder& write( char const *s, std::streamsize n ) { |
742 | -#ifndef ZORBA_NO_ICU |
743 | - if ( utf16 ) |
744 | - write_utf16( s, n ); |
745 | - else |
746 | -#endif /* ZORBA_NO_ICU */ |
747 | - os.write( s, n ); |
748 | - return *this; |
749 | - } |
750 | - |
751 | - transcoder& operator<<( zstring const &s ) { |
752 | - return write( s.data(), (std::streamsize)s.size() ); |
753 | - } |
754 | - |
755 | - transcoder& operator<<( char const *s ) { |
756 | - return write( s, (std::streamsize)std::strlen( s ) ); |
757 | - } |
758 | - |
759 | - transcoder& operator<<( char ch ) { |
760 | -#ifndef ZORBA_NO_ICU |
761 | - if ( utf16 ) |
762 | - write_utf16_char(ch); |
763 | - else |
764 | -#endif /* ZORBA_NO_ICU */ |
765 | - os << ch; |
766 | - return *this; |
767 | - } |
768 | - |
769 | - // Support for manipulators (e.g. tr << flush) |
770 | - transcoder& operator<<( transcoder& (*pf)(transcoder&) ) { |
771 | - return pf( *this ); |
772 | - } |
773 | - |
774 | - /** |
775 | - * Output a byte to the stream without transcoding it. |
776 | - * |
777 | - * @param ch the byte to be output |
778 | - */ |
779 | - void verbatim( char ch ) { |
780 | - os << ch; |
781 | - } |
782 | - |
783 | - transcoder& flush() { |
784 | - os.flush(); |
785 | - return *this; |
786 | - } |
787 | - |
788 | -private: |
789 | -#ifndef ZORBA_NO_ICU |
790 | - void write_utf16(const char* str, std::streamsize n); |
791 | - void write_utf16_char(char ch); |
792 | -#endif /* ZORBA_NO_ICU */ |
793 | -}; |
794 | - |
795 | -} // namespace zorba |
796 | -#endif /* ZORBA_TRANSCODER_H */ |
797 | -/* |
798 | - * Local variables: |
799 | - * mode: c++ |
800 | - * End: |
801 | - */ |
802 | -/* vim:set et sw=2 ts=2: */ |
Validation queue starting for merge proposal. zorbatest. lambda. nu:8080/ remotequeue/ pjl-misc- 2012-07- 24T23-09- 00.444Z/ log.html
Log at: http://