fetchtr.cpp

来自「奇趣公司比较新的qt/emd版本」· C++ 代码 · 共 1,105 行 · 第 1/3 页

CPP
1,105
字号
                            if ( yyStringLen < sizeof(yyString) - 1 )                                yyString[yyStringLen++] = (char) n;                        } else {                            const char *p = strchr( tab, yyCh );                            if ( yyStringLen < sizeof(yyString) - 1 )                                yyString[yyStringLen++] = ( p == 0 ) ?                                        (char) yyCh : backTab[p - tab];                            yyCh = getChar();                        }                    } else {						if (!yyCodecForSource) {							if ( yyParsingUtf8 && yyCh >= 0x80 && !quiet) {								qWarning( "%s:%d: Non-ASCII character detected in trUtf8 string",										  (const char *) yyFileName, yyLineNo );								quiet = true;							}							// common case: optimized							if ( yyStringLen < sizeof(yyString) - 1 )								yyString[yyStringLen++] = (char) yyCh;							yyCh = getChar();						} else {							QByteArray originalBytes;							while ( yyCh != EOF && yyCh != '\n' && yyCh != '"' && yyCh != '\\' ) {								if ( yyParsingUtf8 && yyCh >= 0x80 && !quiet) {									qWarning( "%s:%d: Non-ASCII character detected in trUtf8 string",											(const char *) yyFileName, yyLineNo );									quiet = true;								}								originalBytes += (char)yyCh;								yyCh = getChar();							}							QString unicodeStr = yyCodecForSource->toUnicode(originalBytes);							QByteArray convertedBytes;							if (!yyCodecForTr->canEncode(unicodeStr) && !quiet) {								qWarning( "%s:%d: Cannot convert C++ string from %s to %s",										  (const char *) yyFileName, yyLineNo, yyCodecForSource->name().constData(),										  yyCodecForTr->name().constData() );								quiet = true;							}							convertedBytes = yyCodecForTr->fromUnicode(unicodeStr);							size_t len = qMin((size_t)convertedBytes.size(), sizeof(yyString) - yyStringLen - 1);							memcpy(yyString + yyStringLen, convertedBytes.constData(), len);							yyStringLen += len;						}                    }                }                yyString[yyStringLen] = '\0';                if ( yyCh != '"' )                    qWarning( "%s:%d: Unterminated C++ string",                              (const char *) yyFileName, yyLineNo );                if ( yyCh == EOF ) {                    return Tok_Eof;                } else {                    yyCh = getChar();                    return Tok_String;                }                break;            case '-':                yyCh = getChar();                if ( yyCh == '>' ) {                    yyCh = getChar();                    return Tok_Arrow;                }                break;            case ':':                yyCh = getChar();                if ( yyCh == ':' ) {                    yyCh = getChar();                    return Tok_Gulbrandsen;                }                return Tok_Colon;            case '\'':                yyCh = getChar();                if ( yyCh == '\\' )                    yyCh = getChar();                do {                    yyCh = getChar();                } while ( yyCh != EOF && yyCh != '\'' );                yyCh = getChar();                break;            case '{':                if (yyBraceDepth == 0)                    yyBraceLineNo = yyCurLineNo;                yyBraceDepth++;                yyCh = getChar();                return Tok_LeftBrace;            case '}':                if (yyBraceDepth == 0)                    yyBraceLineNo = yyCurLineNo;                yyBraceDepth--;                yyCh = getChar();                return Tok_RightBrace;            case '(':                if (yyParenDepth == 0)                    yyParenLineNo = yyCurLineNo;                yyParenDepth++;                yyCh = getChar();                return Tok_LeftParen;            case ')':                if (yyParenDepth == 0)                    yyParenLineNo = yyCurLineNo;                yyParenDepth--;                yyCh = getChar();                return Tok_RightParen;            case ',':                yyCh = getChar();                return Tok_Comma;            case ';':                yyCh = getChar();                return Tok_Semicolon;            case '0':            case '1':            case '2':            case '3':            case '4':            case '5':            case '6':            case '7':            case '8':            case '9':                {                    QByteArray ba;                    ba+=yyCh;                    yyCh = getChar();                    bool hex = yyCh == 'x';                    if ( hex ) {                        ba+=yyCh;                        yyCh = getChar();                    }                    while ( (hex ? isxdigit(yyCh) : isdigit(yyCh)) ) {                        ba+=yyCh;                        yyCh = getChar();                    }                    bool ok;                    yyInteger = ba.toLongLong(&ok);                    if (ok) return Tok_Integer;                    break;                }            default:                yyCh = getChar();            }        }    }    return Tok_Eof;}/*  The second part of this source file is the parser. It accomplishes  a very easy task: It finds all strings inside a tr() or translate()  call, and possibly finds out the context of the call. It supports  three cases: (1) the context is specified, as in  FunnyDialog::tr("Hello") or translate("FunnyDialog", "Hello");  (2) the call appears within an inlined function; (3) the call  appears within a function defined outside the class definition.*/static int yyTok;static bool match( int t ){    bool matches = ( yyTok == t );    if ( matches )        yyTok = getToken();    return matches;}static bool matchString( QByteArray *s ){    bool matches = ( yyTok == Tok_String );    *s = "";    while ( yyTok == Tok_String ) {        *s += yyString;        yyTok = getToken();    }    return matches;}static bool matchEncoding( bool *utf8 ){    if ( yyTok == Tok_Ident ) {        if ( strcmp(yyIdent, "QApplication") == 0 || strcmp(yyIdent, "QCoreApplication") == 0) {            yyTok = getToken();            if ( yyTok == Tok_Gulbrandsen )                yyTok = getToken();        }        if (strcmp(yyIdent, "UnicodeUTF8") == 0) {            *utf8 = true;            yyTok = getToken();        } else if (strcmp(yyIdent, "DefaultCodec") == 0) {            *utf8 = false;            yyTok = getToken();        } else {            return false;        }        return true;    } else {        return false;    }}static bool matchInteger( qlonglong *number){    bool matches = (yyTok == Tok_Integer);    if (matches) {        yyTok = getToken();        *number = yyInteger;    }    return matches;}static bool matchStringOrNull(QByteArray *s){    bool matches = matchString(s);    qlonglong num = 0;    if (!matches) matches = matchInteger(&num);    return matches && num == 0;}/* * match any expression that can return a number, which can be * 1. Literal number (e.g. '11') * 2. simple identifier (e.g. 'm_count') * 3. simple function call (e.g. 'size()' ) * 4. function call on an object (e.g. 'list.size()') * 5. function call on an object (e.g. 'list->size()') * * Other cases: * size(2,4) * list().size() * list(a,b).size(2,4) * etc... */static bool matchExpression(){    if (match(Tok_Integer)) {        return true;    }    int parenlevel = 0;    while (match(Tok_Ident) || parenlevel > 0) {        if (yyTok == Tok_RightParen) {            if (parenlevel == 0) break;            --parenlevel;            yyTok = getToken();        } else if (yyTok == Tok_LeftParen) {            yyTok = getToken();            if (yyTok == Tok_RightParen) {                yyTok = getToken();            } else {                ++parenlevel;            }        } else if (yyTok == Tok_Ident) {            continue;        } else if (yyTok == Tok_Arrow) {            yyTok = getToken();        } else if (parenlevel == 0) {            return false;        }    }    return true;}static QByteArray getFullyQualifiedClassName(const QList<QByteArray> &classes, const QStringList &namespaces,                                              const QByteArray &ident, bool hasPrefix = false){    QByteArray context = ident;    if (context.endsWith("::"))        context.chop(2);    int n = namespaces.count() - 1;     if (!context.startsWith("::")) {        for ( ; n >= 0; --n) {            QByteArray ns;            for (int i = 0; i <= n; ++i) {                ns+=namespaces[i].toAscii() + "::";            }            if (classes.indexOf(ns + context) != -1) {                context = ns + context;                break;            }        }        if (!hasPrefix && n == -1 && namespaces.count()) {            context = namespaces.join(QLatin1String("::")).toLatin1() + "::" + context;        }    } else {        context.remove(0, 2);    }    return context;}static void parse( MetaTranslator *tor, const char *initialContext, const char *defaultContext ){    QMap<QByteArray, QByteArray> qualifiedContexts;    QStringList namespaces;    QList<QByteArray> classes;    QByteArray context;    QByteArray text;    QByteArray com;    QByteArray functionContext = initialContext;    QByteArray prefix;#ifdef DIAGNOSE_RETRANSLATABILITY    QByteArray functionName;#endif    bool utf8 = false;    bool missing_Q_OBJECT = false;    yyTok = getToken();    while ( yyTok != Tok_Eof ) {        switch ( yyTok ) {        case Tok_class:            /*              Partial support for inlined functions.            */            yyTok = getToken();            if ( yyBraceDepth == namespaces.count() &&                 yyParenDepth == 0 ) {                do {                    /*                      This code should execute only once, but we play                      safe with impure definitions such as                      'class Q_EXPORT QMessageBox', in which case                      'QMessageBox' is the class name, not 'Q_EXPORT'.                    */                    functionContext = yyIdent;                    yyTok = getToken();                } while ( yyTok == Tok_Ident );                while ( yyTok == Tok_Gulbrandsen ) {                    yyTok = getToken();                    functionContext += "::";                    functionContext += yyIdent;                    yyTok = getToken();                }                if (namespaces.count() > 0) {                    functionContext.prepend( namespaces.join(QLatin1String("::")).toAscii().append("::") );                }                classes.append( functionContext );                if ( yyTok == Tok_Colon ) {                    missing_Q_OBJECT = true;                    // Skip any token until '{' since lupdate might do things wrong if it finds                    // a '::' token here.                    do {                        yyTok = getToken();                    } while (yyTok != Tok_LeftBrace && yyTok != Tok_Eof);                } else {                    functionContext = defaultContext;                }            }            break;        case Tok_namespace:            yyTok = getToken();            if ( yyTok == Tok_Ident ) {                QByteArray ns = yyIdent;                yyTok = getToken();                if ( yyTok == Tok_LeftBrace &&                     yyBraceDepth == namespaces.count() + 1 )                    namespaces.append( QString::fromLatin1(ns.constData()) );            }            break;        case Tok_tr:        case Tok_trUtf8:            utf8 = ( yyTok == Tok_trUtf8 );

⌨️ 快捷键说明

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