Skip to content

Commit e04d90c

Browse files
cousteaulecommandantfacchinm
authored andcommitted
Stream::readBytesUntil() with non-ASCII terminator
Allow Stream::readBytesUntil() and Stream::readStringUntil() use a negative value(i.e. a non-ASCII char) as a terminator. Replaces `[int] == [char]` comparisons with `(char)[int] == [char]`. Solves #1148
1 parent 893bcc5 commit e04d90c

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

api/Stream.cpp

+8-8
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ long Stream::parseInt(LookaheadMode lookahead, char ignore)
139139
return 0; // zero returned if timeout
140140

141141
do{
142-
if(c == ignore)
142+
if((char)c == ignore)
143143
; // ignore this character
144144
else if(c == '-')
145145
isNegative = true;
@@ -148,7 +148,7 @@ long Stream::parseInt(LookaheadMode lookahead, char ignore)
148148
read(); // consume the character we got with peek
149149
c = timedPeek();
150150
}
151-
while( (c >= '0' && c <= '9') || c == ignore );
151+
while( (c >= '0' && c <= '9') || (char)c == ignore );
152152

153153
if(isNegative)
154154
value = -value;
@@ -170,7 +170,7 @@ float Stream::parseFloat(LookaheadMode lookahead, char ignore)
170170
return 0; // zero returned if timeout
171171

172172
do{
173-
if(c == ignore)
173+
if((char)c == ignore)
174174
; // ignore
175175
else if(c == '-')
176176
isNegative = true;
@@ -184,7 +184,7 @@ float Stream::parseFloat(LookaheadMode lookahead, char ignore)
184184
read(); // consume the character we got with peek
185185
c = timedPeek();
186186
}
187-
while( (c >= '0' && c <= '9') || (c == '.' && !isFraction) || c == ignore );
187+
while( (c >= '0' && c <= '9') || (c == '.' && !isFraction) || (char)c == ignore );
188188

189189
if(isNegative)
190190
value = -value;
@@ -222,7 +222,7 @@ size_t Stream::readBytesUntil(char terminator, char *buffer, size_t length)
222222
size_t index = 0;
223223
while (index < length) {
224224
int c = timedRead();
225-
if (c < 0 || c == terminator) break;
225+
if (c < 0 || (char)c == terminator) break;
226226
*buffer++ = (char)c;
227227
index++;
228228
}
@@ -245,7 +245,7 @@ String Stream::readStringUntil(char terminator)
245245
{
246246
String ret;
247247
int c = timedRead();
248-
while (c >= 0 && c != terminator)
248+
while (c >= 0 && (char)c != terminator)
249249
{
250250
ret += (char)c;
251251
c = timedRead();
@@ -268,7 +268,7 @@ int Stream::findMulti( struct Stream::MultiTarget *targets, int tCount) {
268268

269269
for (struct MultiTarget *t = targets; t < targets+tCount; ++t) {
270270
// the simple case is if we match, deal with that first.
271-
if (c == t->str[t->index]) {
271+
if ((char)c == t->str[t->index]) {
272272
if (++t->index == t->len)
273273
return t - targets;
274274
else
@@ -286,7 +286,7 @@ int Stream::findMulti( struct Stream::MultiTarget *targets, int tCount) {
286286
do {
287287
--t->index;
288288
// first check if current char works against the new current index
289-
if (c != t->str[t->index])
289+
if ((char)c != t->str[t->index])
290290
continue;
291291

292292
// if it's the only char then we're good, nothing more to check

0 commit comments

Comments
 (0)