fetchtrjava.cpp
来自「奇趣公司比较新的qt/emd版本」· C++ 代码 · 共 609 行 · 第 1/2 页
CPP
609 行
return Tok_Plus; 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.toLatin1()) : yyCh.isDigit() ) { ba+=yyCh; yyCh = getChar(); } bool ok; yyInteger = ba.toLongLong(&ok); if (ok) return Tok_Integer; break; } default: yyCh = getChar(); } } } return Tok_Eof;}static bool match( int t ){ bool matches = ( yyTok == t ); if ( matches ) yyTok = getToken(); return matches;}static bool matchString( QString &s ){ if ( yyTok != Tok_String ) return false; s = yyString; yyTok = getToken(); while ( yyTok == Tok_Plus ) { yyTok = getToken(); if(yyTok == Tok_String) s += yyString; else { qWarning( "%s:%d: String used in translation can only contain strings concatenated with other strings, not expresions or numbers.", (const char *) yyFileName, yyLineNo ); return false; } yyTok = getToken(); } return true;}static bool matchInteger( qlonglong *number){ bool matches = (yyTok == Tok_Integer); if (matches) { yyTok = getToken(); *number = yyInteger; } return matches;}static bool matchStringOrNull(QString &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 (parenlevel == 0) { return false; } } return true;}static const QString context(){ QString context(yyPackage); bool innerClass = false; for (int i = 0; i < yyScope.size(); ++i) { if (yyScope.at(i)->type == Scope::Clazz){ if(innerClass) context.append("$"); else context.append("."); context.append(yyScope.at(i)->name); innerClass = true; } } return context.isEmpty() ? yyDefaultContext : context;}static void parse( MetaTranslator *tor ){ QString text; QString com; yyCh = getChar(); yyTok = getToken(); while ( yyTok != Tok_Eof ) { switch ( yyTok ) { case Tok_class: yyTok = getToken(); if(yyTok == Tok_Ident) { yyScope.push(new Scope(yyIdent, Scope::Clazz, yyLineNo)); } else { qFatal( "%s:%d: Class must be followed by a classname", (const char *) yyFileName, yyLineNo ); } while (!match(Tok_LeftBrace)) { yyTok = getToken(); } break; case Tok_tr: yyTok = getToken(); if ( match(Tok_LeftParen) && matchString(text) ) { com = ""; bool plural = false; if ( match(Tok_RightParen) ) { // no comment } else if (match(Tok_Comma) && matchStringOrNull(com)) { //comment if ( match(Tok_RightParen)) { // ok, } else if (match(Tok_Comma)) { plural = true; } } tor->insert( MetaTranslatorMessage(context().toUtf8(), text.toUtf8(), com.toUtf8(), QLatin1String(yyFileName), yyLineNo, QStringList(), true, MetaTranslatorMessage::Unfinished, plural) ); } break; case Tok_translate: { QString contextOverride; yyTok = getToken(); if ( match(Tok_LeftParen) && matchString(contextOverride) && match(Tok_Comma) && matchString(text) ) { com = ""; bool plural = false; if (!match(Tok_RightParen)) { // look for comment if ( match(Tok_Comma) && matchStringOrNull(com)) { if (!match(Tok_RightParen)) { if (match(Tok_Comma) && matchExpression() && match(Tok_RightParen)) { plural = true; } else { break; } } } else { break; } } tor->insert( MetaTranslatorMessage(contextOverride.toUtf8(), text.toUtf8(), com.toUtf8(), QLatin1String(yyFileName), yyLineNo, QStringList(), true, MetaTranslatorMessage::Unfinished, plural) ); } } break; case Tok_Ident: yyTok = getToken(); break; case Tok_RightBrace: if ( yyScope.isEmpty() ) { qFatal( "%s:%d: Unbalanced right brace in Java code\n", (const char *)yyFileName, yyLineNo ); } else delete (yyScope.pop()); yyTok = getToken(); break; case Tok_LeftBrace: yyScope.push(new Scope("", Scope::Other, yyLineNo)); yyTok = getToken(); break; case Tok_Semicolon: yyTok = getToken(); break; case Tok_Package: yyTok = getToken(); while(!match(Tok_Semicolon)) { switch(yyTok) { case Tok_Ident: yyPackage.append(yyIdent); break; case Tok_Dot: yyPackage.append("."); break; default: qFatal( "%s:%d: Package keyword should be followed by com.package.name;", (const char *) yyFileName, yyLineNo ); break; } yyTok = getToken(); } break; default: yyTok = getToken(); } } if ( !yyScope.isEmpty() ) qFatal( "%s:%d: Unbalanced braces in Java code\n", (const char *)yyFileName, yyScope.top()->line ); else if ( yyParenDepth != 0 ) qFatal( "%s:%d: Unbalanced parentheses in Java code\n", (const char *)yyFileName, yyParenLineNo );}void fetchtr_java( const char *fileName, MetaTranslator *tor, const char *defaultContext, bool mustExist, const QByteArray &codecForSource ){ yyDefaultContext = defaultContext; yyInPos = -1; yyFileName = fileName; yyPackage = ""; yyInStr = ""; yyScope.clear(); yyTok = -1; yyParenDepth = 0; yyCurLineNo = 0; yyParenLineNo = 1; QFile file(fileName); if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) { if( mustExist ) qFatal( "lupdate error: Cannot open java source file '%s'\n", fileName); } yyInTextStream = new QTextStream( &file ); if( !codecForSource.isEmpty() ) { yyInTextStream->setCodec( QTextCodec::codecForName(codecForSource) ); } parse( tor ); delete( yyInTextStream );}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?