From 9cbf8c559159bcfdeb4461b68a112e5ab70bb866 Mon Sep 17 00:00:00 2001 From: rob tillaart Date: Sun, 27 Nov 2022 12:54:57 +0100 Subject: [PATCH] 0.3.3 XMLWriter --- libraries/XMLWriter/.arduino-ci.yml | 21 +++++- libraries/XMLWriter/CHANGELOG.md | 89 ++++++++++++++++++++++++ libraries/XMLWriter/README.md | 29 ++++---- libraries/XMLWriter/XMLWriter.cpp | 53 ++++---------- libraries/XMLWriter/XMLWriter.h | 95 +++++++++++++------------- libraries/XMLWriter/keywords.txt | 2 + libraries/XMLWriter/library.json | 2 +- libraries/XMLWriter/library.properties | 2 +- 8 files changed, 191 insertions(+), 102 deletions(-) create mode 100644 libraries/XMLWriter/CHANGELOG.md diff --git a/libraries/XMLWriter/.arduino-ci.yml b/libraries/XMLWriter/.arduino-ci.yml index 37b64d55..5f94fea8 100644 --- a/libraries/XMLWriter/.arduino-ci.yml +++ b/libraries/XMLWriter/.arduino-ci.yml @@ -1,3 +1,18 @@ +platforms: + rpipico: + board: rp2040:rp2040:rpipico + package: rp2040:rp2040 + gcc: + features: + defines: + - ARDUINO_ARCH_RP2040 + warnings: + flags: + +packages: + rp2040:rp2040: + url: https://github.com/earlephilhower/arduino-pico/releases/download/global/package_rp2040_index.json + compile: # Choosing to run compilation tests on 2 different Arduino platforms platforms: @@ -7,8 +22,10 @@ compile: - leonardo - m4 - esp32 - # - esp8266 - # - mega2560 + # - esp8266 # causes analog pins to fail + - mega2560 + - rpipico + libraries: - "Ethernet" - "SD" diff --git a/libraries/XMLWriter/CHANGELOG.md b/libraries/XMLWriter/CHANGELOG.md new file mode 100644 index 00000000..abfff905 --- /dev/null +++ b/libraries/XMLWriter/CHANGELOG.md @@ -0,0 +1,89 @@ +# Change Log XMLWriter + +All notable changes to this project will be documented in this file. + +The format is based on [Keep a Changelog](http://keepachangelog.com/) +and this project adheres to [Semantic Versioning](http://semver.org/). + + +## [0.3.3] - 2022-11-27 +- Add RP2040 support to build-CI. +- Add CHANGELOG.md +- update readme.md + + +## [0.3.2] - 2021-12-29 +- update library.json +- update readme.md +- update license +- update unit test +- minor edits + +## [0.3.1] - 2021-11-11 +- refactor naming to improve readability +- update build-CI, +- update readme.md, Badges. + +## [0.3.0] - 2021-01-09 +- Arduino-ci + unit tests +- add getIndentSize() +- add version() +- add debug() + +---- +## [0.2.4] - 2020-07-07 +- fix #6 Print interface made public + +## [0.2.3] - 2020-06-19 +- fix library.json + +## [0.2.2] - 2020-04-29 += dynamic buffer size in constructor + +## [0.2.1] - 2020-04-26 +- performance optimized +- add setconfig() +- add newLine() + +## [0.2.0] - 2020-04-24 +- refactor +- add examples +- add #pragma +- add print as base class + +---- + +## [0.1.9] - 2017-12-09 +- add PROGMEM support for escape() strings + +## [0.1.8] - 2017-12-09 +- fix casting issue #83 (long -> int32_t); + +## [0.1.7] - 2017-07-26 +- add const where possible + +## [0.1.6] - 2016-03-16 +- added incrIndent(), decrIndent() +- add indent() +- add raw() + +## [0.1.05] - 2015-05-23 +- added XMLWRITER_MAXTAGSIZE 15 (to support KML coordinates tag) + +## [0.1.04] - 2015-05-21 +- refactored - reduce RAM -> used F() macro etc. + +## [0.1.03] - 2015-03-07 +- refactored - footprint + interface + +## [0.1.02] - 2013-11-07 +- add setIndentSize() += corrected history +- add escape support + +## [0.1.01] - 2013-11-07 +- rework interfaces + +## [0.1.00] - 2013-11-06 +- initial version + diff --git a/libraries/XMLWriter/README.md b/libraries/XMLWriter/README.md index 733d1996..c1d3eea4 100644 --- a/libraries/XMLWriter/README.md +++ b/libraries/XMLWriter/README.md @@ -28,11 +28,11 @@ and choose one that is appropriate. Indicative sizes based upon the examples. Run your tests to find your application optimum. -| STREAM | SIZE | -|:---------|:-----------| -| Ethernet | 20-30 | -| Serial | 5 | -| SD File | 10-16 | +| STREAM | SIZE | +|:-----------|:-----------| +| Ethernet | 20-30 | +| Serial | 5 | +| SD File | 10-16 | **IMPORTANT:** When using buffering you should always call **XML.flush()** at the end of the XML generation. This will flush the last bytes in the internal buffer into the output stream. @@ -130,12 +130,12 @@ can inject strings. ## Configuration flags -| Flag | Value | Description | -|:-----------------|:------|:------------------| -|XMLWRITER_NONE | 0x00 | minimize output, smaller & faster | -|XMLWRITER_COMMENT | 0x01 | allow comments | -|XMLWRITER_INDENT | 0x02 | allow indentation | -|XMLWRITER_NEWLINE | 0x04 | allow newlines | +| Flag | Value | Description | +|:--------------------|:--------|:--------------------| +| XMLWRITER_NONE | 0x00 | minimize output, smaller & faster | +| XMLWRITER_COMMENT | 0x01 | allow comments | +| XMLWRITER_INDENT | 0x02 | allow indentation | +| XMLWRITER_NEWLINE | 0x04 | allow newlines | - **setConfig(XMLWRITER_NONE);** to minimize the output in bytes. @@ -151,7 +151,12 @@ See examples ## Future +#### must - update documentation -- + +#### should + +#### could +- move code to .cpp diff --git a/libraries/XMLWriter/XMLWriter.cpp b/libraries/XMLWriter/XMLWriter.cpp index 99c8b121..bf702bee 100644 --- a/libraries/XMLWriter/XMLWriter.cpp +++ b/libraries/XMLWriter/XMLWriter.cpp @@ -1,32 +1,9 @@ // // FILE: XMLWriter.cpp // AUTHOR: Rob Tillaart -// VERSION: 0.3.2 +// VERSION: 0.3.3 // DATE: 2013-11-06 -// PURPOSE: Arduino library for creating XML -// -// HISTORY: -// 0.1.00 2013-11-06 initial version -// 0.1.01 2013-11-07 rework interfaces -// 0.1.02 2013-11-07 +setIndentSize(), corrected history, +escape support -// 0.1.03 2015-03-07 refactored - footprint + interface -// 0.1.04 2015-05-21 refactored - reduce RAM -> used F() macro etc. -// 0.1.05 2015-05-23 added XMLWRITER_MAXTAGSIZE 15 (to support KML coordinates tag) -// 0.1.6 2016-03-16 added incrIndent(), decrIndent(), indent(), raw(); -// 0.1.7 2017-07-26 added const where possible -// 0.1.8 2017-12-09 fix casting issue #83 (long -> int32_t); -// 0.1.9 2017-12-09 add PROGMEM support for escape() strings -// 0.2.0 2020-04-24 refactor, added examples, #pragma, print as base class -// 0.2.1 2020-04-26 performance optimized, setconfig() + newLine() added -// 0.2.2 2020-04-29 dynamic buffer size in constructor -// 0.2.3 2020-06-19 fix library.json -// 0.2.4 2020-07-07 fix #6 Print interface made public -// 0.3.0 2021-01-09 Arduino-ci + unit tests -// add getIndentSize(); version(); debug(); -// 0.3.1 2021-11-11 refactor naming to improve readability -// update build-CI, -// update readme.md, Badges. -// 0.3.2 2021-12-29 update library.json, readme, license, unit test, minor edits +// PURPOSE: Arduino library for creating XML #include "XMLWriter.h" @@ -202,7 +179,7 @@ void XMLWriter::writeNode(const char* tag, const char* str) /////////////////////////////////////////////////////////////// // -// TAGFIELD +// TAGFIELD // void XMLWriter::tagField(const char *field, const uint8_t value, const uint8_t base) { @@ -258,7 +235,7 @@ void XMLWriter::tagField(const char *field, const bool value) { print(' '); print(field); - // F() is slower & uses less RAM but 15 bytes saved + // F() is slower & uses less RAM but 15 bytes saved print(value ? F("=\"true\"") : F("=\"false\"")); } @@ -275,7 +252,7 @@ void XMLWriter::tagField(const char *field, const double value, const uint8_t de /////////////////////////////////////////////////////////////// // -// WRITENODE +// WRITENODE // void XMLWriter::writeNode(const char* tag, const uint8_t value, const uint8_t base) { @@ -326,7 +303,7 @@ void XMLWriter::writeNode(const char* tag, const int32_t value, const uint8_t ba void XMLWriter::writeNode(const char* tag, const bool value) { tagOpen(tag, "", NONEWLINE); - // F() is slower & uses less RAM but saves 9 bytes + // F() is slower & uses less RAM but saves 9 bytes print(value ? F("true") : F("false")); tagClose(NOINDENT); } @@ -344,8 +321,8 @@ void XMLWriter::indent() { if (_config & XMLWRITER_INDENT) { - // as indentation is a multiple of 2 - // this is nice balance between speed and RAM. + // as indentation is a multiple of 2 + // this is nice balance between speed and RAM. for (uint8_t i = _indent; i > 0; i-= 2) print(" "); } } @@ -365,8 +342,8 @@ void XMLWriter::flush() if (_bufferIndex > 0) { _buffer[_bufferIndex] = 0; - _stream->write(_buffer, _bufferIndex); // saves ~40 bytes on UNO. - // _stream->print(_buffer); + _stream->write(_buffer, _bufferIndex); // saves ~40 bytes on UNO. + // _stream->print(_buffer); _bufferIndex = 0; } }; @@ -374,7 +351,7 @@ void XMLWriter::flush() //////////////////////////////////////////////////////////////////// // -// ESCAPE +// ESCAPE // #ifdef XMLWRITER_ESCAPE_SUPPORT @@ -393,7 +370,7 @@ PROGMEM const char* const expanded[] = }; #else -// NOTE: & and ; are handled in code. // 25 bytes RAM +// NOTE: & and ; are handled in code. // 25 bytes RAM static char expanded[][5] = { "quot", "apos","lt","gt","amp"}; #endif @@ -406,7 +383,7 @@ void XMLWriter::escape(const char* str) char* q = strchr(c, *p); if (q == NULL) print(*p); #ifdef __PROGMEM__ - else + else { char buf[8]; strcpy_P(buf, (char*)pgm_read_word(&(expanded[q - c]))); @@ -416,7 +393,7 @@ void XMLWriter::escape(const char* str) else { print('&'); - print(expanded[q - c]); // uint8_t idx = q-c; + print(expanded[q - c]); // uint8_t idx = q-c; print(';'); } #endif @@ -426,5 +403,5 @@ void XMLWriter::escape(const char* str) #endif -// -- END OF FILE -- +// -- END OF FILE -- diff --git a/libraries/XMLWriter/XMLWriter.h b/libraries/XMLWriter/XMLWriter.h index 37576e80..a2553c47 100644 --- a/libraries/XMLWriter/XMLWriter.h +++ b/libraries/XMLWriter/XMLWriter.h @@ -2,111 +2,110 @@ // // FILE: XMLWriter.h // AUTHOR: Rob Tillaart -// VERSION: 0.3.2 +// VERSION: 0.3.3 // DATE: 2013-11-06 -// PURPOSE: Arduino library for creating XML -// +// PURPOSE: Arduino library for creating XML #include "Arduino.h" -#define XMLWRITER_VERSION (F("0.3.2")) +#define XMLWRITER_VERSION (F("0.3.3")) -// for comment() +// for comment() #define NOMULTILINE false #define MULTILINE true -// for tagOpen(), tagEnd() +// for tagOpen(), tagEnd() #define NEWLINE true #define NONEWLINE false -#define NOINDENT false // for tagClose() +#define NOINDENT false // for tagClose() -// for tagEnd() +// for tagEnd() #define SLASH true #define NOSLASH false -// deepness of XML tree 5..10 -// needed for stack of tagStack +// deepness of XML tree 5..10 +// needed for stack of tagStack #ifndef XMLWRITER_MAXLEVEL -#define XMLWRITER_MAXLEVEL 5 // adjust for deeper nested structures +#define XMLWRITER_MAXLEVEL 5 // adjust for deeper nested structures #endif #ifndef XMLWRITER_MAXTAGSIZE -#define XMLWRITER_MAXTAGSIZE 15 // adjust for longer fields - !! eats memory !! +#define XMLWRITER_MAXTAGSIZE 15 // adjust for longer fields - !! eats memory !! #endif -// reduce footprint by commenting next line +// reduce footprint by commenting next line #define XMLWRITER_ESCAPE_SUPPORT -// configuration - setConfig +// configuration - setConfig #define XMLWRITER_NONE 0x00 #define XMLWRITER_COMMENT 0x01 #define XMLWRITER_INDENT 0x02 #define XMLWRITER_NEWLINE 0x04 -// uncomment next line to reduce ~30bytes RAM in escape() (AVR oonly) -// #define __PROGMEM__ +// uncomment next line to reduce ~30bytes RAM in escape() (AVR oonly) +// #define __PROGMEM__ class XMLWriter : public Print { public: - // default = Serial + // default = Serial XMLWriter(Print* stream = &Serial, uint8_t bufferSize = 10); ~XMLWriter(); void reset(); - // to show/strip comment, indent, newLine - // to minimize the output setConfig(0); + // to show/strip comment, indent, newLine + // to minimize the output setConfig(0); void setConfig(uint8_t config) { _config = config; }; - // standard XML header + // standard XML header void header(); - // prints XMLWRITER_VERSION as comment + // prints XMLWRITER_VERSION as comment void version(); - // prints debug information into the XML as comment + // prints debug information into the XML as comment void debug(); - // if multiline == true it does not indent to allow bigger text blocks - // + // if multiline == true it does not indent to allow bigger text blocks + // void comment(const char* text, const bool multiLine = false); - // add a number of newlines to the output, default = 1. + // add a number of newlines to the output, default = 1. void newLine(uint8_t n = 1); - // TAG + // TAG // - // + // void tagOpen(const char* tag, const bool newline = true); - // + // void tagOpen(const char* tag, const char* name, const bool newline = true); - // + // void tagClose(const bool ind = true); - // + // /> void tagEnd(const bool newline = true, const bool addSlash = true); - // value + // value void writeNode(const char* tag, const char* value); - // INDENT + // INDENT // - // typically 0,2,4; default == 2; - // multiple of 2; + // typically 0,2,4; default == 2; + // multiple of 2; void setIndentSize(const uint8_t size = 2) { _indentStep = size; }; uint8_t getIndentSize() { return _indentStep; }; - // for manual layout control + // for manual layout control void incrIndent() { _indent += _indentStep; }; void decrIndent() { _indent -= _indentStep; }; void indent(); @@ -140,39 +139,39 @@ public: #ifdef XMLWRITER_ESCAPE_SUPPORT - // expands the special xml chars + // expands the special xml chars void escape(const char* str); #endif - // One need to call flush() at the end of writing to empty the internal buffer. - // Note: this is overridden of the Print interface + // One need to call flush() at the end of writing to empty the internal buffer. + // Note: this is overridden of the Print interface void flush(); - // metrics + // metrics uint8_t bufferIndex() { return _bufferIndex; }; uint32_t bytesWritten() { return _bytesOut; }; private: - // output stream, Print Class + // output stream, Print Class Print* _stream; size_t write(uint8_t c); - // for indentation + // for indentation uint8_t _indent; uint8_t _indentStep; - // configuration + // configuration uint8_t _config; - // stack - used to remember the current tagname to create - // automatic the right close tag. + // stack - used to remember the current tagname to create + // automatic the right close tag. uint8_t _tagIndex; char _tagStack[XMLWRITER_MAXLEVEL][XMLWRITER_MAXTAGSIZE + 1]; - // output admin + // output admin char * _buffer; uint8_t _bufferSize; uint8_t _bufferIndex; @@ -180,5 +179,5 @@ private: }; -// -- END OF FILE -- +// -- END OF FILE -- diff --git a/libraries/XMLWriter/keywords.txt b/libraries/XMLWriter/keywords.txt index 442d9ec6..e7176a6c 100644 --- a/libraries/XMLWriter/keywords.txt +++ b/libraries/XMLWriter/keywords.txt @@ -46,8 +46,10 @@ MULTILINE LITERAL1 NEWLINE LITERAL1 NONEWLINE LITERAL1 NOINDENT LITERAL1 + SLASH LITERAL1 NOSLASH LITERAL1 + XMLWRITER_NONE LITERAL1 XMLWRITER_COMMENT LITERAL1 XMLWRITER_INDENT LITERAL1 diff --git a/libraries/XMLWriter/library.json b/libraries/XMLWriter/library.json index 1a6dfa7a..24714666 100644 --- a/libraries/XMLWriter/library.json +++ b/libraries/XMLWriter/library.json @@ -15,7 +15,7 @@ "type": "git", "url": "https://github.com/RobTillaart/XMLWriter" }, - "version": "0.3.2", + "version": "0.3.3", "license": "MIT", "frameworks": "arduino", "platforms": "*", diff --git a/libraries/XMLWriter/library.properties b/libraries/XMLWriter/library.properties index ec91ac44..4f36c8a9 100644 --- a/libraries/XMLWriter/library.properties +++ b/libraries/XMLWriter/library.properties @@ -1,5 +1,5 @@ name=XMLWriter -version=0.3.2 +version=0.3.3 author=Rob Tillaart maintainer=Rob Tillaart sentence=Arduino library for creating XML