QTranslatorPrivate Class Reference

Inheritance diagram for QTranslatorPrivate:

Inheritance graph
[legend]
Collaboration diagram for QTranslatorPrivate:

Collaboration graph
[legend]
List of all members.

Detailed Description

Definition at line 188 of file qtranslator.cpp.

Public Types

enum  

Public Member Functions

 QTranslatorPrivate ()
bool do_load (const uchar *data, int len)
QString do_translate (const char *context, const char *sourceText, const char *comment, int n) const
void clear ()

Public Attributes

uint used_mmap: 1
char * unmapPointer
unsigned int unmapLength
const uchar * messageArray
const uchar * offsetArray
const uchar * contextArray
const uchar * numerusRulesArray
uint messageLength
uint offsetLength
uint contextLength
uint numerusRulesLength


Member Enumeration Documentation

anonymous enum

Definition at line 192 of file qtranslator.cpp.

00192 { Contexts = 0x2f, Hashes = 0x42, Messages = 0x69, NumerusRules = 0x88 };


Constructor & Destructor Documentation

QTranslatorPrivate::QTranslatorPrivate (  )  [inline]

Definition at line 194 of file qtranslator.cpp.


Member Function Documentation

bool QTranslatorPrivate::do_load ( const uchar *  data,
int  len 
)

Definition at line 507 of file qtranslator.cpp.

References contextArray, contextLength, Contexts, Hashes, magic, MagicLength, messageArray, messageLength, Messages, NumerusRules, numerusRulesArray, numerusRulesLength, offsetArray, offsetLength, read32(), and read8().

00508 {
00509     if (!data || len < MagicLength || memcmp(data, magic, MagicLength) != 0)
00510         return false;
00511 
00512     bool ok = true;
00513     const uchar *end = data + len;
00514 
00515     data += MagicLength;
00516 
00517     while (data < end - 4) {
00518         quint8 tag = read8(data++);
00519         quint32 blockLen = read32(data);
00520         data += 4;
00521         if (!tag || !blockLen)
00522             break;
00523         if (data + blockLen > end) {
00524             ok = false;
00525             break;
00526         }
00527 
00528         if (tag == QTranslatorPrivate::Contexts) {
00529             contextArray = data;
00530             contextLength = blockLen;
00531         } else if (tag == QTranslatorPrivate::Hashes) {
00532             offsetArray = data;
00533             offsetLength = blockLen;
00534         } else if (tag == QTranslatorPrivate::Messages) {
00535             messageArray = data;
00536             messageLength = blockLen;
00537         } else if (tag == QTranslatorPrivate::NumerusRules) {
00538             numerusRulesArray = data;
00539             numerusRulesLength = blockLen;
00540         }
00541 
00542         data += blockLen;
00543     }
00544 
00545     return ok;
00546 }

Here is the call graph for this function:

QString QTranslatorPrivate::do_translate ( const char *  context,
const char *  sourceText,
const char *  comment,
int  n 
) const

Definition at line 616 of file qtranslator.cpp.

References c, contextArray, contextLength, elfHash(), g, getMessage(), h, QString::isNull(), len, match(), messageArray, messageLength, numerus(), numerusRulesArray, numerusRulesLength, offsetArray, offsetLength, read16(), read32(), read8(), and start.

00618 {
00619     if (context == 0)
00620         context = "";
00621     if (sourceText == 0)
00622         sourceText = "";
00623     if (comment == 0)
00624         comment = "";
00625 
00626     if (!offsetLength)
00627         return QString();
00628 
00629     /*
00630         Check if the context belongs to this QTranslator. If many
00631         translators are installed, this step is necessary.
00632     */
00633     if (contextLength) {
00634         quint16 hTableSize = read16(contextArray);
00635         uint g = elfHash(context) % hTableSize;
00636         const uchar *c = contextArray + 2 + (g << 1);
00637         quint16 off = read16(c);
00638         c += 2;
00639         if (off == 0)
00640             return QString();
00641         c = contextArray + (2 + (hTableSize << 1) + (off << 1));
00642 
00643         for (;;) {
00644             quint8 len = read8(c++);
00645             if (len == 0)
00646                 return QString();
00647             if (match(c, context, len))
00648                 break;
00649             c += len;
00650         }
00651     }
00652 
00653     size_t numItems = offsetLength / (2 * sizeof(quint32));
00654     if (!numItems)
00655         return QString();
00656 
00657     int numerus = 0;
00658     if (n >= 0)
00659         numerus = ::numerus(n, numerusRulesArray, numerusRulesLength);
00660 
00661     for (;;) {
00662         quint32 h = elfHash(QByteArray(sourceText) + comment);
00663 
00664         const uchar *start = offsetArray;
00665         const uchar *end = start + ((numItems-1) << 3);
00666         while (start <= end) {
00667             const uchar *middle = start + (((end - start) >> 4) << 3);
00668             uint hash = read32(middle);
00669             if (h == hash) {
00670                 start = middle;
00671                 break;
00672             } else if (hash < h) {
00673                 start = middle + 8;
00674             } else {
00675                 end = middle - 8;
00676             }
00677         }
00678 
00679         if (start <= end) {
00680             // go back on equal key
00681             while (start != offsetArray && read32(start) == read32(start-8))
00682                 start -= 8;
00683 
00684             while (start < offsetArray + offsetLength) {
00685                 quint32 rh = read32(start);
00686                 start += 4;
00687                 if (rh != h)
00688                     break;
00689                 quint32 ro = read32(start);
00690                 start += 4;
00691                 QString tn = getMessage(messageArray + ro, messageArray + messageLength, context,
00692                                         sourceText, comment, numerus);
00693                 if (!tn.isNull())
00694                     return tn;
00695             }
00696         }
00697         if (!comment[0])
00698             break;
00699         comment = "";
00700     }
00701     return QString();
00702 }

Here is the call graph for this function:

void QTranslatorPrivate::clear (  ) 

Empties this translator of all contents.

This function works with stripped translator files.

Definition at line 710 of file qtranslator.cpp.

References contextArray, contextLength, QCoreApplication::instance(), QCoreApplicationPrivate::isTranslatorInstalled(), QEvent::LanguageChange, messageArray, messageLength, numerusRulesArray, numerusRulesLength, offsetArray, offsetLength, QCoreApplication::postEvent(), unmapLength, unmapPointer, and used_mmap.

00711 {
00712     Q_Q(QTranslator);
00713     if (unmapPointer && unmapLength) {
00714 #if defined(QT_USE_MMAP)
00715         if (used_mmap)
00716             munmap(unmapPointer, unmapLength);
00717         else
00718 #endif
00719             delete [] unmapPointer;
00720     }
00721 
00722     unmapPointer = 0;
00723     unmapLength = 0;
00724     messageArray = 0;
00725     contextArray = 0;
00726     offsetArray = 0;
00727     numerusRulesArray = 0;
00728     messageLength = 0;
00729     contextLength = 0;
00730     offsetLength = 0;
00731     numerusRulesLength = 0;
00732 
00733     if (QCoreApplicationPrivate::isTranslatorInstalled(q))
00734         QCoreApplication::postEvent(QCoreApplication::instance(),
00735                                     new QEvent(QEvent::LanguageChange));
00736 }

Here is the call graph for this function:


Member Data Documentation

uint QTranslatorPrivate::used_mmap

Definition at line 200 of file qtranslator.cpp.

Referenced by clear().

char* QTranslatorPrivate::unmapPointer

Definition at line 201 of file qtranslator.cpp.

Referenced by clear().

unsigned int QTranslatorPrivate::unmapLength

Definition at line 202 of file qtranslator.cpp.

Referenced by clear().

const uchar* QTranslatorPrivate::messageArray

Definition at line 205 of file qtranslator.cpp.

Referenced by clear(), do_load(), and do_translate().

const uchar* QTranslatorPrivate::offsetArray

Definition at line 206 of file qtranslator.cpp.

Referenced by clear(), do_load(), and do_translate().

const uchar* QTranslatorPrivate::contextArray

Definition at line 207 of file qtranslator.cpp.

Referenced by clear(), do_load(), and do_translate().

const uchar* QTranslatorPrivate::numerusRulesArray

Definition at line 208 of file qtranslator.cpp.

Referenced by clear(), do_load(), and do_translate().

uint QTranslatorPrivate::messageLength

Definition at line 209 of file qtranslator.cpp.

Referenced by clear(), do_load(), and do_translate().

uint QTranslatorPrivate::offsetLength

Definition at line 210 of file qtranslator.cpp.

Referenced by clear(), do_load(), and do_translate().

uint QTranslatorPrivate::contextLength

Definition at line 211 of file qtranslator.cpp.

Referenced by clear(), do_load(), and do_translate().

uint QTranslatorPrivate::numerusRulesLength

Definition at line 212 of file qtranslator.cpp.

Referenced by clear(), do_load(), and do_translate().


The documentation for this class was generated from the following file:
Generated on Thu Mar 15 19:36:15 2007 for Qt 4.2 User's Guide by  doxygen 1.5.1