summaryrefslogtreecommitdiff
authoralwin <alwin>2004-10-24 00:50:03 (UTC)
committer alwin <alwin>2004-10-24 00:50:03 (UTC)
commite16312f45d5df483d21b02d03d5851bc34674f39 (patch) (side-by-side diff)
tree63920b8a2018910d1e25f08d3278b3eb59e889fb
parent9c5964f8d2be467aa53d3d8255b499890556e320 (diff)
downloadopie-e16312f45d5df483d21b02d03d5851bc34674f39.zip
opie-e16312f45d5df483d21b02d03d5851bc34674f39.tar.gz
opie-e16312f45d5df483d21b02d03d5851bc34674f39.tar.bz2
a small helperclass ValueExplode inserted
it splits a string like a=4&b=2&c=1 into it key - value - pairs the runtime-example in constructor of OpieMail should be removed ;)
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/mail/opiemail.cpp87
1 files changed, 86 insertions, 1 deletions
diff --git a/noncore/net/mail/opiemail.cpp b/noncore/net/mail/opiemail.cpp
index b153292..5654476 100644
--- a/noncore/net/mail/opiemail.cpp
+++ b/noncore/net/mail/opiemail.cpp
@@ -18,4 +18,6 @@
/* QT */
+#include <qmap.h>
+#include <qvaluelist.h>
/* UNIX */
@@ -24,4 +26,81 @@
using namespace Opie::Core;
+typedef QMapNode<QString,QString> tkeyvalues;
+typedef QValueList<tkeyvalues> tvaluelist;
+
+class ValueExplode
+{
+protected:
+ //! what was parsed last
+ tvaluelist m_LastParsed;
+ //! the delemiter to use
+ QString mDelemiter;
+ //! the inner delemiter
+ QString m2Delemiter;
+ //! the real split routine
+ void splitit();
+ //! the content
+ QString m_Command;
+ //! constructor
+ ValueExplode(){}
+public:
+ //! constructor
+ /*!
+ * \param aCommand the string to be splitted
+ * \param aDelemiter which sign will be the delemiter character
+ * \param a2Delemiter which sign will delemiter the key-value-pairs between other delemiters
+ */
+ ValueExplode(const QString&aCommand,const char aDelemiter = '&',const char a2Delemiter='=');
+ //! destructor
+ virtual ~ValueExplode();
+ //! assigen operator
+ /*!
+ * \return a list of substrings
+ */
+ operator const tvaluelist& (){return m_LastParsed;}
+};
+
+ValueExplode::~ValueExplode()
+{
+}
+
+ValueExplode::ValueExplode(const QString&aCommand,const char aDelemiter,const char a2Delemiter)
+ :m_LastParsed(),m_Command(aCommand)
+{
+ mDelemiter = aDelemiter;
+ m2Delemiter = a2Delemiter;
+ splitit();
+}
+
+void ValueExplode::splitit()
+{
+ QString iLine;
+ m_LastParsed.clear();
+ if (mDelemiter.isEmpty()||m2Delemiter.isEmpty()) {
+ m_LastParsed.append(tkeyvalues(m_Command,""));
+ return;
+ }
+ int pos,pos2,startpos;
+ startpos = 0;
+ iLine = m_Command;
+ while ( (pos = iLine.find(mDelemiter,startpos))!=-1) {
+ pos2 = iLine.find(m2Delemiter,startpos);
+ if (pos2==-1||pos2>pos) {
+ m_LastParsed.append(tkeyvalues(iLine.mid(startpos,pos-startpos),""));
+ } else {
+ m_LastParsed.append(tkeyvalues(iLine.mid(startpos,pos2-startpos),iLine.mid(pos2+1,pos-pos2-1)));
+ }
+ startpos = pos+1;
+ }
+ if (startpos<iLine.length()) {
+ pos2 = iLine.find(m2Delemiter,startpos);
+ if (pos2==-1) {
+ m_LastParsed.append(tkeyvalues(iLine.mid(startpos),""));
+ } else {
+ m_LastParsed.append(tkeyvalues(iLine.mid(startpos,pos2-startpos),iLine.mid(pos2+1)));
+ }
+ }
+}
+
OpieMail::OpieMail( QWidget *parent, const char *name, WFlags )
: MainWindow( parent, name, WStyle_ContextHelp )
@@ -31,4 +110,10 @@ OpieMail::OpieMail( QWidget *parent, const char *name, WFlags )
folderView->populate( settings->getAccounts() );
+#if 1
+ tvaluelist s = ValueExplode("a=1&b=holladiewaldfee&c=3&d=&e=3450");
+ for (int i = 0; i < s.count();++i) {
+ odebug<<"Key: " << s[i].key << " Value: " << s[i].data << oendl;
+ }
+#endif
}
@@ -74,5 +159,5 @@ void OpieMail::setDocument(const QString& mail)
*/
if( mail.startsWith(QString::fromLatin1("mailto:")) )
- slotwriteMail(QString::null, mail.mid(7));
+ slotwriteMail(QString::null, mail.mid(7));
}