diff options
author | toma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2009-11-25 17:56:58 +0000 |
---|---|---|
committer | toma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2009-11-25 17:56:58 +0000 |
commit | bd9e6617827818fd043452c08c606f07b78014a0 (patch) | |
tree | 425bb4c3168f9c02f10150f235d2cb998dcc6108 /poxml/parser.h | |
download | tdesdk-bd9e6617827818fd043452c08c606f07b78014a0.tar.gz tdesdk-bd9e6617827818fd043452c08c606f07b78014a0.zip |
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
Diffstat (limited to 'poxml/parser.h')
-rw-r--r-- | poxml/parser.h | 124 |
1 files changed, 124 insertions, 0 deletions
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 <qxml.h> +#include <qmap.h> +#include <qregexp.h> + +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<BlockInfo> 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<QString, int> anchors; + int current; +}; + +class MsgList : public QValueList<MsgBlock> +{ +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 |