author | simon <simon> | 2002-03-14 16:50:51 (UTC) |
---|---|---|
committer | simon <simon> | 2002-03-14 16:50:51 (UTC) |
commit | 5283a32d6d9ab9b9bccd3482ab6694c940c874d3 (patch) (unidiff) | |
tree | 3b0e49a60c460a7627d4d328ed0086e5830896db | |
parent | ab6f5e5cdae5eacf6e1fc2434a7d2981c71cb408 (diff) | |
download | opie-5283a32d6d9ab9b9bccd3482ab6694c940c874d3.zip opie-5283a32d6d9ab9b9bccd3482ab6694c940c874d3.tar.gz opie-5283a32d6d9ab9b9bccd3482ab6694c940c874d3.tar.bz2 |
- moved encodeAttr out of XMLElement into an anonymous namespace
- private copy ctor and assignment operator
- changed license to LGPL
-rw-r--r-- | libopie/xmltree.cc | 70 | ||||
-rw-r--r-- | libopie2/opiecore/xmltree.cc | 70 |
2 files changed, 72 insertions, 68 deletions
diff --git a/libopie/xmltree.cc b/libopie/xmltree.cc index 9b8dd05..bf93151 100644 --- a/libopie/xmltree.cc +++ b/libopie/xmltree.cc | |||
@@ -1,46 +1,64 @@ | |||
1 | /* This file is part of the KDE project | 1 | /* This file is part of the KDE project |
2 | Copyright (C) 2001 Simon Hausmann <hausmann@kde.org> | 2 | Copyright (C) 2001 Simon Hausmann <hausmann@kde.org> |
3 | 3 | ||
4 | This program is free software; you can redistribute it and/or modify | 4 | This library is free software; you can redistribute it and/or |
5 | it under the terms of the GNU General Public License as published by | 5 | modify it under the terms of the GNU Library General Public |
6 | the Free Software Foundation; either version 2 of the License, or | 6 | License as published by the Free Software Foundation; either |
7 | (at your option) any later version. | 7 | version 2 of the License, or (at your option) any later version. |
8 | 8 | ||
9 | This program is distributed in the hope that it will be useful, | 9 | This library is distributed in the hope that it will be useful, |
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
12 | GNU General Public License for more details. | 12 | Library General Public License for more details. |
13 | 13 | ||
14 | You should have received a copy of the GNU General Public License | 14 | You should have received a copy of the GNU Library General Public License |
15 | along with this program; if not, write to the Free Software | 15 | along with this library; see the file COPYING.LIB. If not, write to |
16 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | 16 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
17 | 17 | Boston, MA 02111-1307, USA. | |
18 | As a special exception this program may be linked with Qt non-commercial | ||
19 | edition, the resulting executable be distributed, without including the | ||
20 | source code for the Qt non-commercial edition in the source distribution. | ||
21 | |||
22 | */ | 18 | */ |
23 | 19 | ||
24 | 20 | ||
25 | #include "xmltree.h" | 21 | #include "xmltree.h" |
26 | 22 | ||
27 | #include <qxml.h> | 23 | #include <qxml.h> |
28 | 24 | ||
29 | #include <assert.h> | 25 | #include <assert.h> |
30 | 26 | ||
27 | namespace | ||
28 | { | ||
29 | |||
30 | /** | ||
31 | Encode an attribute value upon saving. | ||
32 | replaces '"' with """ | ||
33 | replaces '<' with "<" | ||
34 | replaces '&' with "&" | ||
35 | replaces '>' with ">" | ||
36 | */ | ||
37 | QString encodeAttr( const QString& str ) | ||
38 | { | ||
39 | QString encAttr( str ); // cause of the const parameter | ||
40 | encAttr = encAttr.replace( QRegExp( "[<]" ), "<" ); | ||
41 | encAttr = encAttr.replace( QRegExp( "[>]" ), ">" ); | ||
42 | encAttr = encAttr.replace( QRegExp( "[\"]" ), """ ); | ||
43 | encAttr = encAttr.replace( QRegExp( "[&]" ), "&" ); | ||
44 | return encAttr; | ||
45 | } | ||
46 | |||
47 | } | ||
48 | |||
31 | XMLElement::XMLElement() | 49 | XMLElement::XMLElement() |
32 | : m_parent( 0 ), m_next( 0 ), m_prev( 0 ), m_first( 0 ), m_last( 0 ) | 50 | : m_parent( 0 ), m_next( 0 ), m_prev( 0 ), m_first( 0 ), m_last( 0 ) |
33 | { | 51 | { |
34 | } | 52 | } |
35 | 53 | ||
36 | XMLElement::~XMLElement() | 54 | XMLElement::~XMLElement() |
37 | { | 55 | { |
38 | XMLElement *n = m_first; | 56 | XMLElement *n = m_first; |
39 | 57 | ||
40 | while ( n ) | 58 | while ( n ) |
41 | { | 59 | { |
42 | XMLElement *tmp = n; | 60 | XMLElement *tmp = n; |
43 | n = n->m_next; | 61 | n = n->m_next; |
44 | delete tmp; | 62 | delete tmp; |
45 | } | 63 | } |
46 | } | 64 | } |
@@ -181,48 +199,32 @@ void XMLElement::save( QTextStream &s, uint indent ) | |||
181 | while ( n ) | 199 | while ( n ) |
182 | { | 200 | { |
183 | n->save( s, newIndent ); | 201 | n->save( s, newIndent ); |
184 | n = n->nextChild(); | 202 | n = n->nextChild(); |
185 | } | 203 | } |
186 | 204 | ||
187 | if ( m_last && m_last->value().isEmpty() && m_parent ) | 205 | if ( m_last && m_last->value().isEmpty() && m_parent ) |
188 | for ( uint i = 0; i < indent; ++i ) | 206 | for ( uint i = 0; i < indent; ++i ) |
189 | s << " "; | 207 | s << " "; |
190 | 208 | ||
191 | if ( m_parent ) | 209 | if ( m_parent ) |
192 | s << "</" << m_tag << ">" << endl; | 210 | s << "</" << m_tag << ">" << endl; |
193 | } | 211 | } |
194 | else | 212 | else |
195 | s << "/>" << endl; | 213 | s << "/>" << endl; |
196 | } | 214 | } |
197 | /** | ||
198 | Encode an attribute value upon saving. | ||
199 | replaces '"' with """ | ||
200 | replaces '<' with "<" | ||
201 | replaces '&' with "&" | ||
202 | replaces '>' with ">" | ||
203 | */ | ||
204 | QString XMLElement::encodeAttr( const QString& str ) | ||
205 | { | ||
206 | QString encAttr( str ); // cause of the const parameter | ||
207 | encAttr = encAttr.replace( QRegExp( "[<]" ), "<" ); | ||
208 | encAttr = encAttr.replace( QRegExp( "[>]" ), ">" ); | ||
209 | encAttr = encAttr.replace( QRegExp( "[\"]" ), """ ); | ||
210 | encAttr = encAttr.replace( QRegExp( "[&]" ), "&" ); | ||
211 | return encAttr; | ||
212 | } | ||
213 | 215 | ||
214 | class Handler : public QXmlDefaultHandler | 216 | class Handler : public QXmlDefaultHandler |
215 | { | 217 | { |
216 | public: | 218 | public: |
217 | Handler() : m_node( 0 ), m_root( 0 ) {} | 219 | Handler() : m_node( 0 ), m_root( 0 ) {} |
218 | 220 | ||
219 | XMLElement *root() const { return m_root; } | 221 | XMLElement *root() const { return m_root; } |
220 | 222 | ||
221 | virtual bool startDocument(); | 223 | virtual bool startDocument(); |
222 | virtual bool endDocument(); | 224 | virtual bool endDocument(); |
223 | virtual bool startElement( const QString &ns, const QString &ln, const QString &qName, | 225 | virtual bool startElement( const QString &ns, const QString &ln, const QString &qName, |
224 | const QXmlAttributes &attr ); | 226 | const QXmlAttributes &attr ); |
225 | virtual bool endElement( const QString &ns, const QString &ln, const QString &qName ); | 227 | virtual bool endElement( const QString &ns, const QString &ln, const QString &qName ); |
226 | virtual bool characters( const QString &ch ); | 228 | virtual bool characters( const QString &ch ); |
227 | 229 | ||
228 | private: | 230 | private: |
diff --git a/libopie2/opiecore/xmltree.cc b/libopie2/opiecore/xmltree.cc index 9b8dd05..bf93151 100644 --- a/libopie2/opiecore/xmltree.cc +++ b/libopie2/opiecore/xmltree.cc | |||
@@ -1,46 +1,64 @@ | |||
1 | /* This file is part of the KDE project | 1 | /* This file is part of the KDE project |
2 | Copyright (C) 2001 Simon Hausmann <hausmann@kde.org> | 2 | Copyright (C) 2001 Simon Hausmann <hausmann@kde.org> |
3 | 3 | ||
4 | This program is free software; you can redistribute it and/or modify | 4 | This library is free software; you can redistribute it and/or |
5 | it under the terms of the GNU General Public License as published by | 5 | modify it under the terms of the GNU Library General Public |
6 | the Free Software Foundation; either version 2 of the License, or | 6 | License as published by the Free Software Foundation; either |
7 | (at your option) any later version. | 7 | version 2 of the License, or (at your option) any later version. |
8 | 8 | ||
9 | This program is distributed in the hope that it will be useful, | 9 | This library is distributed in the hope that it will be useful, |
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
12 | GNU General Public License for more details. | 12 | Library General Public License for more details. |
13 | 13 | ||
14 | You should have received a copy of the GNU General Public License | 14 | You should have received a copy of the GNU Library General Public License |
15 | along with this program; if not, write to the Free Software | 15 | along with this library; see the file COPYING.LIB. If not, write to |
16 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | 16 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
17 | 17 | Boston, MA 02111-1307, USA. | |
18 | As a special exception this program may be linked with Qt non-commercial | ||
19 | edition, the resulting executable be distributed, without including the | ||
20 | source code for the Qt non-commercial edition in the source distribution. | ||
21 | |||
22 | */ | 18 | */ |
23 | 19 | ||
24 | 20 | ||
25 | #include "xmltree.h" | 21 | #include "xmltree.h" |
26 | 22 | ||
27 | #include <qxml.h> | 23 | #include <qxml.h> |
28 | 24 | ||
29 | #include <assert.h> | 25 | #include <assert.h> |
30 | 26 | ||
27 | namespace | ||
28 | { | ||
29 | |||
30 | /** | ||
31 | Encode an attribute value upon saving. | ||
32 | replaces '"' with """ | ||
33 | replaces '<' with "<" | ||
34 | replaces '&' with "&" | ||
35 | replaces '>' with ">" | ||
36 | */ | ||
37 | QString encodeAttr( const QString& str ) | ||
38 | { | ||
39 | QString encAttr( str ); // cause of the const parameter | ||
40 | encAttr = encAttr.replace( QRegExp( "[<]" ), "<" ); | ||
41 | encAttr = encAttr.replace( QRegExp( "[>]" ), ">" ); | ||
42 | encAttr = encAttr.replace( QRegExp( "[\"]" ), """ ); | ||
43 | encAttr = encAttr.replace( QRegExp( "[&]" ), "&" ); | ||
44 | return encAttr; | ||
45 | } | ||
46 | |||
47 | } | ||
48 | |||
31 | XMLElement::XMLElement() | 49 | XMLElement::XMLElement() |
32 | : m_parent( 0 ), m_next( 0 ), m_prev( 0 ), m_first( 0 ), m_last( 0 ) | 50 | : m_parent( 0 ), m_next( 0 ), m_prev( 0 ), m_first( 0 ), m_last( 0 ) |
33 | { | 51 | { |
34 | } | 52 | } |
35 | 53 | ||
36 | XMLElement::~XMLElement() | 54 | XMLElement::~XMLElement() |
37 | { | 55 | { |
38 | XMLElement *n = m_first; | 56 | XMLElement *n = m_first; |
39 | 57 | ||
40 | while ( n ) | 58 | while ( n ) |
41 | { | 59 | { |
42 | XMLElement *tmp = n; | 60 | XMLElement *tmp = n; |
43 | n = n->m_next; | 61 | n = n->m_next; |
44 | delete tmp; | 62 | delete tmp; |
45 | } | 63 | } |
46 | } | 64 | } |
@@ -181,48 +199,32 @@ void XMLElement::save( QTextStream &s, uint indent ) | |||
181 | while ( n ) | 199 | while ( n ) |
182 | { | 200 | { |
183 | n->save( s, newIndent ); | 201 | n->save( s, newIndent ); |
184 | n = n->nextChild(); | 202 | n = n->nextChild(); |
185 | } | 203 | } |
186 | 204 | ||
187 | if ( m_last && m_last->value().isEmpty() && m_parent ) | 205 | if ( m_last && m_last->value().isEmpty() && m_parent ) |
188 | for ( uint i = 0; i < indent; ++i ) | 206 | for ( uint i = 0; i < indent; ++i ) |
189 | s << " "; | 207 | s << " "; |
190 | 208 | ||
191 | if ( m_parent ) | 209 | if ( m_parent ) |
192 | s << "</" << m_tag << ">" << endl; | 210 | s << "</" << m_tag << ">" << endl; |
193 | } | 211 | } |
194 | else | 212 | else |
195 | s << "/>" << endl; | 213 | s << "/>" << endl; |
196 | } | 214 | } |
197 | /** | ||
198 | Encode an attribute value upon saving. | ||
199 | replaces '"' with """ | ||
200 | replaces '<' with "<" | ||
201 | replaces '&' with "&" | ||
202 | replaces '>' with ">" | ||
203 | */ | ||
204 | QString XMLElement::encodeAttr( const QString& str ) | ||
205 | { | ||
206 | QString encAttr( str ); // cause of the const parameter | ||
207 | encAttr = encAttr.replace( QRegExp( "[<]" ), "<" ); | ||
208 | encAttr = encAttr.replace( QRegExp( "[>]" ), ">" ); | ||
209 | encAttr = encAttr.replace( QRegExp( "[\"]" ), """ ); | ||
210 | encAttr = encAttr.replace( QRegExp( "[&]" ), "&" ); | ||
211 | return encAttr; | ||
212 | } | ||
213 | 215 | ||
214 | class Handler : public QXmlDefaultHandler | 216 | class Handler : public QXmlDefaultHandler |
215 | { | 217 | { |
216 | public: | 218 | public: |
217 | Handler() : m_node( 0 ), m_root( 0 ) {} | 219 | Handler() : m_node( 0 ), m_root( 0 ) {} |
218 | 220 | ||
219 | XMLElement *root() const { return m_root; } | 221 | XMLElement *root() const { return m_root; } |
220 | 222 | ||
221 | virtual bool startDocument(); | 223 | virtual bool startDocument(); |
222 | virtual bool endDocument(); | 224 | virtual bool endDocument(); |
223 | virtual bool startElement( const QString &ns, const QString &ln, const QString &qName, | 225 | virtual bool startElement( const QString &ns, const QString &ln, const QString &qName, |
224 | const QXmlAttributes &attr ); | 226 | const QXmlAttributes &attr ); |
225 | virtual bool endElement( const QString &ns, const QString &ln, const QString &qName ); | 227 | virtual bool endElement( const QString &ns, const QString &ln, const QString &qName ); |
226 | virtual bool characters( const QString &ch ); | 228 | virtual bool characters( const QString &ch ); |
227 | 229 | ||
228 | private: | 230 | private: |