Qt 4.8
Public Functions | Public Variables | Properties | List of all members
QXmlStreamWriterPrivate Class Reference
Inheritance diagram for QXmlStreamWriterPrivate:
QXmlStreamPrivateTagStack

Public Functions

void checkIfASCIICompatibleCodec ()
 
NamespaceDeclarationfindNamespace (const QString &namespaceUri, bool writeDeclaration=false, bool noDefault=false)
 
bool finishStartElement (bool contents=true)
 
void indent (int level)
 
 QXmlStreamWriterPrivate (QXmlStreamWriter *q)
 
void write (const QStringRef &)
 
void write (const QString &)
 
void write (const char *s, int len)
 
template<int N>
void write (const char(&s)[N])
 
void writeEscaped (const QString &, bool escapeWhitespace=false)
 
void writeNamespaceDeclaration (const NamespaceDeclaration &namespaceDeclaration)
 
void writeStartElement (const QString &namespaceUri, const QString &name)
 
 ~QXmlStreamWriterPrivate ()
 
- Public Functions inherited from QXmlStreamPrivateTagStack
QStringRef addToStringStorage (const QStringRef &s)
 
QStringRef addToStringStorage (const QString &s)
 
 QXmlStreamPrivateTagStack ()
 
TagtagStack_pop ()
 
TagtagStack_push ()
 

Public Variables

uint autoFormatting:1
 
QByteArray autoFormattingIndent
 
QTextCodeccodec
 
uint deleteDevice:1
 
QIODevicedevice
 
NamespaceDeclaration emptyNamespace
 
QTextEncoderencoder
 
uint hasError:1
 
uint inEmptyElement:1
 
uint inStartElement:1
 
uint isCodecASCIICompatible:1
 
int lastNamespaceDeclaration
 
uint lastWasStartElement:1
 
int namespacePrefixCount
 
QStringstringDevice
 
uint wroteSomething:1
 
- Public Variables inherited from QXmlStreamPrivateTagStack
QXmlStreamSimpleStack< NamespaceDeclarationnamespaceDeclarations
 
bool tagsDone
 
QXmlStreamSimpleStack< TagtagStack
 
QString tagStackStringStorage
 
int tagStackStringStorageSize
 

Properties

QXmlStreamWriterq_ptr
 

Detailed Description

Definition at line 3120 of file qxmlstream.cpp.

Constructors and Destructors

◆ QXmlStreamWriterPrivate()

QXmlStreamWriterPrivate::QXmlStreamWriterPrivate ( QXmlStreamWriter q)

Definition at line 3169 of file qxmlstream.cpp.

3170  :autoFormattingIndent(4, ' ')
3171 {
3172  q_ptr = q;
3173  device = 0;
3174  stringDevice = 0;
3175  deleteDevice = false;
3176 #ifndef QT_NO_TEXTCODEC
3177  codec = QTextCodec::codecForMib(106); // utf8
3178  encoder = codec->makeEncoder(QTextCodec::IgnoreHeader); // no byte order mark for utf8
3179 #endif
3181  inStartElement = inEmptyElement = false;
3182  wroteSomething = false;
3183  hasError = false;
3184  lastWasStartElement = false;
3186  autoFormatting = false;
3188 }
QXmlStreamWriter * q_ptr
QTextEncoder * encoder
static QTextCodec * codecForMib(int mib)
Returns the QTextCodec which matches the MIBenum mib.
QByteArray autoFormattingIndent
QTextEncoder * makeEncoder() const
Creates a QTextEncoder which stores enough state to encode chunks of Unicode data as char * data...

◆ ~QXmlStreamWriterPrivate()

QXmlStreamWriterPrivate::~QXmlStreamWriterPrivate ( )
inline

Definition at line 3125 of file qxmlstream.cpp.

3125  {
3126  if (deleteDevice)
3127  delete device;
3128 #ifndef QT_NO_TEXTCODEC
3129  delete encoder;
3130 #endif
3131  }
QTextEncoder * encoder

Functions

◆ checkIfASCIICompatibleCodec()

void QXmlStreamWriterPrivate::checkIfASCIICompatibleCodec ( )

Definition at line 3190 of file qxmlstream.cpp.

Referenced by QXmlStreamWriterPrivate().

3191 {
3192 #ifndef QT_NO_TEXTCODEC
3193  Q_ASSERT(encoder);
3194  // assumes ASCII-compatibility for all 8-bit encodings
3195  const QByteArray bytes = encoder->fromUnicode(QLatin1String(" "));
3196  isCodecASCIICompatible = (bytes.count() == 1);
3197 #else
3198  isCodecASCIICompatible = true;
3199 #endif
3200 }
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
QTextEncoder * encoder
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
int count(char c) const
Returns the number of occurrences of character ch in the byte array.
QByteArray fromUnicode(const QString &str)
Converts the Unicode string str into an encoded QByteArray.

◆ findNamespace()

QXmlStreamPrivateTagStack::NamespaceDeclaration & QXmlStreamWriterPrivate::findNamespace ( const QString namespaceUri,
bool  writeDeclaration = false,
bool  noDefault = false 
)

Definition at line 3320 of file qxmlstream.cpp.

3321 {
3322  for (int j = namespaceDeclarations.size() - 1; j >= 0; --j) {
3323  NamespaceDeclaration &namespaceDeclaration = namespaceDeclarations[j];
3324  if (namespaceDeclaration.namespaceUri == namespaceUri) {
3325  if (!noDefault || !namespaceDeclaration.prefix.isEmpty())
3326  return namespaceDeclaration;
3327  }
3328  }
3329  if (namespaceUri.isEmpty())
3330  return emptyNamespace;
3331  NamespaceDeclaration &namespaceDeclaration = namespaceDeclarations.push();
3332  if (namespaceUri.isEmpty()) {
3333  namespaceDeclaration.prefix.clear();
3334  } else {
3335  QString s;
3336  int n = ++namespacePrefixCount;
3337  forever {
3338  s = QLatin1Char('n') + QString::number(n++);
3339  int j = namespaceDeclarations.size() - 2;
3340  while (j >= 0 && namespaceDeclarations.at(j).prefix != s)
3341  --j;
3342  if (j < 0)
3343  break;
3344  }
3345  namespaceDeclaration.prefix = addToStringStorage(s);
3346  }
3347  namespaceDeclaration.namespaceUri = addToStringStorage(namespaceUri);
3348  if (writeDeclaration)
3349  writeNamespaceDeclaration(namespaceDeclaration);
3350  return namespaceDeclaration;
3351 }
static QString number(int, int base=10)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: qstring.cpp:6448
The QString class provides a Unicode character string.
Definition: qstring.h:83
void writeNamespaceDeclaration(const NamespaceDeclaration &namespaceDeclaration)
QXmlStreamSimpleStack< NamespaceDeclaration > namespaceDeclarations
Definition: qxmlstream_p.h:697
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
NamespaceDeclaration emptyNamespace
QStringRef addToStringStorage(const QStringRef &s)
Definition: qxmlstream_p.h:702
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55
#define forever
This macro is provided for convenience for writing infinite loops.
Definition: qglobal.h:2452

◆ finishStartElement()

bool QXmlStreamWriterPrivate::finishStartElement ( bool  contents = true)

Definition at line 3300 of file qxmlstream.cpp.

3301 {
3302  bool hadSomethingWritten = wroteSomething;
3303  wroteSomething = contents;
3304  if (!inStartElement)
3305  return hadSomethingWritten;
3306 
3307  if (inEmptyElement) {
3308  write("/>");
3311  lastWasStartElement = false;
3312  } else {
3313  write(">");
3314  }
3315  inStartElement = inEmptyElement = false;
3317  return hadSomethingWritten;
3318 }
QXmlStreamSimpleStack< NamespaceDeclaration > namespaceDeclarations
Definition: qxmlstream_p.h:697
void write(const QStringRef &)

◆ indent()

void QXmlStreamWriterPrivate::indent ( int  level)

Definition at line 3355 of file qxmlstream.cpp.

3356 {
3357  write("\n");
3358  for (int i = level; i > 0; --i)
3360 }
int length() const
Same as size().
Definition: qbytearray.h:356
const char * constData() const
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:433
QByteArray autoFormattingIndent
void write(const QStringRef &)

◆ write() [1/4]

void QXmlStreamWriterPrivate::write ( const QStringRef s)

Definition at line 3202 of file qxmlstream.cpp.

Referenced by finishStartElement(), indent(), write(), writeEscaped(), and writeNamespaceDeclaration().

3203 {
3204  if (device) {
3205  if (hasError)
3206  return;
3207 #ifdef QT_NO_TEXTCODEC
3208  QByteArray bytes = s.toLatin1();
3209 #else
3210  QByteArray bytes = encoder->fromUnicode(s.constData(), s.size());
3211 #endif
3212  if (device->write(bytes) != bytes.size())
3213  hasError = true;
3214  }
3215  else if (stringDevice)
3217  else
3218  qWarning("QXmlStreamWriter: No device");
3219 }
QStringRef appendTo(QString *string) const
Appends the string reference to string, and returns a new reference to the combined string data...
Definition: qstring.cpp:8828
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
QTextEncoder * encoder
const QChar * constData() const
Same as unicode().
Definition: qstring.h:1159
int size() const
Returns the number of characters referred to by the string reference.
Definition: qstring.h:1114
Q_CORE_EXPORT void qWarning(const char *,...)
int size() const
Returns the number of bytes in this byte array.
Definition: qbytearray.h:402
QByteArray toLatin1() const Q_REQUIRED_RESULT
Returns a Latin-1 representation of the string as a QByteArray.
Definition: qstring.cpp:9788
qint64 write(const char *data, qint64 len)
Writes at most maxSize bytes of data from data to the device.
Definition: qiodevice.cpp:1342
QByteArray fromUnicode(const QString &str)
Converts the Unicode string str into an encoded QByteArray.

◆ write() [2/4]

void QXmlStreamWriterPrivate::write ( const QString s)

Definition at line 3221 of file qxmlstream.cpp.

3222 {
3223  if (device) {
3224  if (hasError)
3225  return;
3226 #ifdef QT_NO_TEXTCODEC
3227  QByteArray bytes = s.toLatin1();
3228 #else
3229  QByteArray bytes = encoder->fromUnicode(s);
3230 #endif
3231  if (device->write(bytes) != bytes.size())
3232  hasError = true;
3233  }
3234  else if (stringDevice)
3235  stringDevice->append(s);
3236  else
3237  qWarning("QXmlStreamWriter: No device");
3238 }
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
QTextEncoder * encoder
Q_CORE_EXPORT void qWarning(const char *,...)
QByteArray toLatin1() const Q_REQUIRED_RESULT
Returns a Latin-1 representation of the string as a QByteArray.
Definition: qstring.cpp:3993
QString & append(QChar c)
Definition: qstring.cpp:1777
int size() const
Returns the number of bytes in this byte array.
Definition: qbytearray.h:402
qint64 write(const char *data, qint64 len)
Writes at most maxSize bytes of data from data to the device.
Definition: qiodevice.cpp:1342
QByteArray fromUnicode(const QString &str)
Converts the Unicode string str into an encoded QByteArray.

◆ write() [3/4]

void QXmlStreamWriterPrivate::write ( const char *  s,
int  len 
)

Definition at line 3271 of file qxmlstream.cpp.

3272 {
3273  if (device) {
3274  if (hasError)
3275  return;
3276  if (isCodecASCIICompatible) {
3277  if (device->write(s, len) != len)
3278  hasError = true;
3279  return;
3280  }
3281  }
3282 
3283  write(QString::fromLatin1(s, len));
3284 }
static QString fromLatin1(const char *, int size=-1)
Returns a QString initialized with the first size characters of the Latin-1 string str...
Definition: qstring.cpp:4188
void write(const QStringRef &)
qint64 write(const char *data, qint64 len)
Writes at most maxSize bytes of data from data to the device.
Definition: qiodevice.cpp:1342

◆ write() [4/4]

template<int N>
void QXmlStreamWriterPrivate::write ( const char(&)  s[N])
inline

Definition at line 3137 of file qxmlstream.cpp.

Referenced by write().

3137 { write(s, N - 1); }
void write(const QStringRef &)

◆ writeEscaped()

void QXmlStreamWriterPrivate::writeEscaped ( const QString s,
bool  escapeWhitespace = false 
)

Definition at line 3240 of file qxmlstream.cpp.

3241 {
3242  QString escaped;
3243  escaped.reserve(s.size());
3244  for ( int i = 0; i < s.size(); ++i ) {
3245  QChar c = s.at(i);
3246  if (c.unicode() == '<' )
3247  escaped.append(QLatin1String("&lt;"));
3248  else if (c.unicode() == '>' )
3249  escaped.append(QLatin1String("&gt;"));
3250  else if (c.unicode() == '&' )
3251  escaped.append(QLatin1String("&amp;"));
3252  else if (c.unicode() == '\"' )
3253  escaped.append(QLatin1String("&quot;"));
3254  else if (escapeWhitespace && c.isSpace()) {
3255  if (c.unicode() == '\n')
3256  escaped.append(QLatin1String("&#10;"));
3257  else if (c.unicode() == '\r')
3258  escaped.append(QLatin1String("&#13;"));
3259  else if (c.unicode() == '\t')
3260  escaped.append(QLatin1String("&#9;"));
3261  else
3262  escaped += c;
3263  } else {
3264  escaped += QChar(c);
3265  }
3266  }
3267  write(escaped);
3268 }
unsigned char c[8]
Definition: qnumeric_p.h:62
const QChar at(int i) const
Returns the character at the given index position in the string.
Definition: qstring.h:698
ushort unicode() const
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: qchar.h:251
The QString class provides a Unicode character string.
Definition: qstring.h:83
The QChar class provides a 16-bit Unicode character.
Definition: qchar.h:72
bool isSpace() const
Returns true if the character is a separator character (Separator_* categories); otherwise returns fa...
Definition: qchar.cpp:609
void reserve(int size)
Attempts to allocate memory for at least size characters.
Definition: qstring.h:881
int size() const
Returns the number of characters in this string.
Definition: qstring.h:102
The QLatin1String class provides a thin wrapper around an US-ASCII/Latin-1 encoded string literal...
Definition: qstring.h:654
QString & append(QChar c)
Definition: qstring.cpp:1777
void write(const QStringRef &)

◆ writeNamespaceDeclaration()

void QXmlStreamWriterPrivate::writeNamespaceDeclaration ( const NamespaceDeclaration namespaceDeclaration)

Definition at line 3286 of file qxmlstream.cpp.

Referenced by findNamespace().

3286  {
3287  if (namespaceDeclaration.prefix.isEmpty()) {
3288  write(" xmlns=\"");
3289  write(namespaceDeclaration.namespaceUri);
3290  write("\"");
3291  } else {
3292  write(" xmlns:");
3293  write(namespaceDeclaration.prefix);
3294  write("=\"");
3295  write(namespaceDeclaration.namespaceUri);
3296  write("\"");
3297  }
3298 }
void write(const QStringRef &)

◆ writeStartElement()

void QXmlStreamWriterPrivate::writeStartElement ( const QString namespaceUri,
const QString name 
)

Definition at line 4042 of file qxmlstream.cpp.

4043 {
4044  if (!finishStartElement(false) && autoFormatting)
4045  indent(tagStack.size());
4046 
4047  Tag &tag = tagStack_push();
4048  tag.name = addToStringStorage(name);
4049  tag.namespaceDeclaration = findNamespace(namespaceUri);
4050  write("<");
4051  if (!tag.namespaceDeclaration.prefix.isEmpty()) {
4052  write(tag.namespaceDeclaration.prefix);
4053  write(":");
4054  }
4055  write(tag.name);
4057 
4058  for (int i = lastNamespaceDeclaration; i < namespaceDeclarations.size(); ++i)
4060  tag.namespaceDeclarationsSize = lastNamespaceDeclaration;
4061 }
Tag
Definition: qtranslator.cpp:86
bool finishStartElement(bool contents=true)
void writeNamespaceDeclaration(const NamespaceDeclaration &namespaceDeclaration)
QXmlStreamSimpleStack< NamespaceDeclaration > namespaceDeclarations
Definition: qxmlstream_p.h:697
void indent(int level)
NamespaceDeclaration & findNamespace(const QString &namespaceUri, bool writeDeclaration=false, bool noDefault=false)
QStringRef addToStringStorage(const QStringRef &s)
Definition: qxmlstream_p.h:702
void write(const QStringRef &)
QXmlStreamSimpleStack< Tag > tagStack
Definition: qxmlstream_p.h:721

Properties

◆ autoFormatting

uint QXmlStreamWriterPrivate::autoFormatting

Definition at line 3148 of file qxmlstream.cpp.

Referenced by QXmlStreamWriterPrivate().

◆ autoFormattingIndent

QByteArray QXmlStreamWriterPrivate::autoFormattingIndent

Definition at line 3150 of file qxmlstream.cpp.

Referenced by indent().

◆ codec

QTextCodec* QXmlStreamWriterPrivate::codec

Definition at line 3155 of file qxmlstream.cpp.

Referenced by QXmlStreamWriterPrivate().

◆ deleteDevice

uint QXmlStreamWriterPrivate::deleteDevice

Definition at line 3142 of file qxmlstream.cpp.

Referenced by QXmlStreamWriterPrivate().

◆ device

QIODevice* QXmlStreamWriterPrivate::device

Definition at line 3140 of file qxmlstream.cpp.

Referenced by QXmlStreamWriterPrivate(), and write().

◆ emptyNamespace

NamespaceDeclaration QXmlStreamWriterPrivate::emptyNamespace

Definition at line 3151 of file qxmlstream.cpp.

Referenced by findNamespace().

◆ encoder

QTextEncoder* QXmlStreamWriterPrivate::encoder

Definition at line 3156 of file qxmlstream.cpp.

Referenced by checkIfASCIICompatibleCodec(), QXmlStreamWriterPrivate(), and write().

◆ hasError

uint QXmlStreamWriterPrivate::hasError

Definition at line 3147 of file qxmlstream.cpp.

Referenced by QXmlStreamWriterPrivate(), and write().

◆ inEmptyElement

uint QXmlStreamWriterPrivate::inEmptyElement

Definition at line 3144 of file qxmlstream.cpp.

Referenced by finishStartElement(), and QXmlStreamWriterPrivate().

◆ inStartElement

uint QXmlStreamWriterPrivate::inStartElement

Definition at line 3143 of file qxmlstream.cpp.

Referenced by finishStartElement(), and QXmlStreamWriterPrivate().

◆ isCodecASCIICompatible

uint QXmlStreamWriterPrivate::isCodecASCIICompatible

Definition at line 3149 of file qxmlstream.cpp.

Referenced by checkIfASCIICompatibleCodec(), and write().

◆ lastNamespaceDeclaration

int QXmlStreamWriterPrivate::lastNamespaceDeclaration

Definition at line 3152 of file qxmlstream.cpp.

Referenced by finishStartElement(), and QXmlStreamWriterPrivate().

◆ lastWasStartElement

uint QXmlStreamWriterPrivate::lastWasStartElement

Definition at line 3145 of file qxmlstream.cpp.

Referenced by finishStartElement(), and QXmlStreamWriterPrivate().

◆ namespacePrefixCount

int QXmlStreamWriterPrivate::namespacePrefixCount

Definition at line 3163 of file qxmlstream.cpp.

Referenced by findNamespace(), and QXmlStreamWriterPrivate().

◆ q_ptr

QXmlStreamWriter* QXmlStreamWriterPrivate::q_ptr
private

Definition at line 3121 of file qxmlstream.cpp.

◆ stringDevice

QString* QXmlStreamWriterPrivate::stringDevice

Definition at line 3141 of file qxmlstream.cpp.

Referenced by QXmlStreamWriterPrivate(), and write().

◆ wroteSomething

uint QXmlStreamWriterPrivate::wroteSomething

Definition at line 3146 of file qxmlstream.cpp.

Referenced by finishStartElement(), and QXmlStreamWriterPrivate().


The documentation for this class was generated from the following file: