QIsciiCodec Class Reference

#include <qisciicodec_p.h>

Inheritance diagram for QIsciiCodec:

Inheritance graph
[legend]
Collaboration diagram for QIsciiCodec:

Collaboration graph
[legend]
List of all members.

Detailed Description

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

Definition at line 42 of file qisciicodec_p.h.

Public Member Functions

 QIsciiCodec (int i)
 ~QIsciiCodec ()
QByteArray name () const
int mibEnum () const
QString convertToUnicode (const char *, int, ConverterState *) const
QByteArray convertFromUnicode (const QChar *, int, ConverterState *) const

Private Attributes

int idx


Constructor & Destructor Documentation

QIsciiCodec::QIsciiCodec ( int  i  )  [inline, explicit]

Definition at line 44 of file qisciicodec_p.h.

00044 : idx(i) {}

QIsciiCodec::~QIsciiCodec (  ) 

Definition at line 54 of file qisciicodec.cpp.

00055 {
00056 }


Member Function Documentation

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 58 of file qisciicodec.cpp.

References codecs, idx, and Codecs::name.

00059 {
00060   return codecs[idx].name;
00061 }

int QIsciiCodec::mibEnum (  )  const [virtual]

Subclasses of QTextCodec must reimplement this function. It returns the MIBenum (see the 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 63 of file qisciicodec.cpp.

References idx.

00064 {
00065     /* There is no MIBEnum for Iscii */
00066     return -3000-idx;
00067 }

QString QIsciiCodec::convertToUnicode ( const char *  ,
int  ,
ConverterState *   
) const

Definition at line 217 of file qisciicodec.cpp.

References Codecs::base, base, c, codecs, i, idx, INV, iscii_to_uni_table, QString::resize(), and QString::unicode().

00218 {
00219     bool halant = false;
00220     if (state) {
00221         halant = state->state_data[0];
00222     }
00223 
00224     QString result;
00225     result.resize(len);
00226     QChar *uc = (QChar *)result.unicode();
00227 
00228     int base = codecs[idx].base;
00229 
00230     for (int i = 0; i < len; ++i) {
00231         ushort ch = (uchar) chars[i];
00232         if (ch < 0xa0)
00233             *uc++ = ch;
00234         else {
00235             ushort c = iscii_to_uni_table[ch - 0xa0];
00236             if (halant && (c == INV || c == 0xe9)) {
00237                 // Consonant Halant INV -> Consonant Halant ZWJ
00238                 // Consonant Halant Nukta -> Consonant Halant ZWJ
00239                 *uc++ = QChar(0x200d);
00240             } else if (halant && c == 0xe8) {
00241                 // Consonant Halant Halant -> Consonant Halant ZWNJ
00242                 *uc++ = QChar(0x200c);
00243             } else {
00244                 *uc++ = QChar(c+base);
00245             }
00246         }
00247         halant = ((uchar)chars[i] == 0xe8);
00248     }
00249     result.resize(uc - result.unicode());
00250 
00251     if (state) {
00252         state->state_data[0] = halant;
00253     }
00254     return result;
00255 }

Here is the call graph for this function:

QByteArray QIsciiCodec::convertFromUnicode ( const QChar ,
int  ,
ConverterState *   
) const

Definition at line 160 of file qisciicodec.cpp.

References base, Codecs::base, codecs, QTextCodec::ConvertInvalidToNull, QByteArray::data(), i, idx, QByteArray::resize(), QByteArray::truncate(), uni_to_iscii_pairs, uni_to_iscii_table, and x80.

00161 {
00162     char replacement = '?';
00163     bool halant = false;
00164     if (state) {
00165         if (state->flags & ConvertInvalidToNull)
00166             replacement = 0;
00167         halant = state->state_data[0];
00168     }
00169     int invalid = 0;
00170 
00171     QByteArray result;
00172     result.resize(2*len); //worst case
00173 
00174     uchar *ch = (uchar *)result.data();
00175 
00176     int base = codecs[idx].base;
00177 
00178     for (int i =0; i < len; ++i) {
00179         int pos = uc[i].unicode() - base;
00180         if (pos > 0 && pos < 0x80) {
00181             uchar iscii = uni_to_iscii_table[pos];
00182             if (iscii > 0x80) {
00183                 *ch++ = iscii;
00184             } else if (iscii) {
00185                 const uchar *pair = uni_to_iscii_pairs + 2*iscii;
00186                 *ch++ = *pair++;
00187                 *ch++ = *pair++;
00188             } else {
00189                 *ch++ = replacement;
00190                 ++invalid;
00191             }
00192         } else {
00193             if (uc[i].unicode() == 0x200c) { // ZWNJ
00194                 if (halant)
00195                     // Consonant Halant ZWNJ -> Consonant Halant Halant
00196                     *ch++ = 0xe8;
00197             } else if (uc[i].unicode() == 0x200d) { // ZWJ
00198                 if (halant)
00199                     // Consonant Halant ZWJ -> Consonant Halant Nukta
00200                     *ch++ = 0xe9;
00201             } else {
00202                 *ch++ = replacement;
00203                 ++invalid;
00204             }
00205         }
00206         halant = (pos == 0x4d);
00207     }
00208     result.truncate(ch - (uchar *)result.data());
00209 
00210     if (state) {
00211         state->invalidChars += invalid;
00212         state->state_data[0] = halant;
00213     }
00214     return result;
00215 }

Here is the call graph for this function:


Member Data Documentation

int QIsciiCodec::idx [private]

Definition at line 54 of file qisciicodec_p.h.

Referenced by convertFromUnicode(), convertToUnicode(), mibEnum(), and name().


The documentation for this class was generated from the following files:
Generated on Thu Mar 15 18:04:48 2007 for Qt 4.2 User's Guide by  doxygen 1.5.1