Qt 4.8
Public Functions | Properties | List of all members
QIsciiCodec Class Reference

The QIsciiCodec class provides conversion to and from the ISCII encoding. More...

#include <qisciicodec_p.h>

Inheritance diagram for QIsciiCodec:
QTextCodec

Public Functions

QByteArray convertFromUnicode (const QChar *, int, ConverterState *) const
 QTextCodec subclasses must reimplement this function. More...
 
QString convertToUnicode (const char *, int, ConverterState *) const
 QTextCodec subclasses must reimplement this function. More...
 
int mibEnum () const
 Subclasses of QTextCodec must reimplement this function. More...
 
QByteArray name () const
 QTextCodec subclasses must reimplement this function. More...
 
 QIsciiCodec (int i)
 
 ~QIsciiCodec ()
 
- 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...
 

Properties

int idx
 

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

The QIsciiCodec class provides conversion to and from the ISCII encoding.

Warning
This function is not part of the public interface.

Definition at line 62 of file qisciicodec_p.h.

Constructors and Destructors

◆ QIsciiCodec()

QIsciiCodec::QIsciiCodec ( int  i)
inlineexplicit

Definition at line 64 of file qisciicodec_p.h.

64 : idx(i) {}

◆ ~QIsciiCodec()

QIsciiCodec::~QIsciiCodec ( )

Definition at line 76 of file qisciicodec.cpp.

Referenced by QIsciiCodec().

77 {
78 }

Functions

◆ convertFromUnicode()

QByteArray QIsciiCodec::convertFromUnicode ( const QChar input,
int  number,
ConverterState state 
) const
virtual

QTextCodec subclasses must reimplement this function.

Converts the first number of characters from the input array from Unicode to the encoding of the subclass, and returns the result in a QByteArray.

state can be 0 in which case the conversion is stateless and default conversion rules should be used. If state is not 0, the codec should save the state after the conversion in state, and adjust the remainingChars and invalidChars members of the struct.

Implements QTextCodec.

Definition at line 181 of file qisciicodec.cpp.

Referenced by QIsciiCodec().

182 {
183  char replacement = '?';
184  bool halant = false;
185  if (state) {
186  if (state->flags & ConvertInvalidToNull)
187  replacement = 0;
188  halant = state->state_data[0];
189  }
190  int invalid = 0;
191 
192  QByteArray result(2 * len, Qt::Uninitialized); //worst case
193 
194  uchar *ch = reinterpret_cast<uchar *>(result.data());
195 
196  const int base = codecs[idx].base;
197 
198  for (int i =0; i < len; ++i) {
199  const ushort codePoint = uc[i].unicode();
200 
201  /* The low 7 bits of ISCII is plain ASCII. However, we go all the
202  * way up to 0xA0 such that we can roundtrip with convertToUnicode()'s
203  * behavior. */
204  if(codePoint < 0xA0) {
205  *ch++ = static_cast<uchar>(codePoint);
206  continue;
207  }
208 
209  const int pos = codePoint - base;
210  if (pos > 0 && pos < 0x80) {
211  uchar iscii = uni_to_iscii_table[pos];
212  if (iscii > 0x80) {
213  *ch++ = iscii;
214  } else if (iscii) {
215  const uchar *pair = uni_to_iscii_pairs + 2*iscii;
216  *ch++ = *pair++;
217  *ch++ = *pair++;
218  } else {
219  *ch++ = replacement;
220  ++invalid;
221  }
222  } else {
223  if (uc[i].unicode() == 0x200c) { // ZWNJ
224  if (halant)
225  // Consonant Halant ZWNJ -> Consonant Halant Halant
226  *ch++ = 0xe8;
227  } else if (uc[i].unicode() == 0x200d) { // ZWJ
228  if (halant)
229  // Consonant Halant ZWJ -> Consonant Halant Nukta
230  *ch++ = 0xe9;
231  } else {
232  *ch++ = replacement;
233  ++invalid;
234  }
235  }
236  halant = (pos == 0x4d);
237  }
238  result.truncate(ch - (uchar *)result.data());
239 
240  if (state) {
241  state->invalidChars += invalid;
242  state->state_data[0] = halant;
243  }
244  return result;
245 }
static const uchar uni_to_iscii_table[0x80]
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
static const Codecs codecs[]
Definition: qisciicodec.cpp:64
static const uint base
Definition: qurl.cpp:268
unsigned char uchar
Definition: qglobal.h:994
ushort base
Definition: qisciicodec.cpp:61
static const uchar uni_to_iscii_pairs[]
unsigned short ushort
Definition: qglobal.h:995

◆ convertToUnicode()

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

QTextCodec subclasses must reimplement this function.

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

state can be 0, in which case the conversion is stateless and default conversion rules should be used. If state is not 0, the codec should save the state after the conversion in state, and adjust the remainingChars and invalidChars members of the struct.

Implements QTextCodec.

Definition at line 247 of file qisciicodec.cpp.

Referenced by QIsciiCodec().

248 {
249  bool halant = false;
250  if (state) {
251  halant = state->state_data[0];
252  }
253 
254  QString result(len, Qt::Uninitialized);
255  QChar *uc = result.data();
256 
257  const int base = codecs[idx].base;
258 
259  for (int i = 0; i < len; ++i) {
260  ushort ch = (uchar) chars[i];
261  if (ch < 0xa0)
262  *uc++ = ch;
263  else {
264  ushort c = iscii_to_uni_table[ch - 0xa0];
265  if (halant && (c == inv || c == 0xe9)) {
266  // Consonant Halant inv -> Consonant Halant ZWJ
267  // Consonant Halant Nukta -> Consonant Halant ZWJ
268  *uc++ = QChar(0x200d);
269  } else if (halant && c == 0xe8) {
270  // Consonant Halant Halant -> Consonant Halant ZWNJ
271  *uc++ = QChar(0x200c);
272  } else {
273  *uc++ = QChar(c+base);
274  }
275  }
276  halant = ((uchar)chars[i] == 0xe8);
277  }
278  result.resize(uc - result.unicode());
279 
280  if (state) {
281  state->state_data[0] = halant;
282  }
283  return result;
284 }
unsigned char c[8]
Definition: qnumeric_p.h:62
ushort unicode() const
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: qchar.h:251
static const uchar inv
Definition: qisciicodec.cpp:91
static const Codecs codecs[]
Definition: qisciicodec.cpp:64
The QString class provides a Unicode character string.
Definition: qstring.h:83
static const uint base
Definition: qurl.cpp:268
The QChar class provides a 16-bit Unicode character.
Definition: qchar.h:72
unsigned char uchar
Definition: qglobal.h:994
ushort base
Definition: qisciicodec.cpp:61
static const uchar iscii_to_uni_table[0x60]
Definition: qisciicodec.cpp:94
unsigned short ushort
Definition: qglobal.h:995

◆ mibEnum()

int QIsciiCodec::mibEnum ( ) const
virtual

Subclasses of QTextCodec must reimplement this function.

It returns the MIBenum (see IANA character-sets encoding file for more information). It is important that each QTextCodec subclass returns the correct unique value for this function.

Implements QTextCodec.

Definition at line 85 of file qisciicodec.cpp.

Referenced by QIsciiCodec().

86 {
87  /* There is no MIBEnum for Iscii */
88  return -3000-idx;
89 }

◆ name()

QByteArray QIsciiCodec::name ( ) const
virtual

QTextCodec subclasses must reimplement this function.

It returns the name of the encoding supported by the subclass.

If the codec is registered as a character set in the IANA character-sets encoding file this method should return the preferred mime name for the codec if defined, otherwise its name.

Implements QTextCodec.

Definition at line 80 of file qisciicodec.cpp.

Referenced by QIsciiCodec().

81 {
82  return codecs[idx].name;
83 }
const char name[10]
Definition: qisciicodec.cpp:60
static const Codecs codecs[]
Definition: qisciicodec.cpp:64

Properties

◆ idx

int QIsciiCodec::idx
private

Definition at line 74 of file qisciicodec_p.h.


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