Qt 4.8
Static Public Functions | List of all members
QUtf16 Struct Reference

#include <qutfcodec_p.h>

Static Public Functions

static QByteArray convertFromUnicode (const QChar *, int, QTextCodec::ConverterState *, DataEndianness=DetectEndianness)
 
static QString convertToUnicode (const char *, int, QTextCodec::ConverterState *, DataEndianness=DetectEndianness)
 

Detailed Description

Definition at line 74 of file qutfcodec_p.h.

Functions

◆ convertFromUnicode()

QByteArray QUtf16::convertFromUnicode ( const QChar uc,
int  len,
QTextCodec::ConverterState state,
DataEndianness  e = DetectEndianness 
)
static

Definition at line 269 of file qutfcodec.cpp.

Referenced by QUtf16Codec::convertFromUnicode().

270 {
271  DataEndianness endian = e;
272  int length = 2*len;
273  if (!state || (!(state->flags & QTextCodec::IgnoreHeader))) {
274  length += 2;
275  }
276  if (e == DetectEndianness) {
277  endian = (QSysInfo::ByteOrder == QSysInfo::BigEndian) ? BigEndianness : LittleEndianness;
278  }
279 
280  QByteArray d;
281  d.resize(length);
282  char *data = d.data();
283  if (!state || !(state->flags & QTextCodec::IgnoreHeader)) {
285  if (endian == BigEndianness) {
286  data[0] = bom.row();
287  data[1] = bom.cell();
288  } else {
289  data[0] = bom.cell();
290  data[1] = bom.row();
291  }
292  data += 2;
293  }
294  if (endian == BigEndianness) {
295  for (int i = 0; i < len; ++i) {
296  *(data++) = uc[i].row();
297  *(data++) = uc[i].cell();
298  }
299  } else {
300  for (int i = 0; i < len; ++i) {
301  *(data++) = uc[i].cell();
302  *(data++) = uc[i].row();
303  }
304  }
305 
306  if (state) {
307  state->remainingChars = 0;
309  }
310  return d;
311 }
Q_CORE_EXPORT QTextStream & bom(QTextStream &s)
double d
Definition: qnumeric_p.h:62
char * data()
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:429
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
The QChar class provides a 16-bit Unicode character.
Definition: qchar.h:72
DataEndianness
Definition: qutfcodec_p.h:61
static const char * data(const QByteArray &arr)
ConversionFlags flags
Definition: qtextcodec.h:106
void resize(int size)
Sets the size of the byte array to size bytes.

◆ convertToUnicode()

QString QUtf16::convertToUnicode ( const char *  chars,
int  len,
QTextCodec::ConverterState state,
DataEndianness  e = DetectEndianness 
)
static

Definition at line 313 of file qutfcodec.cpp.

Referenced by QUtf16Codec::convertToUnicode(), and QString::fromUtf16().

314 {
315  DataEndianness endian = e;
316  bool half = false;
317  uchar buf = 0;
318  bool headerdone = false;
319  if (state) {
320  headerdone = state->flags & QTextCodec::IgnoreHeader;
321  if (endian == DetectEndianness)
322  endian = (DataEndianness)state->state_data[Endian];
323  if (state->remainingChars) {
324  half = true;
325  buf = state->state_data[Data];
326  }
327  }
328  if (headerdone && endian == DetectEndianness)
329  endian = (QSysInfo::ByteOrder == QSysInfo::BigEndian) ? BigEndianness : LittleEndianness;
330 
331  QString result(len, Qt::Uninitialized); // worst case
332  QChar *qch = (QChar *)result.unicode();
333  while (len--) {
334  if (half) {
335  QChar ch;
336  if (endian == LittleEndianness) {
337  ch.setRow(*chars++);
338  ch.setCell(buf);
339  } else {
340  ch.setRow(buf);
341  ch.setCell(*chars++);
342  }
343  if (!headerdone) {
344  headerdone = true;
345  if (endian == DetectEndianness) {
346  if (ch == QChar::ByteOrderSwapped) {
347  endian = LittleEndianness;
348  } else if (ch == QChar::ByteOrderMark) {
349  endian = BigEndianness;
350  } else {
351  if (QSysInfo::ByteOrder == QSysInfo::BigEndian) {
352  endian = BigEndianness;
353  } else {
354  endian = LittleEndianness;
355  ch = QChar((ch.unicode() >> 8) | ((ch.unicode() & 0xff) << 8));
356  }
357  *qch++ = ch;
358  }
359  } else if (ch != QChar::ByteOrderMark) {
360  *qch++ = ch;
361  }
362  } else {
363  *qch++ = ch;
364  }
365  half = false;
366  } else {
367  buf = *chars++;
368  half = true;
369  }
370  }
371  result.truncate(qch - result.unicode());
372 
373  if (state) {
374  if (headerdone)
376  state->state_data[Endian] = endian;
377  if (half) {
378  state->remainingChars = 1;
379  state->state_data[Data] = buf;
380  } else {
381  state->remainingChars = 0;
382  state->state_data[Data] = 0;
383  }
384  }
385  return result;
386 }
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
unsigned char uchar
Definition: qglobal.h:994
DataEndianness
Definition: qutfcodec_p.h:61
ConversionFlags flags
Definition: qtextcodec.h:106
if(void) toggleToolbarShown
void setRow(uchar row)
Definition: qchar.h:389
void setCell(uchar cell)
Definition: qchar.h:387

The documentation for this struct was generated from the following files: