summaryrefslogtreecommitdiff
path: root/noncore/net/mail
authoralwin <alwin>2004-10-24 00:50:03 (UTC)
committer alwin <alwin>2004-10-24 00:50:03 (UTC)
commite16312f45d5df483d21b02d03d5851bc34674f39 (patch) (unidiff)
tree63920b8a2018910d1e25f08d3278b3eb59e889fb /noncore/net/mail
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 (limited to 'noncore/net/mail') (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
@@ -19,2 +19,4 @@
19/* QT */ 19/* QT */
20#include <qmap.h>
21#include <qvaluelist.h>
20 22
@@ -25,2 +27,79 @@ using namespace Opie::Core;
25 27
28typedef QMapNode<QString,QString> tkeyvalues;
29typedef QValueList<tkeyvalues> tvaluelist;
30
31class ValueExplode
32{
33protected:
34 //! what was parsed last
35 tvaluelist m_LastParsed;
36 //! the delemiter to use
37 QString mDelemiter;
38 //! the inner delemiter
39 QString m2Delemiter;
40 //! the real split routine
41 void splitit();
42 //! the content
43 QString m_Command;
44 //! constructor
45 ValueExplode(){}
46public:
47 //! constructor
48 /*!
49 * \param aCommand the string to be splitted
50 * \param aDelemiter which sign will be the delemiter character
51 * \param a2Delemiter which sign will delemiter the key-value-pairs between other delemiters
52 */
53 ValueExplode(const QString&aCommand,const char aDelemiter = '&',const char a2Delemiter='=');
54 //! destructor
55 virtual ~ValueExplode();
56 //! assigen operator
57 /*!
58 * \return a list of substrings
59 */
60 operator const tvaluelist& (){return m_LastParsed;}
61};
62
63ValueExplode::~ValueExplode()
64{
65}
66
67ValueExplode::ValueExplode(const QString&aCommand,const char aDelemiter,const char a2Delemiter)
68 :m_LastParsed(),m_Command(aCommand)
69{
70 mDelemiter = aDelemiter;
71 m2Delemiter = a2Delemiter;
72 splitit();
73}
74
75void ValueExplode::splitit()
76{
77 QString iLine;
78 m_LastParsed.clear();
79 if (mDelemiter.isEmpty()||m2Delemiter.isEmpty()) {
80 m_LastParsed.append(tkeyvalues(m_Command,""));
81 return;
82 }
83 int pos,pos2,startpos;
84 startpos = 0;
85 iLine = m_Command;
86 while ( (pos = iLine.find(mDelemiter,startpos))!=-1) {
87 pos2 = iLine.find(m2Delemiter,startpos);
88 if (pos2==-1||pos2>pos) {
89 m_LastParsed.append(tkeyvalues(iLine.mid(startpos,pos-startpos),""));
90 } else {
91 m_LastParsed.append(tkeyvalues(iLine.mid(startpos,pos2-startpos),iLine.mid(pos2+1,pos-pos2-1)));
92 }
93 startpos = pos+1;
94 }
95 if (startpos<iLine.length()) {
96 pos2 = iLine.find(m2Delemiter,startpos);
97 if (pos2==-1) {
98 m_LastParsed.append(tkeyvalues(iLine.mid(startpos),""));
99 } else {
100 m_LastParsed.append(tkeyvalues(iLine.mid(startpos,pos2-startpos),iLine.mid(pos2+1)));
101 }
102 }
103}
104
26OpieMail::OpieMail( QWidget *parent, const char *name, WFlags ) 105OpieMail::OpieMail( QWidget *parent, const char *name, WFlags )
@@ -32,2 +111,8 @@ OpieMail::OpieMail( QWidget *parent, const char *name, WFlags )
32 folderView->populate( settings->getAccounts() ); 111 folderView->populate( settings->getAccounts() );
112#if 1
113 tvaluelist s = ValueExplode("a=1&b=holladiewaldfee&c=3&d=&e=3450");
114 for (int i = 0; i < s.count();++i) {
115 odebug<<"Key: " << s[i].key << " Value: " << s[i].data << oendl;
116 }
117#endif
33} 118}
@@ -75,3 +160,3 @@ void OpieMail::setDocument(const QString& mail)
75 if( mail.startsWith(QString::fromLatin1("mailto:")) ) 160 if( mail.startsWith(QString::fromLatin1("mailto:")) )
76 slotwriteMail(QString::null, mail.mid(7)); 161 slotwriteMail(QString::null, mail.mid(7));
77} 162}