Xalan-C++ API Documentation

The Xalan C++ XSLT Processor Version 1.10

XalanOtherEncodingWriter.hpp
Go to the documentation of this file.
1 /*
2  * Copyright 1999-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 #if !defined(XALANUNICODESUBSETWRITER_HEADER_GUARD_1357924680)
17 #define XALANUNICODESUBSETWRITER_HEADER_GUARD_1357924680
18 
19 
21 
22 
23 
24 XALAN_CPP_NAMESPACE_BEGIN
25 
26 
27 
28 
29 template <class Predicate,
30  class ConstantsType>
32 {
33 public:
34 
36 
38  {
39  public:
40 
42  m_writer(writer)
43  {
44  }
45 
46  void
47  operator()(unsigned int value) const
48  {
49  m_writer.writeNumericCharacterReference(value);
50  }
51 
52  private:
53 
54  ThisType& m_writer;
55  };
56 
58  {
59  public:
60 
62  m_writer(writer)
63  {
64  }
65 
66  void
67  operator()(unsigned int value) const
68  {
69  m_writer.throwInvalidCharacterException(value, m_writer.getMemoryManager());
70  }
71 
72  private:
73 
74  ThisType& m_writer;
75  };
76 
77  friend class WriteCharRef;
79 
80  typedef XalanDOMChar value_type;
81 
83  Writer& writer,
84  MemoryManager& theMemoryManager) :
86  writer,
87  theMemoryManager),
88  m_buffer(),
89  m_bufferPosition(m_buffer),
90  m_bufferRemaining(kBufferSize),
91  m_predicate(writer.getStream()),
92  m_constants(),
93  m_charRefFunctor(*this),
94  m_exceptionFunctor(*this)
95  {
96  }
97 
98  virtual
100  {
101  }
102 
106  void
108  {
109  assert(m_newlineString != 0);
111 
112  write(
115  }
116 
121  size_type
123  const XalanDOMChar chars[],
124  size_type start,
126  bool& outsideCDATA)
127  {
128  assert(chars != 0 && length > 0 && start < length);
129 
130  const XalanDOMChar theChar = chars[start];
131 
132  unsigned int value = theChar;
133 
134  size_type result = start;
135 
136  if (isUTF16HighSurrogate(theChar) == true)
137  {
138  if (start + 1 >= length)
139  {
141  theChar,
142  0,
143  getMemoryManager());
144  }
145  else
146  {
147  value = decodeUTF16SurrogatePair(theChar, chars[start+1], getMemoryManager());
148 
149  ++result;
150  }
151  }
152 
153  if(m_predicate(value))
154  {
155  if (outsideCDATA == false)
156  {
157  // We have a representable char in the normal state,
158  // so just print it.
159  write(value);
160  }
161  else
162  {
163  // The previous character was a not representable.
164  // Open the CDATA section again, print the character,
165  // then change the flag.
166  write(
167  m_constants.s_cdataOpenString,
168  m_constants.s_cdataOpenStringLength);
169 
170  write(value);
171 
172  outsideCDATA = false;
173  }
174  }
175  else
176  {
177  if(outsideCDATA == false)
178  {
179  // we have a non-representable char in the normal state -
180  // close the CDATA section and print the value
181  write(
182  m_constants.s_cdataCloseString,
183  m_constants.s_cdataCloseStringLength);
184 
185  writeNumericCharacterReference(value);
186 
187  outsideCDATA = true;
188  }
189  else
190  {
191  writeNumericCharacterReference(value);
192  }
193  }
194 
195  return result;
196  }
197 
202  void
204  const XalanDOMChar* data,
205  size_type theLength)
206  {
207  for( size_type i = 0; i < theLength; ++i)
208  {
209  i = write(data, i , theLength, m_exceptionFunctor);
210  }
211  }
212 
217  void
219  const XalanDOMChar* data,
220  size_type theLength)
221  {
222  for( size_type i = 0; i < theLength; )
223  {
224  i = write(data, i , theLength, m_exceptionFunctor);
225  }
226  }
227 
233  void
235  const XalanDOMChar* data,
236  size_type theLength)
237  {
238  for( size_type i = 0; i < theLength; )
239  {
240  i = write(data, i , theLength, m_exceptionFunctor);
241  }
242  }
243 
244  void
246  const XalanDOMChar* theChars,
247  size_type theLength)
248  {
249  for(size_type i = 0; i < theLength; ++i)
250  {
251  write(theChars[i]);
252  }
253  }
254 
255  void
256  write(const XalanDOMString& theChars)
257  {
258  write(theChars.c_str(), theChars.length());
259  }
260 
265  void
266  write(XalanDOMChar theChar)
267  {
268  assert(
269  isUTF16HighSurrogate(theChar) == false &&
270  isUTF16LowSurrogate(theChar) == false);
271 
272  if (m_bufferRemaining == 0)
273  {
274  flushBuffer();
275  }
276 
277  if(m_predicate(theChar))
278  {
279  *m_bufferPosition = theChar;
280 
281  ++m_bufferPosition;
282  --m_bufferRemaining;
283  }
284  else
285  {
286  writeNumericCharacterReference(theChar);
287  }
288  }
289 
290  size_type
292  const XalanDOMChar chars[],
293  size_type start,
295  {
296 
297  return write(chars, start, length, m_charRefFunctor);
298  }
299 
300  void
302  const XalanDOMChar* theChars,
303  size_type theLength)
304  {
305  for(size_type i = 0; i < theLength; ++i)
306  {
307  const XalanDOMChar ch = theChars[i];
308 
309  if (isUTF16HighSurrogate(ch) == true)
310  {
311  if (i + 1 >= theLength)
312  {
314  }
315  else
316  {
317  unsigned int value = decodeUTF16SurrogatePair(ch, theChars[i+1], getMemoryManager());
318 
319  if(this->m_isPresentable(value))
320  {
321  write(value);
322  }
323  else
324  {
325  this->writeNumberedEntityReference(value);
326  }
327 
328  ++i;
329  }
330  }
331  else
332  {
333  write((unsigned int)ch);
334  }
335  }
336  }
337 
338  void
339  write(const XalanDOMChar* theChars)
340  {
341  write(theChars, XalanDOMString::length(theChars));
342  }
343 
344  void
346  {
347  m_writer.flush();
348  }
349 
350  void
352  {
353  m_writer.write(m_buffer, 0, m_bufferPosition - m_buffer);
354 
355  m_bufferPosition = m_buffer;
356  m_bufferRemaining = kBufferSize;
357  }
358 
359 private:
360 
375  template <class TranscodingFailureFunctor>
376  size_type
377  write(
378  const XalanDOMChar chars[],
379  size_type start,
381  TranscodingFailureFunctor& failureHandler)
382  {
383  assert(chars != 0 && length > 0);
384  assert(start <= length);
385 
386  size_type result = start;
387 
388  const XalanDOMChar ch = chars[start];
389 
390  unsigned int value = ch;
391 
393  {
394  if (start + 1 >= length)
395  {
397  ch,
398  0,
399  getMemoryManager());
400  }
401  else
402  {
403  value = decodeUTF16SurrogatePair(ch, chars[start+1], getMemoryManager());
404 
405  ++result;
406  }
407  }
408 
409  if(m_predicate(value))
410  {
411  write(value);
412  }
413  else
414  {
415  failureHandler(value);
416  }
417 
418  return result;
419  }
420 
427  void
428  write(unsigned int theChar)
429  {
430  // encode back UTF-32 into UTF-16
431 
432  if( theChar > 0xFFFF )
433  {
434  if (m_bufferRemaining < 2)
435  {
436  flushBuffer();
437  }
438 
439  *m_bufferPosition = (XalanDOMChar((theChar >> 10) + 0xD7C0));
440 
441  ++m_bufferPosition;
442 
443  *m_bufferPosition = (XalanDOMChar((theChar & 0x03FF) + 0xDC00));
444 
445  ++m_bufferPosition;
446 
447  m_bufferRemaining = m_bufferRemaining - size_type(2);
448  }
449  else
450  {
451  if (m_bufferRemaining == 0)
452  {
453  flushBuffer();
454  }
455 
456  *m_bufferPosition = XalanDOMChar(theChar);
457 
458  ++m_bufferPosition;
459  --m_bufferRemaining;
460  }
461  }
462 
463  void
464  writeNumericCharacterReference(unsigned int theNumber)
465  {
467  }
468 
469  enum
470  {
471  kBufferSize = 512u // The size of the buffer
472  };
473 
474 
475  // Data members...
476  XalanDOMChar m_buffer[kBufferSize];
477 
478  XalanDOMChar* m_bufferPosition;
479 
480  size_type m_bufferRemaining;
481 
482  const Predicate m_predicate;
483 
484  const ConstantsType m_constants;
485 
486  const WriteCharRef m_charRefFunctor;
487 
488  const ThrowTranscodingException m_exceptionFunctor;
489 };
490 
491 
492 
493 XALAN_CPP_NAMESPACE_END
494 
495 
496 
497 #endif // XALANUNICODESUBSETWRITER_HEADER_GUARD_1357924680

Interpreting class diagrams

Doxygen and GraphViz are used to generate this API documentation from the Xalan-C header files.

dot

Xalan-C++ XSLT Processor Version 1.10
Copyright © 1999-2004 The Apache Software Foundation. All Rights Reserved.

Apache Logo