⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 translator.cpp

📁 qt-x11-opensource-src-4.1.4.tar.gz源码
💻 CPP
📖 第 1 页 / 共 3 页
字号:
            t >> len;            if (len == 0)                return TranslatorMessage();            t.readRawData(con, len);            con[len] = '\0';            if (qstrcmp(con, context) == 0)                break;        }    }    size_t numItems = d->offsetArray.size() / (2 * sizeof(quint32));    if (!numItems)        return TranslatorMessage();    for (;;) {        quint32 h = elfHash(QByteArray(sourceText) + comment);        char *r = (char *) bsearch(&h, d->offsetArray, numItems,                                   2 * sizeof(quint32),                                   (QSysInfo::ByteOrder == QSysInfo::BigEndian) ? cmp_uint32_big                                   : cmp_uint32_little);        if (r != 0) {            // go back on equal key            while (r != d->offsetArray.constData() && cmp_uint32_big(r - 8, r) == 0)                r -= 8;            QDataStream s(d->offsetArray);            s.device()->seek(r - d->offsetArray.constData());            quint32 rh, ro;            s >> rh >> ro;            QDataStream ms(d->messageArray);            while (rh == h) {                ms.device()->seek(ro);                TranslatorMessage m(ms);                if (match(m.context(), context)                        && match(m.sourceText(), sourceText)                        && match(m.comment(), comment))                    return m;                if (s.atEnd())                    break;                s >> rh >> ro;            }        }        if (!comment[0])            break;        comment = "";    }    return TranslatorMessage();}/*!    Returns true if this translator is empty, otherwise returns false.    This function works with stripped and unstripped translation files.*/bool Translator::isEmpty() const{    return !d->unmapPointer && !d->unmapLength && d->messageArray.isEmpty() &&           d->offsetArray.isEmpty() && d->contextArray.isEmpty() && d->messages.isEmpty();}#ifndef QT_NO_TRANSLATION_BUILDER/*!    Returns a list of the messages in the translator. This function is    rather slow. Because it is seldom called, it's optimized for    simplicity and small size, rather than speed.    If you want to iterate over the list, you should iterate over a    copy, e.g.    \code    QList<TranslatorMessage> list = myTranslator.messages();    QList<TranslatorMessage>::Iterator it = list.begin();    while (it != list.end()) {        process_message(*it);        ++it;    }  \endcode*/QList<TranslatorMessage> Translator::messages() const{    ((Translator *) this)->unsqueeze();    return d->messages.keys();}#endif/*!    \class TranslatorMessage    \brief The TranslatorMessage class contains a translator message and its    properties.    \ingroup i18n    \ingroup environment    This class is of no interest to most applications. It is useful    for translation tools such as \l{Qt Linguist Manual}{Qt Linguist}.    It is provided simply to make the API complete and regular.    For a Translator object, a lookup key is a triple (\e context, \e    {source text}, \e comment) that uniquely identifies a message. An    extended key is a quadruple (\e hash, \e context, \e {source    text}, \e comment), where \e hash is computed from the source text    and the comment. Unless you plan to read and write messages    yourself, you need not worry about the hash value.    TranslatorMessage stores this triple or quadruple and the relevant    translation if there is any.    \sa Translator*//*!    Constructs a translator message with the extended key (0, 0, 0, 0)    and an empty string as translation.*/TranslatorMessage::TranslatorMessage()    : h(0){}/*!    Constructs an translator message with the extended key (\e h, \a    context, \a sourceText, \a comment), where \e h is computed from    \a sourceText and \a comment, and possibly with a \a translation.*/TranslatorMessage::TranslatorMessage(const char * context,                                        const char * sourceText,                                        const char * comment,                                        const QString& translation)    : cx(context), st(sourceText), cm(comment), tn(translation){    // 0 means we don't know, "" means empty    if (cx == (const char*)0)        cx = "";    if (st == (const char*)0)        st = "";    if (cm == (const char*)0)        cm = "";    h = elfHash(st + cm);}/*!    Constructs a translator message read from the \a stream. The    resulting message may have any combination of content.    \sa Translator::save()*/TranslatorMessage::TranslatorMessage(QDataStream & stream)    : h(0){    QString str16;    char tag;    quint8 obs1;    for (;;) {        tag = 0;        if (!stream.atEnd())            stream.readRawData(&tag, 1);        switch((Tag)tag) {        case Tag_End:            if (h == 0)                h = elfHash(st + cm);            return;        case Tag_SourceText16: // obsolete            stream >> str16;            st = str16.toLatin1();            break;        case Tag_Translation:            stream >> tn;            break;        case Tag_Context16: // obsolete            stream >> str16;            cx = str16.toLatin1();            break;        case Tag_Hash:            stream >> h;            break;        case Tag_SourceText:            stream >> st;            break;        case Tag_Context:            stream >> cx;            if (cx.isEmpty()) // for compatibility                cx = 0;            break;        case Tag_Comment:            stream >> cm;            break;        case Tag_Obsolete1: // obsolete            stream >> obs1;            break;        default:            h = 0;            st = 0;            cx = 0;            cm = 0;            tn.clear();            return;        }    }}/*!    Constructs a copy of translator message \a m.*/TranslatorMessage::TranslatorMessage(const TranslatorMessage & m)    : cx(m.cx), st(m.st), cm(m.cm), tn(m.tn){    h = m.h;}/*!    Assigns message \a m to this translator message and returns a    reference to this translator message.*/TranslatorMessage & TranslatorMessage::operator=(        const TranslatorMessage & m){    h = m.h;    cx = m.cx;    st = m.st;    cm = m.cm;    tn = m.tn;    return *this;}/*!    \fn uint TranslatorMessage::hash() const    Returns the hash value used internally to represent the lookup    key. This value is zero only if this translator message was    constructed from a stream containing invalid data.    The hashing function is unspecified, but it will remain unchanged    in future versions of Qt.*//*!    \fn const char *TranslatorMessage::context() const    Returns the context for this message (e.g. "MyDialog").*//*!    \fn const char *TranslatorMessage::sourceText() const    Returns the source text of this message (e.g. "&Save").*//*!    \fn const char *TranslatorMessage::comment() const    Returns the comment for this message (e.g. "File|Save").*//*!    \fn void TranslatorMessage::setTranslation(const QString & translation)    Sets the translation of the source text to \a translation.    \sa translation()*//*!    \fn QString TranslatorMessage::translation() const    Returns the translation of the source text (e.g., "&Sauvegarder").    \sa setTranslation()*//*!    \enum TranslatorMessage::Prefix    Let (\e h, \e c, \e s, \e m) be the extended key. The possible    prefixes are    \value NoPrefix  no prefix    \value Hash  only (\e h)    \value HashContext  only (\e h, \e c)    \value HashContextSourceText  only (\e h, \e c, \e s)    \value HashContextSourceTextComment  the whole extended key, (\e        h, \e c, \e s, \e m)    \sa write() commonPrefix()*//*!    Writes this translator message to the \a stream. If \a strip is    false (the default), all the information in the message is    written. If \a strip is true, only the part of the extended key    specified by \a prefix is written with the translation (\c    HashContextSourceTextComment by default).    \sa commonPrefix()*/void TranslatorMessage::write(QDataStream & stream, bool strip,                                Prefix prefix) const{    char tag;    tag = (char)Tag_Translation;    stream.writeRawData(&tag, 1);    stream << tn;    if (!strip)        prefix = HashContextSourceTextComment;    switch (prefix) {    case HashContextSourceTextComment:        tag = (char)Tag_Comment;        stream.writeRawData(&tag, 1);        stream << cm;        // fall through    case HashContextSourceText:        tag = (char)Tag_SourceText;        stream.writeRawData(&tag, 1);        stream << st;        // fall through    case HashContext:        tag = (char)Tag_Context;        stream.writeRawData(&tag, 1);        stream << cx;        // fall through    default:        tag = (char)Tag_Hash;        stream.writeRawData(&tag, 1);        stream << h;    }    tag = (char)Tag_End;    stream.writeRawData(&tag, 1);}/*!    Returns the widest lookup prefix that is common to this translator    message and to message \a m.    For example, if the extended key is for this message is (71,    "PrintDialog", "Yes", "Print?") and that for \a m is (71,    "PrintDialog", "No", "Print?"), this function returns \c    HashContext.    \sa write()*/TranslatorMessage::Prefix TranslatorMessage::commonPrefix(        const TranslatorMessage& m) const{    if (h != m.h)        return NoPrefix;    if (cx != m.cx)        return Hash;    if (st != m.st)        return HashContext;    if (cm != m.cm)        return HashContextSourceText;    return HashContextSourceTextComment;}/*! Returns true if the extended key of this object is equal to that of \a m; otherwise returns false.*/bool TranslatorMessage::operator==(const TranslatorMessage& m) const{    return h == m.h && cx == m.cx && st == m.st && cm == m.cm;}/*!    \fn bool TranslatorMessage::operator!=(const TranslatorMessage& m) const    Returns true if the extended key of this object is different from    that of \a m; otherwise returns false.*//*!    Returns true if the extended key of this object is    lexicographically before than that of \a m; otherwise returns    false.*/bool TranslatorMessage::operator<(const TranslatorMessage& m) const{    return h != m.h ? h < m.h           : (cx != m.cx ? cx < m.cx             : (st != m.st ? st < m.st : cm < m.cm));}/*!    \fn bool TranslatorMessage::operator<=(const TranslatorMessage& m) const    Returns true if the extended key of this object is    lexicographically before that of \a m or if they are equal;    otherwise returns false.*//*!    \fn bool TranslatorMessage::operator>(const TranslatorMessage& m) const    Returns true if the extended key of this object is    lexicographically after that of \a m; otherwise returns false.*//*!    \fn bool TranslatorMessage::operator>=(const TranslatorMessage& m) const    Returns true if the extended key of this object is    lexicographically after that of \a m or if they are equal;    otherwise returns false.*//*!    \fn QString Translator::find(const char *context, const char *sourceText, const char * comment) const    Use findMessage() instead.*/#endif // QT_NO_TRANSLATION

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -