fetchtrjava.cpp
来自「奇趣公司比较新的qt/emd版本」· C++ 代码 · 共 609 行 · 第 1/2 页
CPP
609 行
/******************************************************************************** Copyright (C) 1992-2007 Trolltech ASA. All rights reserved.**** This file is part of the Qt Linguist of the Qt Toolkit.**** This file may be used under the terms of the GNU General Public** License version 2.0 as published by the Free Software Foundation** and appearing in the file LICENSE.GPL included in the packaging of** this file. Please review the following information to ensure GNU** General Public Licensing requirements will be met:** http://trolltech.com/products/qt/licenses/licensing/opensource/**** If you are unsure which license is appropriate for your use, please** review the following information:** http://trolltech.com/products/qt/licenses/licensing/licensingoverview** or contact the sales department at sales@trolltech.com.**** In addition, as a special exception, Trolltech gives you certain** additional rights. These rights are described in the Trolltech GPL** Exception version 1.0, which can be found at** http://www.trolltech.com/products/qt/gplexception/ and in the file** GPL_EXCEPTION.txt in this package.**** In addition, as a special exception, Trolltech, as the sole copyright** holder for Qt Designer, grants users of the Qt/Eclipse Integration** plug-in the right for the Qt/Eclipse Integration to link to** functionality provided by Qt Designer and its related libraries.**** Trolltech reserves all rights not expressly granted herein.**** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.******************************************************************************/#include <metatranslator.h>#include <QFile>#include <QRegExp>#include <QString>#include <QStack>#include <QTextCodec>#include <QStack>#include <QDebug>#include <ctype.h>enum { Tok_Eof, Tok_class, Tok_return, Tok_tr, Tok_translate, Tok_Ident, Tok_Package, Tok_Comment, Tok_String, Tok_Colon, Tok_Dot, Tok_LeftBrace, Tok_RightBrace, Tok_LeftParen, Tok_RightParen, Tok_Comma, Tok_Semicolon, Tok_Integer, Tok_Plus, Tok_PlusPlus, Tok_PlusEq };class Scope{ public: QString name; enum Type {Clazz, Function, Other} type; int line; Scope(QString name, Type type, int line) : name(name), type(type), line(line) {} ~Scope() {}};/* The tokenizer maintains the following global variables. The names should be self-explanatory.*/static QByteArray yyFileName;static QChar yyCh;static QString yyIdent;static QString yyComment;static QString yyString;static qlonglong yyInteger;static int yyParenDepth;static int yyLineNo;static int yyCurLineNo;static int yyParenLineNo;static int yyTok;// the file to read from (if reading from a file)static QTextStream *yyInTextStream;// the string to read from and current position in the string (otherwise)static QString yyInStr;static int yyInPos;// The parser maintains the following global variables.static QString yyPackage;static QStack<Scope*> yyScope;static QString yyDefaultContext;static QChar getChar() { yyInPos ++; if(yyInPos == yyInStr.length() || yyInStr.isEmpty()) { if( yyInTextStream->atEnd() ) { return 0; } yyInStr = yyInTextStream->readLine(); yyCurLineNo ++; yyInPos = -1; return QChar('\n'); } return yyInStr.at( yyInPos );}static int getToken(){ const char tab[] = "bfnrt\"\'\\"; const char backTab[] = "\b\f\n\r\t\"\'\\"; yyIdent = ""; yyComment = ""; yyString = ""; while ( yyCh != 0 ) { yyLineNo = yyCurLineNo; if ( yyCh.isLetter() || yyCh.toLatin1() == '_' ) { do { yyIdent.append(yyCh); yyCh = getChar(); } while ( yyCh.isLetterOrNumber() || yyCh.toLatin1() == '_' ); if(yyTok != Tok_Dot) { switch ( yyIdent.at(0).toLatin1() ) { case 'r': if ( yyIdent == "return" ) return Tok_return; break; case 'c': if ( yyIdent == "class" ) return Tok_class; break; } } switch ( yyIdent.at(0).toLatin1() ) { case 'T': // TR() for when all else fails if ( yyIdent == "TR" ){ return Tok_tr; } break; case 'p': if( yyIdent == "package" ) return Tok_Package; break; case 't': if ( yyIdent == "tr" ) { return Tok_tr; } else if ( yyIdent == "translate" ) { return Tok_translate; } } return Tok_Ident; } else { switch ( yyCh.toLatin1() ) { case '/': yyCh = getChar(); if ( yyCh == '/' ) { do { yyCh = getChar(); yyComment.append(yyCh); } while ( yyCh != 0 && yyCh.toLatin1() != '\n' ); return Tok_Comment; } else if ( yyCh == '*' ) { bool metAster = false; bool metAsterSlash = false; while ( !metAsterSlash ) { yyCh = getChar(); if ( yyCh == EOF ) { qFatal( "%s: Unterminated Java comment starting at" " line %d\n", (const char *) yyFileName, yyLineNo ); return Tok_Comment; } yyComment.append( yyCh ); if ( yyCh == '*' ) metAster = true; else if ( metAster && yyCh == '/' ) metAsterSlash = true; else metAster = false; } yyCh = getChar(); return Tok_Comment; } break; case '"': yyCh = getChar(); while ( yyCh != 0 && yyCh != '\n' && yyCh != '"' ) { if ( yyCh == '\\' ) { yyCh = getChar(); if ( yyCh == 'u' ) { yyCh = getChar(); uint unicode(0); for(int i = 4; i > 0; i--) { unicode = unicode << 4; if( yyCh.isDigit() ) { unicode += yyCh.digitValue(); } else { int sub(yyCh.toLower().toAscii() - 87); if( sub > 15 || sub < 10) { qFatal( "%s:%d: Invalid Unicode", (const char *) yyFileName, yyLineNo ); } unicode += sub; } yyCh = getChar(); } yyString.append(QChar(unicode)); } else if ( yyCh == '\n' ) { yyCh = getChar(); } else { yyString.append( backTab[strchr( tab, yyCh.toAscii() ) - tab] ); yyCh = getChar(); } } else { yyString.append(yyCh); yyCh = getChar(); } } if ( yyCh != '"' ) qFatal( "%s:%d: Unterminated string", (const char *) yyFileName, yyLineNo ); yyCh = getChar(); return Tok_String; case ':': yyCh = getChar(); return Tok_Colon; case '\'': yyCh = getChar(); if ( yyCh == '\\' ) yyCh = getChar(); do { yyCh = getChar(); } while ( yyCh != 0 && yyCh != '\'' ); yyCh = getChar(); break; case '{': yyCh = getChar(); return Tok_LeftBrace; case '}': 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_Dot; case ';': yyCh = getChar(); return Tok_Semicolon; case '+': yyCh = getChar(); if( yyCh == '+' ){ yyCh = getChar(); return Tok_PlusPlus; } if( yyCh == '=' ){ yyCh = getChar(); return Tok_PlusEq; }
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?