1
1
//
2
2
// FILE: XMLWriter.cpp
3
3
// AUTHOR: Rob Tillaart
4
- // VERSION: 0.3.2
4
+ // VERSION: 0.3.3
5
5
// DATE: 2013-11-06
6
- // PURPOSE: Arduino library for creating XML
7
- //
8
- // HISTORY:
9
- // 0.1.00 2013-11-06 initial version
10
- // 0.1.01 2013-11-07 rework interfaces
11
- // 0.1.02 2013-11-07 +setIndentSize(), corrected history, +escape support
12
- // 0.1.03 2015-03-07 refactored - footprint + interface
13
- // 0.1.04 2015-05-21 refactored - reduce RAM -> used F() macro etc.
14
- // 0.1.05 2015-05-23 added XMLWRITER_MAXTAGSIZE 15 (to support KML coordinates tag)
15
- // 0.1.6 2016-03-16 added incrIndent(), decrIndent(), indent(), raw();
16
- // 0.1.7 2017-07-26 added const where possible
17
- // 0.1.8 2017-12-09 fix casting issue #83 (long -> int32_t);
18
- // 0.1.9 2017-12-09 add PROGMEM support for escape() strings
19
- // 0.2.0 2020-04-24 refactor, added examples, #pragma, print as base class
20
- // 0.2.1 2020-04-26 performance optimized, setconfig() + newLine() added
21
- // 0.2.2 2020-04-29 dynamic buffer size in constructor
22
- // 0.2.3 2020-06-19 fix library.json
23
- // 0.2.4 2020-07-07 fix #6 Print interface made public
24
- // 0.3.0 2021-01-09 Arduino-ci + unit tests
25
- // add getIndentSize(); version(); debug();
26
- // 0.3.1 2021-11-11 refactor naming to improve readability
27
- // update build-CI,
28
- // update readme.md, Badges.
29
- // 0.3.2 2021-12-29 update library.json, readme, license, unit test, minor edits
6
+ // PURPOSE: Arduino library for creating XML
30
7
31
8
32
9
#include " XMLWriter.h"
@@ -202,7 +179,7 @@ void XMLWriter::writeNode(const char* tag, const char* str)
202
179
203
180
// /////////////////////////////////////////////////////////////
204
181
//
205
- // TAGFIELD
182
+ // TAGFIELD
206
183
//
207
184
void XMLWriter::tagField (const char *field, const uint8_t value, const uint8_t base)
208
185
{
@@ -258,7 +235,7 @@ void XMLWriter::tagField(const char *field, const bool value)
258
235
{
259
236
print (' ' );
260
237
print (field);
261
- // F() is slower & uses less RAM but 15 bytes saved
238
+ // F() is slower & uses less RAM but 15 bytes saved
262
239
print (value ? F (" =\" true\" " ) : F (" =\" false\" " ));
263
240
}
264
241
@@ -275,7 +252,7 @@ void XMLWriter::tagField(const char *field, const double value, const uint8_t de
275
252
276
253
// /////////////////////////////////////////////////////////////
277
254
//
278
- // WRITENODE
255
+ // WRITENODE
279
256
//
280
257
void XMLWriter::writeNode (const char * tag, const uint8_t value, const uint8_t base)
281
258
{
@@ -326,7 +303,7 @@ void XMLWriter::writeNode(const char* tag, const int32_t value, const uint8_t ba
326
303
void XMLWriter::writeNode (const char * tag, const bool value)
327
304
{
328
305
tagOpen (tag, " " , NONEWLINE);
329
- // F() is slower & uses less RAM but saves 9 bytes
306
+ // F() is slower & uses less RAM but saves 9 bytes
330
307
print (value ? F (" true" ) : F (" false" ));
331
308
tagClose (NOINDENT);
332
309
}
@@ -344,8 +321,8 @@ void XMLWriter::indent()
344
321
{
345
322
if (_config & XMLWRITER_INDENT)
346
323
{
347
- // as indentation is a multiple of 2
348
- // this is nice balance between speed and RAM.
324
+ // as indentation is a multiple of 2
325
+ // this is nice balance between speed and RAM.
349
326
for (uint8_t i = _indent; i > 0 ; i-= 2 ) print (" " );
350
327
}
351
328
}
@@ -365,16 +342,16 @@ void XMLWriter::flush()
365
342
if (_bufferIndex > 0 )
366
343
{
367
344
_buffer[_bufferIndex] = 0 ;
368
- _stream->write (_buffer, _bufferIndex); // saves ~40 bytes on UNO.
369
- // _stream->print(_buffer);
345
+ _stream->write (_buffer, _bufferIndex); // saves ~40 bytes on UNO.
346
+ // _stream->print(_buffer);
370
347
_bufferIndex = 0 ;
371
348
}
372
349
};
373
350
374
351
375
352
// //////////////////////////////////////////////////////////////////
376
353
//
377
- // ESCAPE
354
+ // ESCAPE
378
355
//
379
356
380
357
#ifdef XMLWRITER_ESCAPE_SUPPORT
@@ -393,7 +370,7 @@ PROGMEM const char* const expanded[] =
393
370
};
394
371
395
372
#else
396
- // NOTE: & and ; are handled in code. // 25 bytes RAM
373
+ // NOTE: & and ; are handled in code. // 25 bytes RAM
397
374
static char expanded[][5 ] = { " quot" , " apos" ," lt" ," gt" ," amp" };
398
375
399
376
#endif
@@ -406,7 +383,7 @@ void XMLWriter::escape(const char* str)
406
383
char * q = strchr (c, *p);
407
384
if (q == NULL ) print (*p);
408
385
#ifdef __PROGMEM__
409
- else
386
+ else
410
387
{
411
388
char buf[8 ];
412
389
strcpy_P (buf, (char *)pgm_read_word (&(expanded[q - c])));
@@ -416,7 +393,7 @@ void XMLWriter::escape(const char* str)
416
393
else
417
394
{
418
395
print (' &' );
419
- print (expanded[q - c]); // uint8_t idx = q-c;
396
+ print (expanded[q - c]); // uint8_t idx = q-c;
420
397
print (' ;' );
421
398
}
422
399
#endif
@@ -426,5 +403,5 @@ void XMLWriter::escape(const char* str)
426
403
#endif
427
404
428
405
429
- // -- END OF FILE --
406
+ // -- END OF FILE --
430
407
0 commit comments