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

#include <qlatincodec_p.h>

Inheritance diagram for QLatin15Codec:
QTextCodec

Public Functions

QList< QByteArrayaliases () const
 Subclasses can return a number of aliases for the codec in question. More...
 
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...
 
 ~QLatin15Codec ()
 
- Public Functions inherited from QTextCodec
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

Definition at line 77 of file qlatincodec_p.h.

Constructors and Destructors

◆ ~QLatin15Codec()

QLatin15Codec::~QLatin15Codec ( )

Definition at line 105 of file qlatincodec.cpp.

106 {
107 }

Functions

◆ aliases()

QList< QByteArray > QLatin15Codec::aliases ( ) const
virtual

Subclasses can return a number of aliases for the codec in question.

Standard aliases for codecs can be found in the IANA character-sets encoding file.

Reimplemented from QTextCodec.

Definition at line 230 of file qlatincodec.cpp.

231 {
232  QList<QByteArray> list;
233  list << "latin9";
234  return list;
235 }

◆ convertFromUnicode()

QByteArray QLatin15Codec::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 150 of file qlatincodec.cpp.

151 {
152  const char replacement = (state && state->flags & ConvertInvalidToNull) ? 0 : '?';
153  QByteArray r(length, Qt::Uninitialized);
154  char *d = r.data();
155  int invalid = 0;
156  for (int i = 0; i < length; ++i) {
157  uchar c;
158  ushort uc = in[i].unicode();
159  if (uc < 0x0100) {
160  if (uc > 0xa3) {
161  switch(uc) {
162  case 0xa4:
163  case 0xa6:
164  case 0xa8:
165  case 0xb4:
166  case 0xb8:
167  case 0xbc:
168  case 0xbd:
169  case 0xbe:
170  c = replacement;
171  ++invalid;
172  break;
173  default:
174  c = (unsigned char) uc;
175  break;
176  }
177  } else {
178  c = (unsigned char) uc;
179  }
180  } else {
181  if (uc == 0x20ac)
182  c = 0xa4;
183  else if ((uc & 0xff00) == 0x0100) {
184  switch(uc) {
185  case 0x0160:
186  c = 0xa6;
187  break;
188  case 0x0161:
189  c = 0xa8;
190  break;
191  case 0x017d:
192  c = 0xb4;
193  break;
194  case 0x017e:
195  c = 0xb8;
196  break;
197  case 0x0152:
198  c = 0xbc;
199  break;
200  case 0x0153:
201  c = 0xbd;
202  break;
203  case 0x0178:
204  c = 0xbe;
205  break;
206  default:
207  c = replacement;
208  ++invalid;
209  }
210  } else {
211  c = replacement;
212  ++invalid;
213  }
214  }
215  d[i] = (char)c;
216  }
217  if (state) {
218  state->remainingChars = 0;
219  state->invalidChars += invalid;
220  }
221  return r;
222 }
double d
Definition: qnumeric_p.h:62
unsigned char c[8]
Definition: qnumeric_p.h:62
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
unsigned char uchar
Definition: qglobal.h:994
unsigned short ushort
Definition: qglobal.h:995

◆ convertToUnicode()

QString QLatin15Codec::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 109 of file qlatincodec.cpp.

110 {
111  if (chars == 0)
112  return QString();
113 
114  QString str = QString::fromLatin1(chars, len);
115  QChar *uc = str.data();
116  while(len--) {
117  switch(uc->unicode()) {
118  case 0xa4:
119  *uc = 0x20ac;
120  break;
121  case 0xa6:
122  *uc = 0x0160;
123  break;
124  case 0xa8:
125  *uc = 0x0161;
126  break;
127  case 0xb4:
128  *uc = 0x017d;
129  break;
130  case 0xb8:
131  *uc = 0x017e;
132  break;
133  case 0xbc:
134  *uc = 0x0152;
135  break;
136  case 0xbd:
137  *uc = 0x0153;
138  break;
139  case 0xbe:
140  *uc = 0x0178;
141  break;
142  default:
143  break;
144  }
145  uc++;
146  }
147  return str;
148 }
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
QChar * data()
Returns a pointer to the data stored in the QString.
Definition: qstring.h:710
static QString fromLatin1(const char *, int size=-1)
Returns a QString initialized with the first size characters of the Latin-1 string str...
Definition: qstring.cpp:4188

◆ mibEnum()

int QLatin15Codec::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 237 of file qlatincodec.cpp.

238 {
239  return 111;
240 }

◆ name()

QByteArray QLatin15Codec::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 225 of file qlatincodec.cpp.

226 {
227  return "ISO-8859-15";
228 }

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