1
1
//
2
2
// FILE: XMLWriter.cpp
3
3
// AUTHOR: Rob Tillaart
4
- // VERSION: 0.1.6
4
+ // VERSION: 0.1.7
5
5
// DATE: 2013-11-06
6
6
// PURPOSE: Simple XML library
7
7
//
13
13
// 0.1.04 2015-05-21 refactored - reduce RAM -> used F() macro etc.
14
14
// 0.1.05 2015-05-23 added XMLWRITER_MAXTAGSIZE 15 (to support KML coordinates tag)
15
15
// 0.1.6 2016-03-16 added incrIndent(), decrIndent(), indent(), raw();
16
+ // 0.1.7 2017-07-26 added const where possible
16
17
//
17
18
// Released to the public domain
18
19
//
@@ -37,7 +38,7 @@ void XMLWriter::header()
37
38
_stream->println (F (" <?xml version=\" 1.0\" encoding=\" UTF-8\" ?>" ));
38
39
}
39
40
40
- void XMLWriter::comment (char * text, bool multiLine)
41
+ void XMLWriter::comment (const char * text, const bool multiLine)
41
42
{
42
43
_stream->println ();
43
44
if (!multiLine) indent ();
@@ -48,12 +49,12 @@ void XMLWriter::comment(char* text, bool multiLine)
48
49
_stream->println (F (" -->" ));
49
50
}
50
51
51
- void XMLWriter::tagOpen (char * tag, bool newline)
52
+ void XMLWriter::tagOpen (const char * tag, const bool newline)
52
53
{
53
54
tagOpen (tag, " " , newline);
54
55
}
55
56
56
- void XMLWriter::tagOpen (char * tag, char * name, bool newline)
57
+ void XMLWriter::tagOpen (const char * tag, const char * name, const bool newline)
57
58
{
58
59
// TODO STACK GUARD
59
60
strncpy (tagStack[_idx++], tag, XMLWRITER_MAXTAGSIZE);
@@ -63,7 +64,7 @@ void XMLWriter::tagOpen(char* tag, char* name, bool newline)
63
64
_indent += _indentStep;
64
65
}
65
66
66
- void XMLWriter::tagClose (bool ind)
67
+ void XMLWriter::tagClose (const bool ind)
67
68
{
68
69
_indent -= _indentStep;
69
70
if (ind) indent ();
@@ -72,14 +73,14 @@ void XMLWriter::tagClose(bool ind)
72
73
_stream->println (F (" >" ));
73
74
}
74
75
75
- void XMLWriter::tagStart (char *tag)
76
+ void XMLWriter::tagStart (const char *tag)
76
77
{
77
78
indent ();
78
79
_stream->print (' <' );
79
80
_stream->print (tag);
80
81
}
81
82
82
- void XMLWriter::tagField (char *field, char * str)
83
+ void XMLWriter::tagField (const char *field, const char * str)
83
84
{
84
85
_stream->print (' ' );
85
86
_stream->print (field);
@@ -92,14 +93,14 @@ void XMLWriter::tagField(char *field, char* str)
92
93
_stream->print (' "' );
93
94
}
94
95
95
- void XMLWriter::tagEnd (bool newline, bool addSlash)
96
+ void XMLWriter::tagEnd (const bool newline, const bool addSlash)
96
97
{
97
98
if (addSlash) _stream->print (' /' );
98
99
_stream->print (' >' );
99
100
if (newline) _stream->println ();
100
101
}
101
102
102
- void XMLWriter::writeNode (char * tag, char * str)
103
+ void XMLWriter::writeNode (const char * tag, const char * str)
103
104
{
104
105
tagOpen (tag, " " , NONEWLINE);
105
106
#ifdef XMLWRITER_ESCAPE_SUPPORT
@@ -110,22 +111,22 @@ void XMLWriter::writeNode(char* tag, char* str)
110
111
tagClose (NOINDENT);
111
112
}
112
113
113
- void XMLWriter::setIndentSize (uint8_t size)
114
+ void XMLWriter::setIndentSize (const uint8_t size)
114
115
{
115
116
_indentStep = size;
116
117
}
117
118
118
- void XMLWriter::tagField (char *field, uint8_t value, uint8_t base)
119
+ void XMLWriter::tagField (const char *field, const uint8_t value, const uint8_t base)
119
120
{
120
121
tagField (field, (uint32_t ) value, base);
121
122
}
122
123
123
- void XMLWriter::tagField (char *field, uint16_t value, uint8_t base)
124
+ void XMLWriter::tagField (const char *field, const uint16_t value, const uint8_t base)
124
125
{
125
126
tagField (field, (uint32_t ) value, base);
126
127
}
127
128
128
- void XMLWriter::tagField (char *field, uint32_t value, uint8_t base)
129
+ void XMLWriter::tagField (const char *field, const uint32_t value, const uint8_t base)
129
130
{
130
131
_stream->print (' ' );
131
132
_stream->print (field);
@@ -134,17 +135,17 @@ void XMLWriter::tagField(char *field, uint32_t value, uint8_t base)
134
135
_stream->print (' "' );
135
136
}
136
137
137
- void XMLWriter::tagField (char *field, int8_t value, uint8_t base)
138
+ void XMLWriter::tagField (const char *field, const int8_t value, const uint8_t base)
138
139
{
139
140
tagField (field, (long ) value, base);
140
141
}
141
142
142
- void XMLWriter::tagField (char *field, int16_t value, uint8_t base)
143
+ void XMLWriter::tagField (const char *field, const int16_t value, const uint8_t base)
143
144
{
144
145
tagField (field, (long ) value, base);
145
146
}
146
147
147
- void XMLWriter::tagField (char *field, int32_t value, uint8_t base)
148
+ void XMLWriter::tagField (const char *field, const int32_t value, const uint8_t base)
148
149
{
149
150
_stream->print (' ' );
150
151
_stream->print (field);
@@ -154,7 +155,7 @@ void XMLWriter::tagField(char *field, int32_t value, uint8_t base)
154
155
}
155
156
156
157
157
- void XMLWriter::tagField (char *field, bool value)
158
+ void XMLWriter::tagField (const char *field, const bool value)
158
159
{
159
160
_stream->print (' ' );
160
161
_stream->print (field);
@@ -163,7 +164,7 @@ void XMLWriter::tagField(char *field, bool value)
163
164
_stream->print (' "' );
164
165
}
165
166
166
- void XMLWriter::tagField (char *field, double value, uint8_t decimals)
167
+ void XMLWriter::tagField (const char *field, const double value, const uint8_t decimals)
167
168
{
168
169
_stream->print (' ' );
169
170
_stream->print (field);
@@ -172,48 +173,48 @@ void XMLWriter::tagField(char *field, double value, uint8_t decimals)
172
173
_stream->print (' "' );
173
174
}
174
175
175
- void XMLWriter::writeNode (char * tag, uint8_t value, uint8_t base)
176
+ void XMLWriter::writeNode (const char * tag, const uint8_t value, const uint8_t base)
176
177
{
177
178
writeNode (tag, (uint32_t ) value, base);
178
179
}
179
180
180
- void XMLWriter::writeNode (char * tag, uint16_t value, uint8_t base)
181
+ void XMLWriter::writeNode (const char * tag, const uint16_t value, const uint8_t base)
181
182
{
182
183
writeNode (tag, (uint32_t ) value, base);
183
184
}
184
185
185
- void XMLWriter::writeNode (char * tag, uint32_t value, uint8_t base)
186
+ void XMLWriter::writeNode (const char * tag, const uint32_t value, const uint8_t base)
186
187
{
187
188
tagOpen (tag, " " , NONEWLINE);
188
189
_stream->print (value, base); // todo: leading zero's
189
190
tagClose (NOINDENT);
190
191
}
191
192
192
- void XMLWriter::writeNode (char * tag, int8_t value, uint8_t base)
193
+ void XMLWriter::writeNode (const char * tag, const int8_t value, const uint8_t base)
193
194
{
194
195
writeNode (tag, (int32_t ) value, base);
195
196
}
196
197
197
- void XMLWriter::writeNode (char * tag, int16_t value, uint8_t base)
198
+ void XMLWriter::writeNode (const char * tag, const int16_t value, const uint8_t base)
198
199
{
199
200
writeNode (tag, (int32_t ) value, base);
200
201
}
201
202
202
- void XMLWriter::writeNode (char * tag, int32_t value, uint8_t base)
203
+ void XMLWriter::writeNode (const char * tag, const int32_t value, const uint8_t base)
203
204
{
204
205
tagOpen (tag, " " , NONEWLINE);
205
206
_stream->print (value, base); // todo: leading zero's
206
207
tagClose (NOINDENT);
207
208
}
208
209
209
- void XMLWriter::writeNode (char * tag, bool value)
210
+ void XMLWriter::writeNode (const char * tag, const bool value)
210
211
{
211
212
tagOpen (tag, " " , NONEWLINE);
212
213
_stream->print (value?F (" true" ):F (" false" ));
213
214
tagClose (NOINDENT);
214
215
}
215
216
216
- void XMLWriter::writeNode (char * tag, double value, uint8_t decimals)
217
+ void XMLWriter::writeNode (const char * tag, const double value, const uint8_t decimals)
217
218
{
218
219
tagOpen (tag, " " , NONEWLINE);
219
220
_stream->print (value, decimals);
@@ -231,9 +232,9 @@ void XMLWriter::indent()
231
232
char c[6 ] = " \"\' <>&" ;
232
233
char expanded[][7 ] = { " "" , " '" ," <" ," >" ," &" }; // todo in flash
233
234
234
- void XMLWriter::escape (char * str)
235
+ void XMLWriter::escape (const char * str)
235
236
{
236
- char * p = str;
237
+ char * p = ( char *) str;
237
238
while (*p != 0 )
238
239
{
239
240
char * q = strchr (c, *p);
0 commit comments