diff options
Diffstat (limited to 'poxml/parser.cpp')
-rw-r--r-- | poxml/parser.cpp | 214 |
1 files changed, 107 insertions, 107 deletions
diff --git a/poxml/parser.cpp b/poxml/parser.cpp index c34976bf..2f0f7e16 100644 --- a/poxml/parser.cpp +++ b/poxml/parser.cpp @@ -4,7 +4,7 @@ #include <iostream> #include <stdlib.h> #include <assert.h> -#include <qregexp.h> +#include <tqregexp.h> using namespace std; @@ -47,7 +47,7 @@ static const char *cuttingtags[] = {"bridgehead", "trans_comment", "para", "titl static const char *literaltags[] = {"literallayout", "synopsis", "screen", "programlisting", 0}; -bool StructureParser::fatalError ( const QXmlParseException &e ) +bool StructureParser::fatalError ( const TQXmlParseException &e ) { cerr << "fatalError " << e.message().latin1() << " " << e.lineNumber() << " " << e.columnNumber() << endl; @@ -56,14 +56,14 @@ bool StructureParser::fatalError ( const QXmlParseException &e ) bool StructureParser::startDocument() { - infos_reg = QRegExp("\\s*poxml_line=\"(\\d+)\" poxml_col=\"(\\d+)\""); - do_not_split_reg = QRegExp("\\s*condition=\"do-not-split\""); + infos_reg = TQRegExp("\\s*poxml_line=\"(\\d+)\" poxml_col=\"(\\d+)\""); + do_not_split_reg = TQRegExp("\\s*condition=\"do-not-split\""); message = ""; inside = 0; return true; } -bool StructureParser::isCuttingTag(const QString &qName) +bool StructureParser::isCuttingTag(const TQString &qName) { int index = 0; while (cuttingtags[index]) { @@ -74,7 +74,7 @@ bool StructureParser::isCuttingTag(const QString &qName) return isLiteralTag(qName); } -bool StructureParser::isSingleTag(const QString &qName) +bool StructureParser::isSingleTag(const TQString &qName) { int index = 0; while (singletags[index]) { @@ -85,7 +85,7 @@ bool StructureParser::isSingleTag(const QString &qName) return false; } -bool StructureParser::isLiteralTag(const QString &qName) +bool StructureParser::isLiteralTag(const TQString &qName) { int index = 0; while (literaltags[index]) { @@ -96,24 +96,24 @@ bool StructureParser::isLiteralTag(const QString &qName) return false; } -bool StructureParser::skippedEntity ( const QString & name ) +bool StructureParser::skippedEntity ( const TQString & name ) { if (inside) - message += QString("&%1;").arg(name); + message += TQString("&%1;").arg(name); return true; } -bool StructureParser::startElement( const QString& , const QString& , - const QString& qName, - const QXmlAttributes & attr ) +bool StructureParser::startElement( const TQString& , const TQString& , + const TQString& qName, + const TQXmlAttributes & attr ) { - QString tname = qName.lower(); + TQString tname = qName.lower(); bool first = false; if (isCuttingTag(tname)) { if (!inside) { - message = QString::null; + message = TQString::null; list.pc.increasePara(); startline = locator->lineNumber(); startcol = locator->columnNumber(); @@ -124,12 +124,12 @@ bool StructureParser::startElement( const QString& , const QString& , if (inside) { - QString tmp = "<" + tname; + TQString tmp = "<" + tname; for (int i = 0; i < attr.length(); i++) { - tmp += QString(" %1=\"%2\"").arg(attr.qName(i)).arg(attr.value(i)); + tmp += TQString(" %1=\"%2\"").arg(attr.qName(i)).arg(attr.value(i)); } - tmp += QString(" poxml_line=\"%1\"").arg(locator->lineNumber()); - tmp += QString(" poxml_col=\"%1\"").arg(locator->columnNumber()); + tmp += TQString(" poxml_line=\"%1\"").arg(locator->lineNumber()); + tmp += TQString(" poxml_col=\"%1\"").arg(locator->columnNumber()); if (isSingleTag(qName)) tmp += "/>"; @@ -160,17 +160,17 @@ bool StructureParser::endCDATA() return true; } -bool StructureParser::isClosure(const QString &message) +bool StructureParser::isClosure(const TQString &message) { assert(message.at(0) == '<'); int endindex = 1; while (!message.at(endindex).isSpace() && message.at(endindex) != '>') endindex++; - QString tag = message.mid(1, endindex - 1); + TQString tag = message.mid(1, endindex - 1); return closureTag(message, tag); } -bool StructureParser::closureTag(const QString& message, const QString &tag) +bool StructureParser::closureTag(const TQString& message, const TQString &tag) { #ifdef POXML_DEBUG qDebug("closureTag %s %s", message.latin1(), tag.latin1()); @@ -180,8 +180,8 @@ bool StructureParser::closureTag(const QString& message, const QString &tag) uint index = 0; while (true) { - int nextclose = message.find(QRegExp(QString::fromLatin1("</%1[\\s>]").arg(tag)), index); - int nextstart = message.find(QRegExp(QString::fromLatin1("<%1[>\\s]").arg(tag)), index); + int nextclose = message.find(TQRegExp(TQString::fromLatin1("</%1[\\s>]").arg(tag)), index); + int nextstart = message.find(TQRegExp(TQString::fromLatin1("<%1[>\\s]").arg(tag)), index); // qDebug("finding %d %d %d %d", nextstart, nextclose, index, inside); if (nextclose == -1) { #ifdef POXML_DEBUG @@ -214,7 +214,7 @@ bool StructureParser::closureTag(const QString& message, const QString &tag) } } -void StructureParser::descape(QString &message) +void StructureParser::descape(TQString &message) { uint index = 0; stripWhiteSpace( message ); @@ -239,7 +239,7 @@ void StructureParser::descape(QString &message) while (endindex < message.length() && !message.at(endindex).isSpace() && message.at(endindex) != '>') endindex++; - QString tag = message.mid(index + 1, endindex - index - 1); + TQString tag = message.mid(index + 1, endindex - index - 1); if (tag.at(0) == '/') { if (isLiteralTag(tag.mid(1))) inside--; @@ -254,7 +254,7 @@ void StructureParser::descape(QString &message) index++; } - message.replace(QRegExp("\010"), ""); + message.replace(TQRegExp("\010"), ""); } bool StructureParser::formatMessage(MsgBlock &msg) const @@ -278,7 +278,7 @@ bool StructureParser::formatMessage(MsgBlock &msg) const { int slen = strlen(singletags[index]); - if (msg.msgid.left(slen + 1) == QString::fromLatin1("<%1").arg(singletags[index]) && + if (msg.msgid.left(slen + 1) == TQString::fromLatin1("<%1").arg(singletags[index]) && !msg.msgid.at( slen + 1 ).isLetterOrNumber() ) { #ifdef POXML_DEBUG @@ -316,7 +316,7 @@ bool StructureParser::formatMessage(MsgBlock &msg) const int strindex = 1; while (msg.msgid.at(strindex) != ' ' && msg.msgid.at(strindex) != '>') strindex++; - QString starttag = msg.msgid.mid(1, strindex - 1); + TQString starttag = msg.msgid.mid(1, strindex - 1); int endindex = msg.msgid.length() - 2; while (msg.msgid.at(endindex) != '<' && msg.msgid.at(endindex + 1) != '/') endindex--; @@ -324,10 +324,10 @@ bool StructureParser::formatMessage(MsgBlock &msg) const qDebug("endIndex %d", endindex); #endif strindex = endindex; - QString orig = msg.msgid; + TQString orig = msg.msgid; - QString endtag = msg.msgid.mid(endindex + 2, msg.msgid.length() - (endindex + 2) - 1); - QString endtag_attr = endtag.mid(endtag.find(' '), endtag.length()); + TQString endtag = msg.msgid.mid(endindex + 2, msg.msgid.length() - (endindex + 2) - 1); + TQString endtag_attr = endtag.mid(endtag.find(' '), endtag.length()); endtag.replace(infos_reg, ""); if (endtag == starttag) { if (!closureTag(msg.msgid, starttag)) @@ -338,7 +338,7 @@ bool StructureParser::formatMessage(MsgBlock &msg) const strindex = 0; while (msg.msgid.at(strindex) != '>') strindex++; - QString attr = msg.msgid.left(strindex); + TQString attr = msg.msgid.left(strindex); msg.msgid = msg.msgid.mid(strindex + 1); offset += strindex + 1; for (int index = 0; msg.msgid.at(index) == ' '; index++, offset++) ; @@ -389,7 +389,7 @@ MsgList StructureParser::splitMessage(const MsgBlock &mb) MsgBlock msg1 = mb; MsgBlock msg2 = mb; - QString message = mb.msgid; + TQString message = mb.msgid; #ifdef POXML_DEBUG qDebug("splitMessage %s", message.latin1()); @@ -399,7 +399,7 @@ MsgList StructureParser::splitMessage(const MsgBlock &mb) int endindex = 1; while (!message.at(endindex).isSpace() && message.at(endindex) != '>') endindex++; - QString tag = message.mid(1, endindex - 1); + TQString tag = message.mid(1, endindex - 1); if (closureTag(message, tag)) goto error; @@ -418,9 +418,9 @@ MsgList StructureParser::splitMessage(const MsgBlock &mb) #endif // the exception for poxml_* attributes is made in the closing tag - int closing_index = message.find(QRegExp(QString::fromLatin1("</%1[\\s>]").arg(tag)), + int closing_index = message.find(TQRegExp(TQString::fromLatin1("</%1[\\s>]").arg(tag)), strindex); - int starting_index = message.find(QRegExp(QString::fromLatin1("<%1[\\s>]").arg(tag)), + int starting_index = message.find(TQRegExp(TQString::fromLatin1("<%1[\\s>]").arg(tag)), strindex); #ifdef POXML_DEBUG @@ -509,7 +509,7 @@ MsgList StructureParser::splitMessage(const MsgBlock &mb) int endindex = message.length() - 1; while (endindex >= 0 && (message.at(endindex) != '<' || message.at(endindex + 1) != '/')) endindex--; - QString tag = message.mid(endindex + 2, message.length() - endindex - 3); + TQString tag = message.mid(endindex + 2, message.length() - endindex - 3); if (tag.find(' ') > 0 ) { tag = tag.left(tag.find(' ')); } @@ -529,9 +529,9 @@ MsgList StructureParser::splitMessage(const MsgBlock &mb) qDebug("inside %s %d", message.mid(strindex, 35).latin1(), inside); #endif - int closing_index = message.findRev(QRegExp(QString::fromLatin1("</%1[\\s>]").arg(tag)), + int closing_index = message.findRev(TQRegExp(TQString::fromLatin1("</%1[\\s>]").arg(tag)), strindex - 1); - int starting_index = message.findRev(QRegExp(QString::fromLatin1("<%1[\\s>]").arg(tag)), + int starting_index = message.findRev(TQRegExp(TQString::fromLatin1("<%1[\\s>]").arg(tag)), strindex - 1); #ifdef POXML_DEBUG @@ -593,17 +593,17 @@ error: return result; } -bool StructureParser::endElement( const QString& , const QString&, const QString& qName) +bool StructureParser::endElement( const TQString& , const TQString&, const TQString& qName) { - QString tname = qName.lower(); + TQString tname = qName.lower(); // qDebug("endElement %s - %s %d", tname.latin1(), message.latin1(), inside); if (inside) { if (!isSingleTag(qName)) { - message += QString("</%1").arg(tname); - message += QString(" poxml_line=\"%1\"").arg(locator->lineNumber()); - message += QString(" poxml_col=\"%1\"").arg(locator->columnNumber()); + message += TQString("</%1").arg(tname); + message += TQString(" poxml_line=\"%1\"").arg(locator->lineNumber()); + message += TQString(" poxml_col=\"%1\"").arg(locator->columnNumber()); message += ">"; } } @@ -640,7 +640,7 @@ bool StructureParser::endElement( const QString& , const QString&, const QString (*it).lines.first().offset = 0; } } - (*it).msgid.replace(infos_reg, QString::null); + (*it).msgid.replace(infos_reg, TQString::null); if (!(*it).msgid.isEmpty()) list.append(*it); @@ -651,7 +651,7 @@ bool StructureParser::endElement( const QString& , const QString&, const QString return true; } -bool StructureParser::comment ( const QString &c ) +bool StructureParser::comment ( const TQString &c ) { if (c.left(7) != " TRANS:") return true; @@ -660,30 +660,30 @@ bool StructureParser::comment ( const QString &c ) return true; } -QString StructureParser::escapeLiterals( const QString &_contents) { - QString contents = _contents; +TQString StructureParser::escapeLiterals( const TQString &_contents) { + TQString contents = _contents; - contents.replace(QRegExp("\n"), "&POXML_LINEFEED;"); - contents.replace(QRegExp("<"), "&POXML_LT;"); - contents.replace(QRegExp(">"), "&POXML_GT;"); - contents.replace(QRegExp("\t"), " "); - contents.replace(QRegExp(" "), "&POXML_SPACE;"); + contents.replace(TQRegExp("\n"), "&POXML_LINEFEED;"); + contents.replace(TQRegExp("<"), "&POXML_LT;"); + contents.replace(TQRegExp(">"), "&POXML_GT;"); + contents.replace(TQRegExp("\t"), " "); + contents.replace(TQRegExp(" "), "&POXML_SPACE;"); return contents; } -QString StructureParser::descapeLiterals( const QString &_contents) { - QString contents = _contents; +TQString StructureParser::descapeLiterals( const TQString &_contents) { + TQString contents = _contents; - contents.replace(QRegExp("&POXML_LINEFEED;"), "\n"); - contents.replace(QRegExp("&POXML_LT;"), "<"); - contents.replace(QRegExp("&POXML_GT;"), ">"); - contents.replace(QRegExp("&POXML_SPACE;"), " "); - contents.replace(QRegExp("!POXML_AMP!"), "&"); + contents.replace(TQRegExp("&POXML_LINEFEED;"), "\n"); + contents.replace(TQRegExp("&POXML_LT;"), "<"); + contents.replace(TQRegExp("&POXML_GT;"), ">"); + contents.replace(TQRegExp("&POXML_SPACE;"), " "); + contents.replace(TQRegExp("!POXML_AMP!"), "&"); return contents; } -void StructureParser::stripWhiteSpace( QString &contents) +void StructureParser::stripWhiteSpace( TQString &contents) { contents = contents.stripWhiteSpace(); bool changed; @@ -708,13 +708,13 @@ void StructureParser::stripWhiteSpace( QString &contents) } while (changed); } -void StructureParser::cleanupTags( QString &contents ) +void StructureParser::cleanupTags( TQString &contents ) { - contents.replace(QRegExp("&"), "!POXML_AMP!"); + contents.replace(TQRegExp("&"), "!POXML_AMP!"); for (int index = 0; literaltags[index]; index++) { - QRegExp start(QString("<%1[\\s>]").arg(literaltags[index])); - QRegExp end(QString("</%1[\\s>]").arg(literaltags[index])); + TQRegExp start(TQString("<%1[\\s>]").arg(literaltags[index])); + TQRegExp end(TQString("</%1[\\s>]").arg(literaltags[index])); int strindex = 0; while (true) { strindex = contents.find(start, strindex); @@ -724,25 +724,25 @@ void StructureParser::cleanupTags( QString &contents ) strindex++; strindex++; // one more int endindex = contents.find(end, strindex); - QString part = contents.mid(strindex, endindex - strindex); - QString newpart = escapeLiterals(part); + TQString part = contents.mid(strindex, endindex - strindex); + TQString newpart = escapeLiterals(part); contents.replace(strindex, part.length(), newpart); // this assumes that literal tags to not overlap strindex = strindex + newpart.length(); } } - QRegExp unclosed("</(\\w*)\\s\\s*>"); + TQRegExp unclosed("</(\\w*)\\s\\s*>"); int index = -1; while (true) { index = unclosed.search(contents, index + 1); if (index < 0) break; - QString tag = unclosed.cap(1); - contents.replace(index, unclosed.matchedLength(), QString("</%1>").arg(tag)); + TQString tag = unclosed.cap(1); + contents.replace(index, unclosed.matchedLength(), TQString("</%1>").arg(tag)); } - QRegExp start("<((\\s*[^<>\\s])*)\\s\\s*(/*)>"); + TQRegExp start("<((\\s*[^<>\\s])*)\\s\\s*(/*)>"); start.setMinimal(true); index = -1; @@ -750,32 +750,32 @@ void StructureParser::cleanupTags( QString &contents ) index = start.search(contents, index + 1); if (index < 0) break; - QString tag = start.cap(1); - QString cut = start.capturedTexts().last(); + TQString tag = start.cap(1); + TQString cut = start.capturedTexts().last(); // qDebug("UNCLO %s %d -%s- -%s-", start.cap(0).latin1(), index, tag.latin1(), cut.latin1()); - contents.replace(index, start.matchedLength(), QString("<%1%2>").arg(tag).arg(cut)); + contents.replace(index, start.matchedLength(), TQString("<%1%2>").arg(tag).arg(cut)); } - QRegExp singletag("<(\\w*)\\s([^><]*)/>"); + TQRegExp singletag("<(\\w*)\\s([^><]*)/>"); index = -1; while (true) { index = singletag.search(contents, index + 1); if (index < 0) break; - QString tag = singletag.cap(1); + TQString tag = singletag.cap(1); if (!StructureParser::isSingleTag(tag)) { - contents.replace(index, singletag.matchedLength(), QString("<%1 %2></%3>").arg(tag).arg(singletag.cap(2)).arg(tag)); + contents.replace(index, singletag.matchedLength(), TQString("<%1 %2></%3>").arg(tag).arg(singletag.cap(2)).arg(tag)); } } - QRegExp trans_comment("<!-- TRANS:([^<>]*)-->"); + TQRegExp trans_comment("<!-- TRANS:([^<>]*)-->"); index = -1; while (true) { index = trans_comment.search(contents, index + 1); if (index < 0) break; - QString msgid = trans_comment.cap(1); - contents.replace(index, trans_comment.matchedLength(), QString("<trans_comment>%1</trans_comment>").arg(msgid)); + TQString msgid = trans_comment.cap(1); + contents.replace(index, trans_comment.matchedLength(), TQString("<trans_comment>%1</trans_comment>").arg(msgid)); } #ifdef POXML_DEBUG @@ -784,11 +784,11 @@ void StructureParser::cleanupTags( QString &contents ) } -static bool removeEmptyTag( QString &contents, const QString & tag) +static bool removeEmptyTag( TQString &contents, const TQString & tag) { // qDebug("cont %s %s", contents.latin1(), tag.latin1()); - QRegExp empty(QString("<%1[^>]*>[\\s\n][\\s\n]*</%2\\s*>").arg(tag).arg(tag)); + TQRegExp empty(TQString("<%1[^>]*>[\\s\n][\\s\n]*</%2\\s*>").arg(tag).arg(tag)); int strindex = 0; while (true) { strindex = contents.find(empty, strindex); @@ -802,7 +802,7 @@ static bool removeEmptyTag( QString &contents, const QString & tag) return false; } -void StructureParser::removeEmptyTags( QString &contents ) +void StructureParser::removeEmptyTags( TQString &contents ) { bool removed; do { @@ -822,24 +822,24 @@ void StructureParser::removeEmptyTags( QString &contents ) } while (removed); } -bool StructureParser::characters(const QString &ch) +bool StructureParser::characters(const TQString &ch) { if (inside && !ch.isEmpty()) message += ch; return true; } -QString escape(QString message) +TQString escape(TQString message) { - message.replace(QRegExp("\\\\"), "\\\\"); - message.replace(QRegExp("\""), "\\\""); + message.replace(TQRegExp("\\\\"), "\\\\"); + message.replace(TQRegExp("\""), "\\\""); return message; } -void outputMsg(const char *prefix, const QString &message) +void outputMsg(const char *prefix, const TQString &message) { - QStringList list = QStringList::split('\n', message, true); - QString line; + TQStringList list = TQStringList::split('\n', message, true); + TQString line; if (list.count() == 1) { line = list.first(); @@ -849,7 +849,7 @@ void outputMsg(const char *prefix, const QString &message) cout << prefix << " \"" << escape(line).utf8().data() << "\"\n"; } else { cout << prefix << " \"\"\n"; - for (QStringList::ConstIterator it = list.begin(); it != list.end(); it++) { + for (TQStringList::ConstIterator it = list.begin(); it != list.end(); it++) { line = *it; if (!line.isEmpty()) { cout << " \"" << escape(line).utf8().data(); @@ -867,7 +867,7 @@ void outputMsg(const char *prefix, const QString &message) } } -QString escapePO(QString msgid) +TQString escapePO(TQString msgid) { int index = 0; while (true) { @@ -909,8 +909,8 @@ QString escapePO(QString msgid) index += 1; } - msgid.replace(QRegExp("&POXML_LITERALLINEFEED;"), "\\n"); - msgid.replace(QRegExp("&POXML_LITERALQUOTE;"), "\\"); + msgid.replace(TQRegExp("&POXML_LITERALLINEFEED;"), "\\n"); + msgid.replace(TQRegExp("&POXML_LITERALQUOTE;"), "\\"); return msgid; } @@ -918,15 +918,15 @@ QString escapePO(QString msgid) MsgList parseXML(const char *filename) { StructureParser handler; - QFile xmlFile( filename ); + TQFile xmlFile( filename ); xmlFile.open(IO_ReadOnly); - QCString ccontents; + TQCString ccontents; ccontents.fill(0, xmlFile.size() + 1); memcpy(ccontents.data(), xmlFile.readAll().data(), xmlFile.size()); xmlFile.close(); - QString contents = QString::fromUtf8( ccontents ); + TQString contents = TQString::fromUtf8( ccontents ); StructureParser::cleanupTags(contents); while (true) { @@ -935,7 +935,7 @@ MsgList parseXML(const char *filename) break; int inside = 0; int endindex = index + 1; - QString replacement = ""; + TQString replacement = ""; while (contents.at(endindex) != '>' || inside) { switch (contents.at(endindex).latin1()) { @@ -955,9 +955,9 @@ MsgList parseXML(const char *filename) contents.replace(index, endindex - index, replacement); } - QTextStream ts(contents.utf8(), IO_ReadOnly); - QXmlInputSource source( ts ); - QXmlSimpleReader reader; + TQTextStream ts(contents.utf8(), IO_ReadOnly); + TQXmlInputSource source( ts ); + TQXmlSimpleReader reader; reader.setFeature( "http://trolltech.com/xml/features/report-start-end-entity", true); reader.setContentHandler( &handler ); reader.setLexicalHandler( &handler ); @@ -970,15 +970,15 @@ MsgList parseXML(const char *filename) do { changed = false; - QMap<QString, QString> msgids; + TQMap<TQString, TQString> msgids; for (MsgList::Iterator it = english.begin(); it != english.end(); it++) { - QMap<QString,QString>::Iterator found = msgids.find((*it).msgid); + TQMap<TQString,TQString>::Iterator found = msgids.find((*it).msgid); if ((*it).msgid.length() < 4) { - (*it).msgid = QString("<%1>").arg((*it).tag) + (*it).msgid + - QString("</%1>").arg((*it).tag); + (*it).msgid = TQString("<%1>").arg((*it).tag) + (*it).msgid + + TQString("</%1>").arg((*it).tag); changed = true; break; } @@ -988,12 +988,12 @@ MsgList parseXML(const char *filename) qDebug("same msgid for '%s' and '%s'", found.data().latin1(), (*it).tag.latin1()); #endif changed = true; - QString msgid = (*it).msgid; + TQString msgid = (*it).msgid; for (MsgList::Iterator it2 = english.begin(); it2 != english.end(); it2++) { if ((*it2).msgid == msgid) - (*it2).msgid = QString("<%1>").arg((*it2).tag) + msgid + QString("</%1>").arg((*it2).tag); + (*it2).msgid = TQString("<%1>").arg((*it2).tag) + msgid + TQString("</%1>").arg((*it2).tag); } break; } |