From bd9e6617827818fd043452c08c606f07b78014a0 Mon Sep 17 00:00:00 2001 From: toma Date: Wed, 25 Nov 2009 17:56:58 +0000 Subject: Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features. BUG:215923 git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdesdk@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da --- poxml/parser.h | 124 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 124 insertions(+) create mode 100644 poxml/parser.h (limited to 'poxml/parser.h') diff --git a/poxml/parser.h b/poxml/parser.h new file mode 100644 index 00000000..f63f6cef --- /dev/null +++ b/poxml/parser.h @@ -0,0 +1,124 @@ +#ifndef PARSER_H +#define PARSER_H + +#include +#include +#include + +struct BlockInfo { + int start_line; + int start_col; + int end_line; + int end_col; + + // used to detect sub-messages + int offset; + + BlockInfo() { + start_line = 0; + start_col = 0; + end_line = 0; + end_col = 0; + + // used to detect sub-messages + offset = 0; + } +}; + +class MsgBlock { + public: + MsgBlock() { start = end = 0; do_not_split = false; } + MsgBlock(const MsgBlock &rhs ) { + *this = rhs; + } + QValueList lines; + QString tag; + QString comment; + QString msgid; + QString msgid_plural; + QString msgstr; + QStringList msgstr_plurals; + int start, end; + bool do_not_split; + + void operator=(const MsgBlock& rhs) { + lines = rhs.lines; + tag = rhs.tag; + comment = rhs.comment; + msgid = rhs.msgid; + msgid_plural = rhs.msgid_plural; + msgstr = rhs.msgstr; + msgstr_plurals = rhs.msgstr_plurals; + start = rhs.start; + end = rhs.end; + do_not_split = rhs.do_not_split; + } +}; + +class ParaCounter +{ +public: + ParaCounter() { current = 0; } + void addAnchor(QString anchor) { anchors.insert(anchor, current); } + void increasePara() { current++; } + + QMap anchors; + int current; +}; + +class MsgList : public QValueList +{ +public: + MsgList() {} + ParaCounter pc; +}; + +class StructureParser : public QXmlDefaultHandler +{ +public: + bool startDocument(); + bool startElement( const QString&, const QString&, const QString& , + const QXmlAttributes& ); + bool endElement( const QString&, const QString&, const QString& ); + bool characters( const QString &ch); + static bool isCuttingTag(const QString &tag); + static bool isSingleTag(const QString &qName); + static bool isLiteralTag(const QString &qName); + void setDocumentLocator ( QXmlLocator * l ) { locator = l; } + bool skippedEntity ( const QString & name ); + bool fatalError ( const QXmlParseException & ); + bool comment ( const QString & ); + bool error(const QXmlParseException &e ) { return fatalError(e); } + bool warning(const QXmlParseException &e ) { return fatalError(e); } + MsgList getList() const { return list; } + MsgList splitMessage(const MsgBlock &message); + + virtual bool startCDATA(); + virtual bool endCDATA(); + + static bool closureTag(const QString& message, const QString &tag); + static bool isClosure(const QString &message); + static void descape(QString &message); + static QString escapeLiterals( const QString &contents); + static QString descapeLiterals( const QString &contents); + static void cleanupTags( QString &contents ); + static void removeEmptyTags( QString &contents); + static void stripWhiteSpace( QString &contents); + +private: + bool formatMessage(MsgBlock &message) const; + + QXmlLocator *locator; + QString message; + int inside, startline, startcol; + int line; + MsgList list; + mutable QRegExp infos_reg; + mutable QRegExp do_not_split_reg; +}; + +void outputMsg(const char *prefix, const QString &message); +MsgList parseXML(const char *filename); +QString escapePO(QString msgid); + +#endif -- cgit v1.2.1