Xalan-C++ API Reference  1.12.0
XalanUTF16Writer.hpp
Go to the documentation of this file.
1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one
3  * or more contributor license agreements. See the NOTICE file
4  * distributed with this work for additional information
5  * regarding copyright ownership. The ASF licenses this file
6  * to you under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */
18 #if !defined(XALANUTF16WRITER_HEADER_GUARD_1357924680)
19 #define XALANUTF16WRITER_HEADER_GUARD_1357924680
20 
21 
23 
24 
25 namespace XALAN_CPP_NAMESPACE {
26 
27 
29 {
30 public:
31 
32  typedef XalanDOMChar value_type;
33 
34 
36  Writer& writer,
37  MemoryManager& theMemoryManager);
38 
39  virtual
41  {
42  }
43 
44  /**
45  * Output a line break.
46  */
47  void
49  {
50  assert(m_newlineString != 0);
51  assert(length(m_newlineString) == m_newlineStringLength);
52 
53  write(
54  m_newlineString,
55  m_newlineStringLength);
56  }
57 
58 
59  size_type
61  const XalanDOMChar chars[],
62  size_type start,
63  size_type /*length*/,
64  bool& /* outsideCDATA */)
65  {
66  assert( chars != 0 );
67 
68  write(chars[start]);
69 
70  return start;
71  }
72 
73  /**
74  * Writes name chars, if not representable, throws
75  */
76  void
78  const XalanDOMChar* data,
79  size_type theLength)
80  {
81  write(data, theLength);
82  }
83 
84  /**
85  * Writes name chars, if not representable, throws
86  */
87  void
89  const XalanDOMChar* data,
90  size_type theLength)
91  {
92  write(data, theLength);
93  }
94 
95  /**
96  * Writes name chars, if not representable, throws
97  */
98  void
100  const XalanDOMChar* data,
101  size_type theLength)
102  {
103  write(data, theLength);
104  }
105 
106  void
108  const XalanDOMChar* theChars,
109  size_type theLength)
110  {
111  write(theChars, theLength);
112  }
113 
114  void
116  const value_type* theChars,
117  size_type theLength)
118  {
119  if (theLength > kBufferSize)
120  {
121  flushBuffer();
122 
123  m_writer.write(theChars, 0, theLength);
124  }
125  else
126  {
127  if (m_bufferRemaining < theLength)
128  {
129  flushBuffer();
130  }
131 
132  for(size_type i = 0; i < theLength; ++i)
133  {
134  *m_bufferPosition = theChars[i];
135 
136  ++m_bufferPosition;
137  }
138 
139  m_bufferRemaining -= theLength;
140  }
141 
142  }
143 
144  void
145  write(const XalanDOMString& theChars)
146  {
147  write(theChars.c_str(), theChars.length());
148  }
149 
150  void
151  write(value_type theChar)
152  {
153 
154  if (m_bufferRemaining == 0)
155  {
156  flushBuffer();
157  }
158 
159  *m_bufferPosition = theChar;
160 
161  ++m_bufferPosition;
162  --m_bufferRemaining;
163  }
164 
165 
166  size_type
168  const value_type chars[],
169  size_type start,
170  size_type /*length*/)
171  {
172  write(chars[start]);
173 
174  return start;
175  }
176 
177  void
179  const XalanDOMChar* theChars,
180  size_type theLength)
181  {
182  write(theChars, theLength);
183  }
184 
185  void
186  write(const value_type* theChars)
187  {
188  write(theChars, XalanDOMString::length(theChars));
189  }
190 
191  void
193  {
194  m_writer.write(
195  m_buffer,
196  0,
197  m_bufferPosition - m_buffer);
198 
199 
200  m_bufferPosition = m_buffer;
201  m_bufferRemaining = kBufferSize;
202  }
203 
204 
205 private:
206 
207  enum
208  {
209  kBufferSize = 512 // The size of the buffer
210  };
211 
212 
213  // Data members...
214  value_type m_buffer[kBufferSize];
215 
216  value_type* m_bufferPosition;
217 
218  size_type m_bufferRemaining;
219 };
220 
221 
222 
223 }
224 
225 
226 
227 #endif // XALANUTF16WRITER_HEADER_GUARD_1357924680
xalanc::XalanUTF16Writer::writeNameChar
void writeNameChar(const XalanDOMChar *data, size_type theLength)
Writes name chars, if not representable, throws.
Definition: XalanUTF16Writer.hpp:77
xalanc::XalanUTF16Writer::writePIChars
void writePIChars(const XalanDOMChar *data, size_type theLength)
Writes name chars, if not representable, throws.
Definition: XalanUTF16Writer.hpp:88
xalanc::XalanUTF16Writer::writeCommentChars
void writeCommentChars(const XalanDOMChar *data, size_type theLength)
Writes name chars, if not representable, throws.
Definition: XalanUTF16Writer.hpp:99
XALAN_CPP_NAMESPACE
#define XALAN_CPP_NAMESPACE
Xalan-C++ namespace, including major and minor version.
Definition: XalanVersion.hpp:76
xalanc::XalanUTF16Writer::writeSafe
void writeSafe(const XalanDOMChar *theChars, size_type theLength)
Definition: XalanUTF16Writer.hpp:178
xalanc::size_type
size_t size_type
Definition: XalanMap.hpp:46
xalanc::XalanUTF16Writer::write
size_type write(const value_type chars[], size_type start, size_type)
Definition: XalanUTF16Writer.hpp:167
xalanc::XalanUTF16Writer::outputNewline
void outputNewline()
Output a line break.
Definition: XalanUTF16Writer.hpp:48
xalanc::XalanDOMString::length
size_type length() const
Definition: XalanDOMString.hpp:209
xalanc::XalanUTF16Writer::~XalanUTF16Writer
virtual ~XalanUTF16Writer()
Definition: XalanUTF16Writer.hpp:40
xalanc::XalanFormatterWriter::size_type
FormatterListener::size_type size_type
Definition: XalanFormatterWriter.hpp:48
xalanc::length
XalanDOMString::size_type length(const XalanDOMString &theString)
Get the length of a XalanDOMString.
Definition: DOMStringHelper.hpp:235
XalanFormatterWriter.hpp
xalanc::XalanUTF16Writer::write
void write(const XalanDOMString &theChars)
Definition: XalanUTF16Writer.hpp:145
xalanc::XalanUTF16Writer::write
void write(value_type theChar)
Definition: XalanUTF16Writer.hpp:151
xalanc::XalanFormatterWriter
Definition: XalanFormatterWriter.hpp:44
xalanc::XalanUTF16Writer::write
void write(const value_type *theChars, size_type theLength)
Definition: XalanUTF16Writer.hpp:115
xalanc::XalanUTF16Writer::safeWriteContent
void safeWriteContent(const XalanDOMChar *theChars, size_type theLength)
Definition: XalanUTF16Writer.hpp:107
xalanc::XalanDOMString::c_str
const XalanDOMChar * c_str() const
Definition: XalanDOMString.hpp:344
xalanc::XalanUTF16Writer::value_type
XalanDOMChar value_type
Definition: XalanUTF16Writer.hpp:32
xalanc::XalanUTF16Writer::writeCDATAChar
size_type writeCDATAChar(const XalanDOMChar chars[], size_type start, size_type, bool &)
Definition: XalanUTF16Writer.hpp:60
xalanc::XalanUTF16Writer::flushBuffer
void flushBuffer()
Definition: XalanUTF16Writer.hpp:192
xalanc::XalanDOMString
Definition: XalanDOMString.hpp:45
xalanc::XalanUTF16Writer
Definition: XalanUTF16Writer.hpp:28
xalanc::XalanUTF16Writer::write
void write(const value_type *theChars)
Definition: XalanUTF16Writer.hpp:186
xalanc::Writer
Definition: Writer.hpp:44