[ Index ] |
|
Code source de eZ Publish 3.9.0 |
1 /********************************************************************** 2 ** Copyright (C) 2000 Trolltech AS. All rights reserved. 3 ** 4 ** proparser.cpp 5 ** 6 ** This file is part of Qt Linguist. 7 ** 8 ** See the file LICENSE included in the distribution for the usage 9 ** and distribution terms. 10 ** 11 ** The file is provided AS IS with NO WARRANTY OF ANY KIND, 12 ** INCLUDING THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR 13 ** A PARTICULAR PURPOSE. 14 ** 15 **********************************************************************/ 16 17 #include <qregexp.h> 18 #include <qstringlist.h> 19 20 #include "proparser.h" 21 22 QMap<QString, QString> proFileTagMap( const QString& text ) 23 { 24 QString t = text; 25 26 /* 27 Strip comments, merge lines ending with backslash, add 28 spaces around '=' and '+=', replace '\n' with ';', and 29 simplify white spaces. 30 */ 31 t.replace( QRegExp(QString("#[^\n]$")), QString(" ") ); 32 t.replace( QRegExp(QString("\\\\\\s*\n")), QString(" ") ); 33 t.replace( QRegExp(QString("=")), QString(" = ") ); 34 t.replace( QRegExp(QString("\\+ =")), QString(" += ") ); 35 t.replace( QRegExp(QString("\n")), QString(";") ); 36 t = t.simplifyWhiteSpace(); 37 38 QMap<QString, QString> tagMap; 39 40 QStringList lines = QStringList::split( QChar(';'), t ); 41 QStringList::Iterator line; 42 for ( line = lines.begin(); line != lines.end(); ++line ) { 43 QStringList toks = QStringList::split( QChar(' '), *line ); 44 45 if ( toks.count() >= 3 && 46 (toks[1] == QString("=") || toks[1] == QString("+=")) ) { 47 QString tag = toks.first(); 48 int k = tag.findRev( QChar(':') ); // as in 'unix:' 49 if ( k != -1 ) 50 tag = tag.mid( k + 1 ); 51 toks.remove( toks.begin() ); 52 53 QString action = toks.first(); 54 toks.remove( toks.begin() ); 55 56 if ( tagMap.contains(tag) ) { 57 if ( action == QString("=") ) 58 tagMap.replace( tag, toks.join(QChar(' ')) ); 59 else 60 tagMap[tag] += QChar( ' ' ) + toks.join( QChar(' ') ); 61 } else { 62 tagMap[tag] = toks.join( QChar(' ') ); 63 } 64 } 65 } 66 67 QRegExp var( "\\$\\$[a-zA-Z0-9_]+" ); 68 QMap<QString, QString>::Iterator it; 69 for ( it = tagMap.begin(); it != tagMap.end(); ++it ) { 70 int i = 0; 71 72 while ( (i = var.search(it.data(), i)) != -1 ) { 73 int len = var.matchedLength(); 74 (*it).replace( i, len, tagMap[(*it).mid(i + 2, len - 2)] ); 75 } 76 } 77 return tagMap; 78 }
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Sat Feb 24 10:30:04 2007 | par Balluche grâce à PHPXref 0.7 |