KDevelop API Documentation

directorystatusmessagefilter.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (C) 1999-2001 by Bernd Gehrmann and the KDevelop Team       *
00003  *   bernd@kdevelop.org                                                    *
00004  *                                                                         *
00005  *   This program is free software; you can redistribute it and/or modify  *
00006  *   it under the terms of the GNU General Public License as published by  *
00007  *   the Free Software Foundation; either version 2 of the License, or     *
00008  *   (at your option) any later version.                                   *
00009  *                                                                         *
00010  ***************************************************************************/
00011 
00012 #include "directorystatusmessagefilter.h"
00013 #include "directorystatusmessagefilter.moc"
00014 #include "makeitem.h"
00015 
00016 #include <qregexp.h>
00017 #include <kdebug.h>
00018 
00019 DirectoryStatusMessageFilter::DirectoryStatusMessageFilter( OutputFilter& next )
00020     : OutputFilter( next )
00021 {
00022 }
00023 
00024 void DirectoryStatusMessageFilter::processLine( const QString& line )
00025 {
00026         QString dir;
00027     if ( matchEnterDir( line, dir ) )
00028     {
00029         emit item( new EnteringDirectoryItem( dir, line ) );
00030     }
00031     else if ( matchLeaveDir( line, dir ) )
00032     {
00033         emit item( new ExitingDirectoryItem( dir, line ) );
00034     }
00035     else
00036     {
00037         OutputFilter::processLine( line );
00038     }
00039 }
00040 
00041 // simple helper function - checks whether we entered a new directory
00042 // (locale and Utf8 aware)
00043 bool DirectoryStatusMessageFilter::matchEnterDir( const QString& line, QString& dir )
00044 {
00045     // make outputs localised strings in Utf8 for entering/leaving directories...
00046     static const unsigned short fr_enter[] =
00047         {'E','n','t','r','e',' ','d','a','n','s',' ','l','e',' ','r',0xe9,'p','e','r','t','o','i','r','e'
00048         };
00049     static const unsigned short pl_enter[] =
00050         {'W','c','h','o','d','z',0x119,' ','k','a','t','a','l','o','g'
00051         };
00052     static const unsigned short ja_enter[] =
00053         {
00054             0x5165,0x308a,0x307e,0x3059,0x20,0x30c7,0x30a3,0x30ec,0x30af,0x30c8,0x30ea
00055         };
00056     static const unsigned short ko_enter[] =
00057         {
00058             0xb4e4,0xc5b4,0xac10
00059         };
00060     static const unsigned short ko_behind[] =
00061         {
00062             0x20,0xb514,0xb809,0xd1a0,0xb9ac
00063         };
00064     static const unsigned short pt_br_enter[] =
00065         {
00066             0x45,0x6e,0x74,0x72,0x61,0x6e,0x64,0x6f,0x20,0x6e,0x6f,0x20,0x64,0x69,0x72,0x65,0x74,0xf3,0x72,0x69,0x6f
00067         };
00068     static const unsigned short ru_enter[] =
00069         {
00070             0x412,0x445,0x43e,0x434,0x20,0x432,0x20,0x43a,0x430,0x442,0x430,0x43b,0x43e,0x433
00071         };
00072 
00073     static const QString fr_e( (const QChar*)fr_enter, sizeof(fr_enter) / 2 );
00074     static const QString pl_e( (const QChar*)pl_enter, sizeof(pl_enter) / 2 );
00075     static const QString ja_e( (const QChar*)ja_enter, sizeof(ja_enter) / 2 );
00076     static const QString ko_e( (const QChar*)ko_enter, sizeof(ko_enter) / 2 );
00077     static const QString ko_b( (const QChar*)ko_behind, sizeof(ko_behind) / 2 );
00078     static const QString pt_br_e( (const QChar*)pt_br_enter, sizeof(pt_br_enter) / 2 );
00079     static const QString ru_e( (const QChar*)ru_enter, sizeof(ru_enter) / 2 );
00080     static const QString en_e("Entering directory");
00081     static const QString de_e1("Wechsel in das Verzeichnis Verzeichnis");
00082     static const QString de_e2("Wechsel in das Verzeichnis");
00083     static const QString es_e("Cambiando a directorio");
00084     static const QString nl_e("Binnengaan van directory");
00085     //@todo: other translations!
00086     
00087     // we need a QRegExp because KRegExp is not Utf8 aware.
00088     // 0x00AB is LEFT-POINTING DOUBLE ANGLE QUOTATION MARK
00089     // 0X00BB is RIGHT-POINTING DOUBLE ANGLE QUOTATION MARK
00090     static QRegExp dirChange(QString::fromLatin1(".*: (.+) (`|") + QChar(0x00BB) + QString::fromLatin1(")(.*)('|") + QChar(0x00AB) + QString::fromLatin1(")(.*)"));
00091     static QRegExp enEnter(QString::fromLatin1(".*: Entering directory"));
00092     kdDebug(9004) << "Directory filter line " << line << endl;
00093 
00094     // avoid QRegExp if possible. This regex performs VERY badly with large inputs,
00095     // and the input required is very short if these strings match.
00096     if(line.find(en_e) > -1 ||
00097        line.find(fr_e) > -1 ||
00098        line.find(pl_e) > -1 ||
00099        line.find(ja_e) > -1 ||
00100        line.find(ko_e) > -1 ||
00101        line.find(ko_b) > -1 ||
00102        line.find(pt_br_e) > -1 ||
00103        line.find(ru_e) > -1 ||
00104        line.find(de_e1) > -1 ||
00105        line.find(de_e2) > -1 ||
00106        line.find(es_e) > -1 ||
00107        line.find(nl_e) > -1)
00108     {
00109         // grab the directory name
00110         if(dirChange.search(line) > -1)
00111         {
00112             dir = dirChange.cap(3);
00113             return true;
00114         }
00115     }
00116     return false;
00117 }
00118 
00119 // simple helper function - checks whether we left a directory
00120 // (locale and Utf8 aware).
00121 bool DirectoryStatusMessageFilter::matchLeaveDir( const QString& line, QString& dir )
00122 {
00123     static const unsigned short fr_leave[] =
00124         { 'Q','u','i','t','t','e',' ','l','e',' ','r',0xe9,'p','e','r','t','o','i','r','e'
00125         };
00126     static const unsigned short ja_leave[] =
00127         {
00128             0x51fa,0x307e,0x3059,0x20,0x30c7,0x30a3,0x30ec,0x30af,0x30c8,0x30ea
00129         };
00130     static const unsigned short pt_br_leave[] =
00131         {'S','a','i','n','d','o',' ','d','o',' ','d','i','r','e','t',0xf3,'r','i','o'
00132         };
00133     static const unsigned short ru_leave[] =
00134         {
00135             0x412,0x44b,0x445,0x43e,0x434,0x20,0x438,0x437,0x20,0x43a,0x430,0x442,0x430,0x43b,0x43e,0x433
00136         };
00137     static const unsigned short ko_leave[] =
00138         {
00139             0xb098,0xac10
00140         };
00141     static const unsigned short ko_behind[] =
00142         {
00143             0x20,0xb514,0xb809,0xd1a0,0xb9ac
00144         };
00145 
00146     static const QString fr_l( (const QChar*)fr_leave, sizeof(fr_leave) / 2 );
00147     static const QString ja_l( (const QChar*)ja_leave, sizeof(ja_leave) / 2 );
00148     static const QString ko_l( (const QChar*)ko_leave, sizeof(ko_leave) / 2 );
00149     static const QString ko_b( (const QChar*)ko_behind, sizeof(ko_behind) / 2 );
00150     static const QString pt_br_l( (const QChar*)pt_br_leave, sizeof(pt_br_leave) / 2 );
00151     static const QString ru_l( (const QChar*)ru_leave, sizeof(ru_leave) / 2 );
00152     static const QString en_l("Leaving directory");
00153     static const QString de_l1("Verlassen des Verzeichnisses Verzeichnis");
00154     static const QString de_l2("Verlassen des Verzeichnisses");
00155     static const QString es_l("Saliendo directorio");
00156     static const QString nl_l("Verdwijnen uit directory");
00157     static const QString po_l("Opuszczam katalog");
00158     
00159     // we need a QRegExp because KRegExp is not Utf8 aware.
00160     // 0x00AB is LEFT-POINTING DOUBLE ANGLE QUOTATION MARK
00161     // 0X00BB is RIGHT-POINTING DOUBLE ANGLE QUOTATION MARK
00162 
00163     static QRegExp dirChange(QString::fromLatin1(".*: (.+) (`|") + QChar(0x00BB) + QString::fromLatin1(")(.*)('|") + QChar(0x00AB) + QString::fromLatin1(")(.*)"));
00164 
00165     // avoid QRegExp if possible. This regex performs VERY badly with large inputs,
00166     // and the input required is very short if these strings match.
00167     if(line.find(en_l) > -1 ||
00168        line.find(fr_l) > -1 ||
00169        line.find(ja_l) > -1 ||
00170        (line.find(ko_l) > -1 && line.find(ko_b) > -1) ||
00171        line.find(pt_br_l) > -1 ||
00172        line.find(ru_l) > -1 ||
00173        line.find(de_l1) > -1 ||
00174        line.find(de_l2) > -1 ||
00175        line.find(es_l) > -1 ||
00176        line.find(nl_l) > -1 ||
00177        line.find(po_l) > -1)
00178     {
00179         // grab the directory name
00180         if(dirChange.search(line) > -1 )
00181         {
00182             dir = dirChange.cap(3);
00183             return true;            
00184         }
00185     }
00186     return false;
00187 }
KDE Logo
This file is part of the documentation for KDevelop Version 3.1.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Tue Feb 22 09:22:41 2005 by doxygen 1.3.9.1 written by Dimitri van Heesch, © 1997-2003