Public Member Functions | Private Attributes | List of all members
QUtf8Decoder Class Reference
Inheritance diagram for QUtf8Decoder:
QTextDecoder

Public Member Functions

 QUtf8Decoder ()
 
QString toUnicode (const char *chars, int len)
 
- Public Member Functions inherited from QTextDecoder
virtual ~QTextDecoder ()
 

Private Attributes

ushort uc
 
int need
 

Detailed Description

Definition at line 120 of file qutfcodec.cpp.

Constructor & Destructor Documentation

QUtf8Decoder::QUtf8Decoder ( )
inline

Definition at line 124 of file qutfcodec.cpp.

124  : need(0)
125  {
126  }

Member Function Documentation

QString QUtf8Decoder::toUnicode ( const char *  chars,
int  len 
)
inlinevirtual

Converts the first len bytes at chars to Unicode, returning the result.

If not all characters are used (eg. only part of a multi-byte encoding is at the end of the characters), the decoder remembers enough state to continue with the next call to this function.

Implements QTextDecoder.

Definition at line 128 of file qutfcodec.cpp.

129  {
130  QString result;
131  for (int i=0; i<len; i++) {
132  uchar ch = chars[i];
133  if (need) {
134  if ( (ch&0xc0) == 0x80 ) {
135  uc = (uc << 6) | (ch & 0x3f);
136  need--;
137  if ( !need ) {
138  result += QChar(uc);
139  }
140  } else {
141  // error
142  result += QChar::replacement;
143  need = 0;
144  }
145  } else {
146  if ( ch < 128 ) {
147  result += QChar(ch);
148  } else if ( (ch&0xe0) == 0xc0 ) {
149  uc = ch &0x1f;
150  need = 1;
151  } else if ( (ch&0xf0) == 0xe0 ) {
152  uc = ch &0x0f;
153  need = 2;
154  }
155  }
156  }
157  return result;
158  }
static QCString result
The QString class provides an abstraction of Unicode text and the classic C null-terminated char arra...
Definition: qstring.h:350
The QChar class provides a light-weight Unicode character.
Definition: qstring.h:56
unsigned char uchar
Definition: nybbler.cc:11
QT_STATIC_CONST QChar replacement
Definition: qstring.h:69

Member Data Documentation

int QUtf8Decoder::need
private

Definition at line 122 of file qutfcodec.cpp.

ushort QUtf8Decoder::uc
private

Definition at line 121 of file qutfcodec.cpp.


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