Classes | Macros | Functions | Variables
qtextcodec.cpp File Reference
#include "qtextcodec.h"
#include "qinternallist.h"
#include "qutfcodec.h"
#include "qfile.h"
#include "qstrlist.h"
#include "qstring.h"
#include <stdlib.h>
#include <ctype.h>
#include <locale.h>

Go to the source code of this file.

Classes

class  QTextStatelessEncoder
 
class  QTextStatelessDecoder
 
struct  QMultiByteUnicodeTable
 
class  QTextCodecFromIODDecoder
 
class  QTextCodecFromIOD
 
class  QSimpleTextCodec
 
class  QLatin1Codec
 

Macros

#define CHAINED   0xffff
 
#define LAST_MIB   2259
 

Functions

static void setupBuiltinCodecs ()
 
static void realSetup ()
 
static void setup ()
 
static QString lettersAndNumbers (const char *input)
 
static bool try_locale_list (const char *const locale[], const char *lang)
 
static QTextCodecru_RU_hack (const char *i)
 
void qt_set_locale_codec (QTextCodec *codec)
 
static int getByte (char *&cursor)
 

Variables

static QInternalList< QTextCodec > * all = 0
 
static bool destroying_is_ok
 
static const char *const iso8859_2locales []
 
static const char *const iso8859_3locales []
 
static const char *const iso8859_4locales []
 
static const char *const iso8859_5locales []
 
static const char *const iso8859_6locales []
 
static const char *const iso8859_7locales []
 
static const char *const iso8859_8locales []
 
static const char *const iso8859_9locales []
 
static const char *const iso8859_15locales []
 
static const char *const koi8_ulocales []
 
static const char *const tis_620locales []
 
static const char *const probably_koi8_rlocales []
 
static QTextCodecru_RU_codec = 0
 
static QTextCodeclocaleMapper = 0
 
struct {
   const char *   cs
 
   int   mib
 
   Q_UINT16   values [128]
 
unicodevalues []
 
static const QSimpleTextCodecreverseOwner = 0
 
static QArray< char > * reverseMap = 0
 

Macro Definition Documentation

#define CHAINED   0xffff

Definition at line 911 of file qtextcodec.cpp.

#define LAST_MIB   2259

Definition at line 1347 of file qtextcodec.cpp.

Function Documentation

static int getByte ( char *&  cursor)
static

Definition at line 929 of file qtextcodec.cpp.

930 {
931  int byte = 0;
932  if ( *cursor ) {
933  if ( cursor[1] == 'x' )
934  byte = (int)strtol(cursor+2,&cursor,16);
935  else if ( cursor[1] == 'd' )
936  byte = (int)strtol(cursor+2,&cursor,10);
937  else
938  byte = (int)strtol(cursor+2,&cursor,8);
939  }
940  return byte&0xff;
941 }
byte_as<> byte
Type of data size stored in bytes, in long long precision.
Definition: datasize.h:98
static QString lettersAndNumbers ( const char *  input)
static

Definition at line 286 of file qtextcodec.cpp.

287 {
288  QString result;
289  QChar c;
290 
291  while( input && *input ) {
292  c = *input;
293  if ( c.isLetter() || c.isNumber() )
294  result += c.lower();
295  if ( input[1] ) {
296  // add space at character class transition, except
297  // transition from upper-case to lower-case letter
298  QChar n( input[1] );
299  if ( c.isLetter() && n.isLetter() ) {
300  if ( c == c.lower() && n == n.upper() )
301  result += ' ';
302  } else if ( c.category() != n.category() ) {
303  result += ' ';
304  }
305  }
306  input++;
307  }
308  return result.simplifyWhiteSpace();
309 }
bool isNumber() const
Definition: qstring.cpp:11046
static QCString result
bool isLetter() const
Definition: qstring.cpp:11035
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
Category category() const
Definition: qstring.cpp:11096
QString simplifyWhiteSpace() const
Definition: qstring.cpp:13482
static int input(void)
Definition: code.cpp:15695
std::void_t< T > n
QChar lower() const
Definition: qstring.cpp:11229
void qt_set_locale_codec ( QTextCodec codec)

Definition at line 535 of file qtextcodec.cpp.

536 {
537  localeMapper = codec;
538 }
static QTextCodec * localeMapper
Definition: qtextcodec.cpp:533
static void realSetup ( )
static

Definition at line 98 of file qtextcodec.cpp.

99 {
100 #if defined(CHECK_STATE)
101  if ( destroying_is_ok )
102  qWarning( "creating new codec during codec cleanup" );
103 #endif
105  all->setAutoDelete( TRUE );
107 }
void qWarning(const char *msg,...)
Definition: qglobal.cpp:409
static bool destroying_is_ok
Definition: qtextcodec.cpp:64
static void setupBuiltinCodecs()
static QInternalList< QTextCodec > * all
Definition: qtextcodec.cpp:63
const bool TRUE
Definition: qglobal.h:371
static QTextCodec* ru_RU_hack ( const char *  i)
static

Definition at line 508 of file qtextcodec.cpp.

508  {
509  if ( ! ru_RU_codec ) {
510  QCString origlocale = setlocale( LC_CTYPE, i );
511  // unicode koi8r latin5 name
512  // 0x044E 0xC0 0xEE CYRILLIC SMALL LETTER YU
513  // 0x042E 0xE0 0xCE CYRILLIC CAPITAL LETTER YU
514  int latin5 = tolower( 0xCE );
515  int koi8r = tolower( 0xE0 );
516  if ( koi8r == 0xC0 && latin5 != 0xEE ) {
518  } else if ( koi8r != 0xC0 && latin5 == 0xEE ) {
519  ru_RU_codec = QTextCodec::codecForName( "ISO 8859-5" );
520  } else {
521  // something else again... let's assume... *throws dice*
523  qWarning( "QTextCodec: using KOI8-R, probe failed (%02x %02x %s)",
524  koi8r, latin5, i );
525  }
526  setlocale( LC_CTYPE, origlocale.data() );
527  }
528  return ru_RU_codec;
529 }
void qWarning(const char *msg,...)
Definition: qglobal.cpp:409
static QTextCodec * ru_RU_codec
Definition: qtextcodec.cpp:506
const char * data() const
Definition: qcstring.h:207
static QTextCodec * codecForName(const char *hint, int accuracy=0)
Definition: qtextcodec.cpp:626
static void setup ( )
inlinestatic

Definition at line 110 of file qtextcodec.cpp.

111 {
112  if ( !all )
113  realSetup();
114 }
static QInternalList< QTextCodec > * all
Definition: qtextcodec.cpp:63
static void realSetup()
Definition: qtextcodec.cpp:98
static void setupBuiltinCodecs ( )
static

Definition at line 2047 of file qtextcodec.cpp.

2048 {
2049  (void)new QLatin1Codec;
2050 
2051 #ifndef QT_NO_CODECS
2052  int i = 0;
2053  do {
2054  (void)new QSimpleTextCodec( i );
2055  } while( unicodevalues[i++].mib != LAST_MIB );
2056 
2057  //(void)new QEucJpCodec;
2058  //(void)new QSjisCodec;
2059  //(void)new QJisCodec;
2060  //(void)new QEucKrCodec;
2061  //(void)new QGbkCodec;
2062  //(void)new QBig5Codec;
2063  (void)new QUtf8Codec;
2064  (void)new QUtf16Codec;
2065  //(void)new QHebrewCodec;
2066  //(void)new QArabicCodec;
2067  //(void)new QTsciiCodec;
2068 #endif // QT_NO_CODECS
2069 }
#define LAST_MIB
static struct @4 unicodevalues[]
int mib
static bool try_locale_list ( const char *const  locale[],
const char *  lang 
)
static

Definition at line 482 of file qtextcodec.cpp.

483 {
484  int i;
485  for( i=0; locale[i] && qstrcmp(locale[i], lang); i++ )
486  { }
487  return locale[i] != 0;
488 }
Q_EXPORT int qstrcmp(const char *str1, const char *str2)
Definition: qcstring.h:95

Variable Documentation

QInternalList<QTextCodec>* all = 0
static

Definition at line 63 of file qtextcodec.cpp.

const char* cs

Definition at line 1350 of file qtextcodec.cpp.

bool destroying_is_ok
static

Definition at line 64 of file qtextcodec.cpp.

const char* const iso8859_15locales[]
static
Initial value:
= {
"fr", "fi", "french", "finnish", "et", "et_EE", 0 }

Definition at line 472 of file qtextcodec.cpp.

const char* const iso8859_2locales[]
static
Initial value:
= {
"croatian", "cs", "cs_CS", "cs_CZ","cz", "cz_CZ", "czech", "hr",
"hr_HR", "hu", "hu_HU", "hungarian", "pl", "pl_PL", "polish", "ro",
"ro_RO", "rumanian", "serbocroatian", "sh", "sh_SP", "sh_YU", "sk",
"sk_SK", "sl", "sl_CS", "sl_SI", "slovak", "slovene", "sr_SP", 0 }

Definition at line 444 of file qtextcodec.cpp.

const char* const iso8859_3locales[]
static
Initial value:
= {
"eo", 0 }

Definition at line 450 of file qtextcodec.cpp.

const char* const iso8859_4locales[]
static
Initial value:
= {
"ee", "ee_EE", "lt", "lt_LT", "lv", "lv_LV", 0 }

Definition at line 453 of file qtextcodec.cpp.

const char* const iso8859_5locales[]
static
Initial value:
= {
"bg", "bg_BG", "bulgarian", "mk", "mk_MK",
"sp", "sp_YU", 0 }

Definition at line 456 of file qtextcodec.cpp.

const char* const iso8859_6locales[]
static
Initial value:
= {
"ar_AA", "ar_SA", "arabic", 0 }

Definition at line 460 of file qtextcodec.cpp.

const char* const iso8859_7locales[]
static
Initial value:
= {
"el", "el_GR", "greek", 0 }

Definition at line 463 of file qtextcodec.cpp.

const char* const iso8859_8locales[]
static
Initial value:
= {
"hebrew", "he", "he_IL", "iw", "iw_IL", 0 }

Definition at line 466 of file qtextcodec.cpp.

const char* const iso8859_9locales[]
static
Initial value:
= {
"tr", "tr_TR", "turkish", 0 }

Definition at line 469 of file qtextcodec.cpp.

const char* const koi8_ulocales[]
static
Initial value:
= {
"uk", "uk_UA", "ru_UA", "ukrainian", 0 }

Definition at line 475 of file qtextcodec.cpp.

QTextCodec* localeMapper = 0
static

Definition at line 533 of file qtextcodec.cpp.

int mib

Definition at line 1351 of file qtextcodec.cpp.

const char* const probably_koi8_rlocales[]
static
Initial value:
= {
"ru", "ru_SU", "ru_RU", "russian", 0 }

Definition at line 501 of file qtextcodec.cpp.

QArray<char>* reverseMap = 0
static

Definition at line 1810 of file qtextcodec.cpp.

const QSimpleTextCodec* reverseOwner = 0
static

Definition at line 1809 of file qtextcodec.cpp.

QTextCodec* ru_RU_codec = 0
static

Definition at line 506 of file qtextcodec.cpp.

const char* const tis_620locales[]
static
Initial value:
= {
"th", "th_TH", "thai", 0 }

Definition at line 478 of file qtextcodec.cpp.

struct { ... } unicodevalues[]
Q_UINT16 values[128]

Definition at line 1352 of file qtextcodec.cpp.