Skip to content

Commit 19ea3cf

Browse files
committed
Added const for most parameters; added keywords.txt
1 parent c4df580 commit 19ea3cf

File tree

5 files changed

+110
-63
lines changed

5 files changed

+110
-63
lines changed

libraries/XMLWriter/XMLWriter.cpp

Lines changed: 29 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//
22
// FILE: XMLWriter.cpp
33
// AUTHOR: Rob Tillaart
4-
// VERSION: 0.1.6
4+
// VERSION: 0.1.7
55
// DATE: 2013-11-06
66
// PURPOSE: Simple XML library
77
//
@@ -13,6 +13,7 @@
1313
// 0.1.04 2015-05-21 refactored - reduce RAM -> used F() macro etc.
1414
// 0.1.05 2015-05-23 added XMLWRITER_MAXTAGSIZE 15 (to support KML coordinates tag)
1515
// 0.1.6 2016-03-16 added incrIndent(), decrIndent(), indent(), raw();
16+
// 0.1.7 2017-07-26 added const where possible
1617
//
1718
// Released to the public domain
1819
//
@@ -37,7 +38,7 @@ void XMLWriter::header()
3738
_stream->println(F("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"));
3839
}
3940

40-
void XMLWriter::comment(char* text, bool multiLine)
41+
void XMLWriter::comment(const char* text, const bool multiLine)
4142
{
4243
_stream->println();
4344
if (!multiLine) indent();
@@ -48,12 +49,12 @@ void XMLWriter::comment(char* text, bool multiLine)
4849
_stream->println(F(" -->"));
4950
}
5051

51-
void XMLWriter::tagOpen(char* tag, bool newline)
52+
void XMLWriter::tagOpen(const char* tag, const bool newline)
5253
{
5354
tagOpen(tag, "", newline);
5455
}
5556

56-
void XMLWriter::tagOpen(char* tag, char* name, bool newline)
57+
void XMLWriter::tagOpen(const char* tag, const char* name, const bool newline)
5758
{
5859
// TODO STACK GUARD
5960
strncpy(tagStack[_idx++], tag, XMLWRITER_MAXTAGSIZE);
@@ -63,7 +64,7 @@ void XMLWriter::tagOpen(char* tag, char* name, bool newline)
6364
_indent += _indentStep;
6465
}
6566

66-
void XMLWriter::tagClose(bool ind)
67+
void XMLWriter::tagClose(const bool ind)
6768
{
6869
_indent -= _indentStep;
6970
if (ind) indent();
@@ -72,14 +73,14 @@ void XMLWriter::tagClose(bool ind)
7273
_stream->println(F(">"));
7374
}
7475

75-
void XMLWriter::tagStart(char *tag)
76+
void XMLWriter::tagStart(const char *tag)
7677
{
7778
indent();
7879
_stream->print('<');
7980
_stream->print(tag);
8081
}
8182

82-
void XMLWriter::tagField(char *field, char* str)
83+
void XMLWriter::tagField(const char *field, const char* str)
8384
{
8485
_stream->print(' ');
8586
_stream->print(field);
@@ -92,14 +93,14 @@ void XMLWriter::tagField(char *field, char* str)
9293
_stream->print('"');
9394
}
9495

95-
void XMLWriter::tagEnd(bool newline, bool addSlash)
96+
void XMLWriter::tagEnd(const bool newline, const bool addSlash)
9697
{
9798
if (addSlash) _stream->print('/');
9899
_stream->print('>');
99100
if (newline) _stream->println();
100101
}
101102

102-
void XMLWriter::writeNode(char* tag, char* str)
103+
void XMLWriter::writeNode(const char* tag, const char* str)
103104
{
104105
tagOpen(tag, "", NONEWLINE);
105106
#ifdef XMLWRITER_ESCAPE_SUPPORT
@@ -110,22 +111,22 @@ void XMLWriter::writeNode(char* tag, char* str)
110111
tagClose(NOINDENT);
111112
}
112113

113-
void XMLWriter::setIndentSize(uint8_t size)
114+
void XMLWriter::setIndentSize(const uint8_t size)
114115
{
115116
_indentStep = size;
116117
}
117118

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)
119120
{
120121
tagField(field, (uint32_t) value, base);
121122
}
122123

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)
124125
{
125126
tagField(field, (uint32_t) value, base);
126127
}
127128

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)
129130
{
130131
_stream->print(' ');
131132
_stream->print(field);
@@ -134,17 +135,17 @@ void XMLWriter::tagField(char *field, uint32_t value, uint8_t base)
134135
_stream->print('"');
135136
}
136137

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)
138139
{
139140
tagField(field, (long) value, base);
140141
}
141142

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)
143144
{
144145
tagField(field, (long) value, base);
145146
}
146147

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)
148149
{
149150
_stream->print(' ');
150151
_stream->print(field);
@@ -154,7 +155,7 @@ void XMLWriter::tagField(char *field, int32_t value, uint8_t base)
154155
}
155156

156157

157-
void XMLWriter::tagField(char *field, bool value)
158+
void XMLWriter::tagField(const char *field, const bool value)
158159
{
159160
_stream->print(' ');
160161
_stream->print(field);
@@ -163,7 +164,7 @@ void XMLWriter::tagField(char *field, bool value)
163164
_stream->print('"');
164165
}
165166

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)
167168
{
168169
_stream->print(' ');
169170
_stream->print(field);
@@ -172,48 +173,48 @@ void XMLWriter::tagField(char *field, double value, uint8_t decimals)
172173
_stream->print('"');
173174
}
174175

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)
176177
{
177178
writeNode(tag, (uint32_t) value, base);
178179
}
179180

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)
181182
{
182183
writeNode(tag, (uint32_t) value, base);
183184
}
184185

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)
186187
{
187188
tagOpen(tag, "", NONEWLINE);
188189
_stream->print(value, base); // todo: leading zero's
189190
tagClose(NOINDENT);
190191
}
191192

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)
193194
{
194195
writeNode(tag, (int32_t) value, base);
195196
}
196197

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)
198199
{
199200
writeNode(tag, (int32_t) value, base);
200201
}
201202

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)
203204
{
204205
tagOpen(tag, "", NONEWLINE);
205206
_stream->print(value, base); // todo: leading zero's
206207
tagClose(NOINDENT);
207208
}
208209

209-
void XMLWriter::writeNode(char* tag, bool value)
210+
void XMLWriter::writeNode(const char* tag, const bool value)
210211
{
211212
tagOpen(tag, "", NONEWLINE);
212213
_stream->print(value?F("true"):F("false"));
213214
tagClose(NOINDENT);
214215
}
215216

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)
217218
{
218219
tagOpen(tag, "", NONEWLINE);
219220
_stream->print(value, decimals);
@@ -231,9 +232,9 @@ void XMLWriter::indent()
231232
char c[6] = "\"\'<>&";
232233
char expanded[][7] = { "&quot;", "&apos;","&lt;","&gt;","&amp;"}; // todo in flash
233234

234-
void XMLWriter::escape(char* str)
235+
void XMLWriter::escape(const char* str)
235236
{
236-
char* p = str;
237+
char* p = (char *)str;
237238
while(*p != 0)
238239
{
239240
char* q = strchr(c, *p);

libraries/XMLWriter/XMLWriter.h

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
//
44
// FILE: XMLWriter.h
55
// AUTHOR: Rob Tillaart
6-
// VERSION: 0.1.6
6+
// VERSION: 0.1.7
77
// DATE: 2013-11-06
88
// PURPOSE: Simple XML writer library
99
//
@@ -13,7 +13,7 @@
1313
#include "Arduino.h"
1414
// no pre 1.0 support!
1515

16-
#define XMLWRITER_VERSION "0.1.6"
16+
#define XMLWRITER_VERSION "0.1.7"
1717

1818
// for comment()
1919
#define NOMULTILINE false
@@ -48,55 +48,55 @@ class XMLWriter
4848

4949
// if multiline == true it does not indent to allow bigger text blocks
5050
// <!-- text -->
51-
void comment(char* text, bool multiLine=false);
51+
void comment(const char* text, const bool multiLine=false);
5252

5353
// <tag>
54-
void tagOpen(char* tag, bool newline=true);
54+
void tagOpen(const char* tag, const bool newline=true);
5555
// <tag name="name">
56-
void tagOpen(char* tag, char* name, bool newline=true);
56+
void tagOpen(const char* tag, const char* name, const bool newline=true);
5757
// </tag>
58-
void tagClose(bool ind=true);
58+
void tagClose(const bool ind=true);
5959

6060
// <tag
61-
void tagStart(char* tag);
61+
void tagStart(const char* tag);
6262
// field="value"
63-
void tagField(char* field, char* value);
63+
void tagField(const char* field, const char* value);
6464
// />
65-
void tagEnd(bool newline=true, bool addSlash=true);
65+
void tagEnd(const bool newline=true, const bool addSlash=true);
6666

6767
// <tag>value</tag>
68-
void writeNode(char* tag, char* value);
68+
void writeNode(const char* tag, const char* value);
6969

7070
// typically 0,2,4; default == 2;
71-
void setIndentSize(uint8_t size = 2);
71+
void setIndentSize(const uint8_t size = 2);
7272

7373
// for manual layout control
7474
void incrIndent() { _indent += _indentStep; };
7575
void decrIndent() { _indent -= _indentStep; };
7676
void indent();
77-
void raw(char * str) { _stream->print(str); }; // TODO Q:other types?
78-
79-
void tagField(char* field, uint8_t value, uint8_t base=DEC);
80-
void tagField(char* field, uint16_t value, uint8_t base=DEC);
81-
void tagField(char* field, uint32_t value, uint8_t base=DEC);
82-
void tagField(char* field, int8_t value, uint8_t base=DEC);
83-
void tagField(char* field, int16_t value, uint8_t base=DEC);
84-
void tagField(char* field, int32_t value, uint8_t base=DEC);
85-
void tagField(char *field, bool value);
86-
void tagField(char* field, double value, uint8_t decimals=2);
87-
88-
void writeNode(char* tag, uint8_t value, uint8_t base=DEC);
89-
void writeNode(char* tag, uint16_t value, uint8_t base=DEC);
90-
void writeNode(char* tag, uint32_t value, uint8_t base=DEC);
91-
void writeNode(char* tag, int8_t value, uint8_t base=DEC);
92-
void writeNode(char* tag, int16_t value, uint8_t base=DEC);
93-
void writeNode(char* tag, int32_t value, uint8_t base=DEC);
94-
void writeNode(char* tag, bool value);
95-
void writeNode(char* tag, double value, uint8_t decimals=2);
77+
void raw(const char * str) { _stream->print(str); }; // TODO Q:other types?
78+
79+
void tagField(const char* field, const uint8_t value, const uint8_t base=DEC);
80+
void tagField(const char* field, const uint16_t value, const uint8_t base=DEC);
81+
void tagField(const char* field, const uint32_t value, const uint8_t base=DEC);
82+
void tagField(const char* field, const int8_t value, const uint8_t base=DEC);
83+
void tagField(const char* field, const int16_t value, const uint8_t base=DEC);
84+
void tagField(const char* field, const int32_t value, const uint8_t base=DEC);
85+
void tagField(const char *field, const bool value);
86+
void tagField(const char* field, const double value, const uint8_t decimals=2);
87+
88+
void writeNode(const char* tag, const uint8_t value, const uint8_t base=DEC);
89+
void writeNode(const char* tag, const uint16_t value, const uint8_t base=DEC);
90+
void writeNode(const char* tag, const uint32_t value, const uint8_t base=DEC);
91+
void writeNode(const char* tag, const int8_t value, const uint8_t base=DEC);
92+
void writeNode(const char* tag, const int16_t value, const uint8_t base=DEC);
93+
void writeNode(const char* tag, const int32_t value, const uint8_t base=DEC);
94+
void writeNode(const char* tag, const bool value);
95+
void writeNode(const char* tag, const double value, const uint8_t decimals=2);
9696

9797
#ifdef XMLWRITER_ESCAPE_SUPPORT
9898
// expands the special xml chars
99-
void escape(char* str);
99+
void escape(const char* str);
100100
#endif
101101

102102
private:

libraries/XMLWriter/examples/XMLWriterTest/XMLWriterTest.ino

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//
22
// FILE: XMLWriterTest.ino
33
// AUTHOR: Rob Tillaart
4-
// VERSION: 0.1.02
4+
// VERSION: 0.1.03
55
// PURPOSE: make a simple XML generating lib
66
// DATE: 2013-11-06
77
// URL:
@@ -66,7 +66,7 @@ void Weather()
6666
XML.tagClose();
6767
}
6868

69-
void AnalogPorts(char* name)
69+
void AnalogPorts(const char* name)
7070
{
7171
XML.comment("The analog ports are multiplexed");
7272
XML.tagOpen("Analog", name);
@@ -115,4 +115,4 @@ void DataTypes()
115115

116116
void loop()
117117
{
118-
}
118+
}

libraries/XMLWriter/keywords.txt

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#######################################
2+
# Syntax Coloring Map For XMLWriter
3+
#######################################
4+
5+
#######################################
6+
# Datatypes (KEYWORD1)
7+
#######################################
8+
9+
XMLWriter KEYWORD1
10+
11+
#######################################
12+
# Methods and Functions (KEYWORD2)
13+
#######################################
14+
15+
reset KEYWORD2
16+
header KEYWORD2
17+
comment KEYWORD2
18+
tagOpen KEYWORD2
19+
tagClose KEYWORD2
20+
tagStart KEYWORD2
21+
tagField KEYWORD2
22+
tagEnd KEYWORD2
23+
writeNode KEYWORD2
24+
setIndentSize KEYWORD2
25+
incrIndent KEYWORD2
26+
decrIndent KEYWORD2
27+
indent KEYWORD2
28+
raw KEYWORD2
29+
escape KEYWORD2
30+
31+
#######################################
32+
# Instances (KEYWORD2)
33+
#######################################
34+
35+
36+
#######################################
37+
# Constants (LITERAL1)
38+
#######################################
39+
40+
NOMULTILINE LITERAL1
41+
MULTILINE LITERAL1
42+
NEWLINE LITERAL1
43+
NONEWLINE LITERAL1
44+
NOINDENT LITERAL1
45+
SLASH LITERAL1
46+
NOSLASH LITERAL1

0 commit comments

Comments
 (0)