author | alwin <alwin> | 2004-10-24 00:50:03 (UTC) |
---|---|---|
committer | alwin <alwin> | 2004-10-24 00:50:03 (UTC) |
commit | e16312f45d5df483d21b02d03d5851bc34674f39 (patch) (unidiff) | |
tree | 63920b8a2018910d1e25f08d3278b3eb59e889fb | |
parent | 9c5964f8d2be467aa53d3d8255b499890556e320 (diff) | |
download | opie-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 ;)
-rw-r--r-- | noncore/net/mail/opiemail.cpp | 87 |
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 @@ | |||
18 | 18 | ||
19 | /* QT */ | 19 | /* QT */ |
20 | #include <qmap.h> | ||
21 | #include <qvaluelist.h> | ||
20 | 22 | ||
21 | /* UNIX */ | 23 | /* UNIX */ |
@@ -24,4 +26,81 @@ | |||
24 | using namespace Opie::Core; | 26 | using namespace Opie::Core; |
25 | 27 | ||
28 | typedef QMapNode<QString,QString> tkeyvalues; | ||
29 | typedef QValueList<tkeyvalues> tvaluelist; | ||
30 | |||
31 | class ValueExplode | ||
32 | { | ||
33 | protected: | ||
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(){} | ||
46 | public: | ||
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 | |||
63 | ValueExplode::~ValueExplode() | ||
64 | { | ||
65 | } | ||
66 | |||
67 | ValueExplode::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 | |||
75 | void 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 | |||
26 | OpieMail::OpieMail( QWidget *parent, const char *name, WFlags ) | 105 | OpieMail::OpieMail( QWidget *parent, const char *name, WFlags ) |
27 | : MainWindow( parent, name, WStyle_ContextHelp ) | 106 | : MainWindow( parent, name, WStyle_ContextHelp ) |
@@ -31,4 +110,10 @@ OpieMail::OpieMail( QWidget *parent, const char *name, WFlags ) | |||
31 | 110 | ||
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 | } |
34 | 119 | ||
@@ -74,5 +159,5 @@ void OpieMail::setDocument(const QString& mail) | |||
74 | */ | 159 | */ |
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 | } |
78 | 163 | ||