Qt 4.8
Public Functions | List of all members
QTsciiCodec Class Reference

#include <qtsciicodec_p.h>

Inheritance diagram for QTsciiCodec:
QTextCodec

Public Functions

QByteArray convertFromUnicode (const QChar *, int, ConverterState *) const
 Converts the first len characters in uc from Unicode to this encoding, and returns the result in a byte array. More...
 
QString convertToUnicode (const char *, int, ConverterState *) const
 Converts the first len characters in chars from this encoding to Unicode, and returns the result in a QString. More...
 
int mibEnum () const
 Returns the MIB enum for the encoding. More...
 
QByteArray name () const
 Returns the official name for the encoding that is handled by the codec. More...
 
 ~QTsciiCodec ()
 Destroys the text codec object. More...
 
- Public Functions inherited from QTextCodec
virtual QList< QByteArrayaliases () const
 Subclasses can return a number of aliases for the codec in question. More...
 
bool canEncode (QChar) const
 Returns true if the Unicode character ch can be fully encoded with this codec; otherwise returns false. More...
 
bool canEncode (const QString &) const
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.s contains the string being tested for encode-ability. More...
 
QByteArray fromUnicode (const QString &uc) const
 Converts str from Unicode to the encoding of this codec, and returns the result in a QByteArray. More...
 
QByteArray fromUnicode (const QChar *in, int length, ConverterState *state=0) const
 Converts the first number of characters from the input array from Unicode to the encoding of this codec, and returns the result in a QByteArray. More...
 
QTextDecodermakeDecoder () const
 Creates a QTextDecoder which stores enough state to decode chunks of char * data to create chunks of Unicode data. More...
 
QTextDecodermakeDecoder (ConversionFlags flags) const
 
QTextEncodermakeEncoder () const
 Creates a QTextEncoder which stores enough state to encode chunks of Unicode data as char * data. More...
 
QTextEncodermakeEncoder (ConversionFlags flags) const
 
QString toUnicode (const QByteArray &) const
 Converts a from the encoding of this codec to Unicode, and returns the result in a QString. More...
 
QString toUnicode (const char *chars) const
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.chars contains the source characters. More...
 
QString toUnicode (const char *in, int length, ConverterState *state=0) const
 Converts the first size characters from the input from the encoding of this codec to Unicode, and returns the result in a QString. More...
 

Additional Inherited Members

- Public Types inherited from QTextCodec
enum  ConversionFlag { DefaultConversion, ConvertInvalidToNull = 0x80000000, IgnoreHeader = 0x1, FreeFunction = 0x2 }
 
- Static Public Functions inherited from QTextCodec
static QList< QByteArrayavailableCodecs ()
 Returns the list of all available codecs, by name. More...
 
static QList< int > availableMibs ()
 Returns the list of MIBs for all available codecs. More...
 
static QTextCodeccodecForCStrings ()
 Returns the codec used by QString to convert to and from const char * and QByteArrays. More...
 
static QTextCodeccodecForHtml (const QByteArray &ba)
 Tries to detect the encoding of the provided snippet of HTML in the given byte array, ba, by checking the BOM (Byte Order Mark) and the content-type meta header and returns a QTextCodec instance that is capable of decoding the html to unicode. More...
 
static QTextCodeccodecForHtml (const QByteArray &ba, QTextCodec *defaultCodec)
 Tries to detect the encoding of the provided snippet of HTML in the given byte array, ba, by checking the BOM (Byte Order Mark) and the content-type meta header and returns a QTextCodec instance that is capable of decoding the html to unicode. More...
 
static QTextCodeccodecForLocale ()
 Returns a pointer to the codec most suitable for this locale. More...
 
static QTextCodeccodecForMib (int mib)
 Returns the QTextCodec which matches the MIBenum mib. More...
 
static QTextCodeccodecForName (const QByteArray &name)
 Searches all installed QTextCodec objects and returns the one which best matches name; the match is case-insensitive. More...
 
static QTextCodeccodecForName (const char *name)
 Searches all installed QTextCodec objects and returns the one which best matches name; the match is case-insensitive. More...
 
static QTextCodeccodecForTr ()
 Returns the codec used by QObject::tr() on its argument. More...
 
static QTextCodeccodecForUtfText (const QByteArray &ba)
 Tries to detect the encoding of the provided snippet ba by using the BOM (Byte Order Mark) and returns a QTextCodec instance that is capable of decoding the text to unicode. More...
 
static QTextCodeccodecForUtfText (const QByteArray &ba, QTextCodec *defaultCodec)
 Tries to detect the encoding of the provided snippet ba by using the BOM (Byte Order Mark) and returns a QTextCodec instance that is capable of decoding the text to unicode. More...
 
static void setCodecForCStrings (QTextCodec *c)
 
static void setCodecForLocale (QTextCodec *c)
 Set the codec to c; this will be returned by codecForLocale(). More...
 
static void setCodecForTr (QTextCodec *c)
 
- Protected Functions inherited from QTextCodec
 QTextCodec ()
 Constructs a QTextCodec, and gives it the highest precedence. More...
 
virtual ~QTextCodec ()
 Destroys the QTextCodec. More...
 

Detailed Description

Note
This class or function is reentrant.
Warning
This function is not part of the public interface.

Definition at line 91 of file qtsciicodec_p.h.

Constructors and Destructors

◆ ~QTsciiCodec()

QTsciiCodec::~QTsciiCodec ( )

Destroys the text codec object.

Definition at line 66 of file qtsciicodec.cpp.

67 {
68 }

Functions

◆ convertFromUnicode()

QByteArray QTsciiCodec::convertFromUnicode ( const QChar uc,
int  len,
ConverterState state 
) const
virtual

Converts the first len characters in uc from Unicode to this encoding, and returns the result in a byte array.

The state contains some conversion flags, and is used by the codec to maintain state information.

Implements QTextCodec.

Definition at line 76 of file qtsciicodec.cpp.

77 {
78  char replacement = '?';
79  if (state) {
80  if (state->flags & ConvertInvalidToNull)
81  replacement = 0;
82  }
83  int invalid = 0;
84 
85  QByteArray rstr(len, Qt::Uninitialized);
86  uchar* cursor = (uchar*)rstr.data();
87  for (int i = 0; i < len; i++) {
88  QChar ch = uc[i];
89  uchar j;
90  if (ch.row() == 0x00 && ch.cell() < 0x80) {
91  // ASCII
92  j = ch.cell();
93  } else if ((j = qt_UnicodeToTSCII(uc[i].unicode(),
94  uc[i + 1].unicode(),
95  uc[i + 2].unicode()))) {
96  // We have to check the combined chars first!
97  i += 2;
98  } else if ((j = qt_UnicodeToTSCII(uc[i].unicode(),
99  uc[i + 1].unicode(), 0))) {
100  i++;
101  } else if ((j = qt_UnicodeToTSCII(uc[i].unicode(), 0, 0))) {
102  } else {
103  // Error
104  j = replacement;
105  ++invalid;
106  }
107  *cursor++ = j;
108  }
109  rstr.resize(cursor - (const uchar*)rstr.constData());
110 
111  if (state) {
112  state->invalidChars += invalid;
113  }
114  return rstr;
115 }
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
unsigned char uchar
Definition: qglobal.h:994
static unsigned char qt_UnicodeToTSCII(ushort u1, ushort u2, ushort u3)
uchar cell() const
Returns the cell (least significant byte) of the Unicode character.
Definition: qchar.h:283
uchar row() const
Returns the row (most significant byte) of the Unicode character.
Definition: qchar.h:284

◆ convertToUnicode()

QString QTsciiCodec::convertToUnicode ( const char *  chars,
int  len,
ConverterState state 
) const
virtual

Converts the first len characters in chars from this encoding to Unicode, and returns the result in a QString.

The state contains some conversion flags, and is used by the codec to maintain state information.

Implements QTextCodec.

Definition at line 123 of file qtsciicodec.cpp.

124 {
125  QChar replacement = QChar::ReplacementCharacter;
126  if (state) {
127  if (state->flags & ConvertInvalidToNull)
128  replacement = QChar::Null;
129  }
130  int invalid = 0;
131 
132  QString result;
133  for (int i = 0; i < len; i++) {
134  uchar ch = chars[i];
135  if (ch < 0x80) {
136  // ASCII
137  result += QLatin1Char(ch);
138  } else if (IsTSCIIChar(ch)) {
139  // TSCII
140  uint s[3];
141  uint u = qt_TSCIIToUnicode(ch, s);
142  uint *p = s;
143  while (u--) {
144  uint c = *p++;
145  if (c)
146  result += QChar(c);
147  else {
148  result += replacement;
149  ++invalid;
150  }
151  }
152  } else {
153  // Invalid
154  result += replacement;
155  ++invalid;
156  }
157  }
158 
159  if (state) {
160  state->invalidChars += invalid;
161  }
162  return result;
163 }
#define IsTSCIIChar(c)
Definition: qtsciicodec.cpp:56
unsigned char c[8]
Definition: qnumeric_p.h:62
quint16 u
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
static unsigned int qt_TSCIIToUnicode(unsigned int code, uint *s)
unsigned int uint
Definition: qglobal.h:996
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55

◆ mibEnum()

int QTsciiCodec::mibEnum ( ) const
virtual

Returns the MIB enum for the encoding.

See also
QTextCodec::mibEnum()

Implements QTextCodec.

Definition at line 180 of file qtsciicodec.cpp.

181 {
182  return 2107;
183 }

◆ name()

QByteArray QTsciiCodec::name ( ) const
virtual

Returns the official name for the encoding that is handled by the codec.

See also
QTextCodec::name()

Implements QTextCodec.

Definition at line 170 of file qtsciicodec.cpp.

171 {
172  return "TSCII";
173 }

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