1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-06-23 19:21:59 +03:00

Updated Stream.cpp in SAM core to the latest version

This commit is contained in:
Cristian Maglie
2015-04-21 18:11:05 +02:00
parent c96c917dd0
commit c944a4c84d

View File

@ -254,9 +254,10 @@ String Stream::readStringUntil(char terminator)
int Stream::findMulti( struct Stream::MultiTarget *targets, int tCount) { int Stream::findMulti( struct Stream::MultiTarget *targets, int tCount) {
// any zero length target string automatically matches and would make // any zero length target string automatically matches and would make
// a mess of the rest of the algorithm. // a mess of the rest of the algorithm.
for (struct MultiTarget *t = targets; t < targets+tCount; ++t) for (struct MultiTarget *t = targets; t < targets+tCount; ++t) {
if (t->len <= 0) if (t->len <= 0)
return t - targets; return t - targets;
}
while (1) { while (1) {
int c = timedRead(); int c = timedRead();
@ -265,11 +266,12 @@ int Stream::findMulti( struct Stream::MultiTarget *targets, int tCount) {
for (struct MultiTarget *t = targets; t < targets+tCount; ++t) { for (struct MultiTarget *t = targets; t < targets+tCount; ++t) {
// the simple case is if we match, deal with that first. // the simple case is if we match, deal with that first.
if (c == t->str[t->index]) if (c == t->str[t->index]) {
if (++t->index == t->len) if (++t->index == t->len)
return t - targets; return t - targets;
else else
continue; continue;
}
// if not we need to walk back and see if we could have matched further // if not we need to walk back and see if we could have matched further
// down the stream (ie '1112' doesn't match the first position in '11112' // down the stream (ie '1112' doesn't match the first position in '11112'
@ -293,16 +295,19 @@ int Stream::findMulti( struct Stream::MultiTarget *targets, int tCount) {
// otherwise we need to check the rest of the found string // otherwise we need to check the rest of the found string
int diff = origIndex - t->index; int diff = origIndex - t->index;
int i; size_t i;
for (i = 0; i < t->index; ++i) for (i = 0; i < t->index; ++i) {
if (t->str[i] != t->str[i + diff]) if (t->str[i] != t->str[i + diff])
break; break;
}
// if we successfully got through the previous loop then our current // if we successfully got through the previous loop then our current
// index is good. // index is good.
if (i == t->index) { if (i == t->index) {
t->index++; t->index++;
break; break;
} }
// otherwise we just try the next index // otherwise we just try the next index
} while (t->index); } while (t->index);
} }