Xalan-C++ API Documentation

The Xalan C++ XSLT Processor Version 1.10

XalanUTF8Writer.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(XALANUTF8WRITER_HEADER_GUARD_1357924680)
17 #define XALANUTF8WRITER_HEADER_GUARD_1357924680
18 
19 
21 
22 
23 
24 XALAN_CPP_NAMESPACE_BEGIN
25 
26 
27 
28 inline char
29 bits19to21(unsigned int theChar)
30 {
31  return char((theChar >> 18) & 0x7);
32 }
33 
34 
35 
36 inline char
37 bits13to18(unsigned int theChar)
38 {
39  return char((theChar >> 12) & 0x3F);
40 }
41 
42 
43 
44 inline char
45 bits13to16(unsigned int theChar)
46 {
47  return char((theChar >> 12) & 0xF);
48 }
49 
50 
51 
52 inline char
53 bits7to12(unsigned int theChar)
54 {
55  return char((theChar >> 6) & 0x3f);
56 }
57 
58 
59 
60 inline char
61 bits7to11(unsigned int theChar)
62 {
63  return char((theChar >> 6) & 0x1f);
64 }
65 
66 
67 
68 inline char
69 bits1to6(unsigned int theChar)
70 {
71  return char(theChar & 0x3f);
72 }
73 
74 
75 
76 inline char
77 leadingByteOf2(char theBits)
78 {
79  return char(0xC0 + theBits);
80 }
81 
82 
83 
84 inline char
85 leadingByteOf3(char theBits)
86 {
87  return char(0xE0 + theBits);
88 }
89 
90 
91 
92 inline char
93 leadingByteOf4(char theBits)
94 {
95  return char(0xF0 + theBits);
96 }
97 
98 
99 
100 inline char
101 trailingByte(char theBits)
102 {
103  return char(0x80 + theBits);
104 }
105 
106 
107 
109 {
110 public:
111 
112  typedef char value_type;
113 
114 
116  Writer& writer,
117  MemoryManager& theMemoryManager);
118 
119  virtual
121  {
122  }
123 
127  void
129  {
130  assert(m_newlineString != 0);
132 
133  write(
136  }
137 
138  size_type
140  const XalanDOMChar chars[],
141  size_type start,
143  bool& /* outsideCDATA */)
144  {
145  assert(chars != 0 && length != 0 && start < length);
146 
147  return write(chars, start, length);
148  }
149 
153  void writeNameChar(const XalanDOMChar* data,
154  size_type theLength)
155  {
156  write(data, theLength);
157  }
158 
162  void writePIChars(const XalanDOMChar* data,
163  size_type theLength)
164  {
165  write(data, theLength);
166  }
167 
171  void writeCommentChars(const XalanDOMChar* data,
172  size_type theLength)
173  {
174  write(data, theLength);
175  }
176 
177  void
179  const XalanDOMChar* theChars,
180  XalanDOMString::size_type theLength)
181  {
182  for(size_type i = 0; i < theLength; ++i)
183  {
184  write(value_type(theChars[i]));
185  }
186  }
187 
188  void
190  const value_type* theChars,
191  XalanDOMString::size_type theLength)
192  {
193  #if defined(NDEBUG)
194  if (theLength > sizeof(m_buffer))
195  {
196  flushBuffer();
197 
198  m_writer.write(theChars, 0, theLength);
199  }
200  else
201  {
202  if (m_bufferRemaining < theLength)
203  {
204  flushBuffer();
205  }
206 
207  for(size_type i = 0; i < theLength; ++i)
208  {
209  *m_bufferPosition = theChars[i];
210 
211  ++m_bufferPosition;
212  }
213 
214  m_bufferRemaining -= theLength;
215  }
216  #else
217  for(XalanDOMString::size_type i = 0; i < theLength; ++i)
218  {
219  write(theChars[i]);
220  }
221  #endif
222  }
223 
224  void
225  write(const XalanDOMChar* theChars)
226  {
227  write(theChars, XalanDOMString::length(theChars));
228  }
229 
230  void
231  write(const XalanDOMString& theChars)
232  {
233  write(theChars.c_str(), theChars.length());
234  }
235 
236  void
237  write(value_type theChar)
238  {
239  assert(theChar < 128);
240 
241  if (m_bufferRemaining == 0)
242  {
243  flushBuffer();
244  }
245 
246  *m_bufferPosition = theChar;
247 
248  ++m_bufferPosition;
249  --m_bufferRemaining;
250  }
251 
252  void
254  const XalanDOMChar* theChars,
255  XalanDOMString::size_type theLength)
256  {
257  for(size_type i = 0; i < theLength; ++i)
258  {
259  write((unsigned int)theChars[i]);
260  }
261  }
262 
263  size_type
265  const XalanDOMChar chars[],
268  {
269  XalanDOMChar ch = chars[start];
270 
272  {
273  write((unsigned int)ch);
274  }
275  else
276  {
277  if (start + 1 >= length)
278  {
280  ch,
281  0,
282  getMemoryManager());
283  }
284  else
285  {
286  write(
288  ch,
289  chars[++start],
290  getMemoryManager()));
291  }
292  }
293 
294  return start;
295  }
296 
297  void
299  const XalanDOMChar* theChars,
300  XalanDOMString::size_type theLength)
301  {
302  XalanDOMChar ch = 0;
303 
304  for(size_type i = 0; i < theLength; ++i)
305  {
306  ch = theChars[i];
307 
309  {
310  if (i + 1 >= theLength)
311  {
313  }
314  else
315  {
317 
318  ++i;
319  }
320  }
321  else
322  {
323  write((unsigned int)ch);
324  }
325  }
326 
327  }
328 
329  void
330  write(const value_type* theChars)
331  {
332  write(theChars, XalanDOMString::length(theChars));
333  }
334 
335  void
337  {
338  m_writer.flush();
339  }
340 
341  void
343  {
344  m_writer.write(m_buffer, 0, m_bufferPosition - m_buffer);
345 
346  m_bufferPosition = m_buffer;
347  m_bufferRemaining = kBufferSize;
348  }
349 
350 private:
351 
352  void
353  write(unsigned int theChar)
354  {
355  if (theChar <= 0x7F)
356  {
357  write(char(theChar));
358  }
359  else if (theChar <= 0x7FF)
360  {
361  if (m_bufferRemaining < 2)
362  {
363  flushBuffer();
364  }
365 
366  *m_bufferPosition = leadingByteOf2(bits7to11(theChar));
367  ++m_bufferPosition;
368  *m_bufferPosition = trailingByte(bits1to6(theChar));
369  ++m_bufferPosition;
370 
371  m_bufferRemaining -= 2;
372  }
373  else if (theChar <= 0xFFFF)
374  {
375  // We should never get a high or low surrogate here...
376  assert(theChar < 0xD800 || theChar > 0xDBFF);
377  assert(theChar < 0xDC00 || theChar > 0xDFFF);
378 
379  if (m_bufferRemaining < 3)
380  {
381  flushBuffer();
382  }
383 
384  *m_bufferPosition = leadingByteOf3(bits13to16(theChar));
385  ++m_bufferPosition;
386  *m_bufferPosition = trailingByte(bits7to12(theChar));
387  ++m_bufferPosition;
388  *m_bufferPosition = trailingByte(bits1to6(theChar));
389  ++m_bufferPosition;
390 
391  m_bufferRemaining -= 3;
392  }
393  else if (theChar <= 0x10FFFF)
394  {
395  if (m_bufferRemaining < 4)
396  {
397  flushBuffer();
398  }
399 
400  *m_bufferPosition = leadingByteOf4(bits19to21(theChar));
401  ++m_bufferPosition;
402  *m_bufferPosition = trailingByte(bits13to18(theChar));
403  ++m_bufferPosition;
404  *m_bufferPosition = trailingByte(bits7to12(theChar));
405  ++m_bufferPosition;
406  *m_bufferPosition = trailingByte(bits1to6(theChar));
407  ++m_bufferPosition;
408 
409  m_bufferRemaining -= 4;
410  }
411  else
412  {
414  }
415  }
416 
417  enum
418  {
419  kBufferSize = 512 // The size of the buffer
420  };
421 
422 
423  // Data members...
424  value_type m_buffer[kBufferSize];
425 
426  value_type* m_bufferPosition;
427 
428  XalanDOMString::size_type m_bufferRemaining;
429 };
430 
431 
432 
433 XALAN_CPP_NAMESPACE_END
434 
435 
436 
437 #endif // XALANUTF8WRITER_HEADER_GUARD_1357924680
void write(const value_type *theChars, XalanDOMString::size_type theLength)
Definition: XalanUTF8Writer.hpp:189
size_type length() const
Definition: XalanDOMString.hpp:209
Definition: XalanUTF8Writer.hpp:108
void writeCommentChars(const XalanDOMChar *data, size_type theLength)
Writes name chars , if not presentable, throws.
Definition: XalanUTF8Writer.hpp:171
XalanDOMString::size_type m_newlineStringLength
The length of the the string of characters that represents the newline.
Definition: XalanFormatterWriter.hpp:316
static unsigned int decodeUTF16SurrogatePair(XalanDOMChar theHighSurrogate, XalanDOMChar theLowSurrogate, MemoryManager &theManager)
Definition: XalanFormatterWriter.hpp:231
void safeWriteContent(const XalanDOMChar *theChars, XalanDOMString::size_type theLength)
Definition: XalanUTF8Writer.hpp:178
virtual void write(const char *s, size_t theOffset=0, size_t theLength=npos)=0
Writes a string.
void write(const XalanDOMString &theChars)
Definition: XalanUTF8Writer.hpp:231
Definition: Writer.hpp:42
void writePIChars(const XalanDOMChar *data, size_type theLength)
Writes name chars , if not presentable, throws.
Definition: XalanUTF8Writer.hpp:162
MemoryManagerType & getMemoryManager()
Definition: XalanFormatterWriter.hpp:183
char bits7to11(unsigned int theChar)
Definition: XalanUTF8Writer.hpp:61
char bits13to18(unsigned int theChar)
Definition: XalanUTF8Writer.hpp:37
char leadingByteOf3(char theBits)
Definition: XalanUTF8Writer.hpp:85
static void throwInvalidCharacterException(unsigned int ch, MemoryManager &theManager)
Definition: XalanFormatterWriter.hpp:247
static bool isUTF16HighSurrogate(XalanDOMChar theChar)
Definition: XalanFormatterWriter.hpp:219
char leadingByteOf4(char theBits)
Definition: XalanUTF8Writer.hpp:93
void write(const XalanDOMChar *theChars)
Definition: XalanUTF8Writer.hpp:225
XALAN_CPP_NAMESPACE_BEGIN char bits19to21(unsigned int theChar)
Definition: XalanUTF8Writer.hpp:29
size_type writeCDATAChar(const XalanDOMChar chars[], size_type start, size_type length, bool &)
Definition: XalanUTF8Writer.hpp:139
void write(const XalanDOMChar *theChars, XalanDOMString::size_type theLength)
Definition: XalanUTF8Writer.hpp:253
XalanDOMString::size_type size_type
Definition: XalanFormatterWriter.hpp:153
void outputNewline()
Output a line break.
Definition: XalanUTF8Writer.hpp:128
Writer & m_writer
The writer.
Definition: XalanFormatterWriter.hpp:298
void write(value_type theChar)
Definition: XalanUTF8Writer.hpp:237
virtual void flush()=0
Flush the stream.
size_type write(const XalanDOMChar chars[], XalanDOMString::size_type start, XalanDOMString::size_type length)
Definition: XalanUTF8Writer.hpp:264
char bits13to16(unsigned int theChar)
Definition: XalanUTF8Writer.hpp:45
const XalanDOMChar * c_str() const
Definition: XalanDOMString.hpp:314
char bits1to6(unsigned int theChar)
Definition: XalanUTF8Writer.hpp:69
char bits7to12(unsigned int theChar)
Definition: XalanUTF8Writer.hpp:53
XalanUTF8Writer(Writer &writer, MemoryManager &theMemoryManager)
virtual ~XalanUTF8Writer()
Definition: XalanUTF8Writer.hpp:120
char trailingByte(char theBits)
Definition: XalanUTF8Writer.hpp:101
char leadingByteOf2(char theBits)
Definition: XalanUTF8Writer.hpp:77
void flushWriter()
Definition: XalanUTF8Writer.hpp:336
static void throwInvalidUTF16SurrogateException(XalanDOMChar ch, XalanDOMChar next, MemoryManagerType &theManager)
Definition: XalanFormatterWriter.hpp:265
Definition: XalanDOMString.hpp:42
void flushBuffer()
Definition: XalanUTF8Writer.hpp:342
XalanDOMString::size_type length(const XalanDOMString &theString)
Get the length of a XalanDOMString.
Definition: DOMStringHelper.hpp:277
Definition: XalanFormatterWriter.hpp:41
unsigned int size_type
Definition: XalanDOMString.hpp:53
void write(const value_type *theChars)
Definition: XalanUTF8Writer.hpp:330
const XalanDOMChar * m_newlineString
The string of characters that represents the newline.
Definition: XalanFormatterWriter.hpp:311
char value_type
Definition: XalanUTF8Writer.hpp:112
void writeSafe(const XalanDOMChar *theChars, XalanDOMString::size_type theLength)
Definition: XalanUTF8Writer.hpp:298
void writeNameChar(const XalanDOMChar *data, size_type theLength)
Writes name chars , if not presentable, throws.
Definition: XalanUTF8Writer.hpp:153

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