Skip to content

Commit 1953b60

Browse files
committed
Fixing findUntil() problem with repeated initial characters. (Jeffery.zksun)
http://code.google.com/p/arduino/issues/detail?id=768
1 parent 79cbec0 commit 1953b60

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

hardware/arduino/cores/arduino/Stream.cpp

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -99,25 +99,27 @@ bool Stream::findUntil(char *target, size_t targetLen, char *terminator, size_t
9999
size_t index = 0; // maximum target string length is 64k bytes!
100100
size_t termIndex = 0;
101101
int c;
102-
102+
103103
if( *target == 0)
104-
return true; // return true if target is a null string
104+
return true; // return true if target is a null string
105105
while( (c = timedRead()) > 0){
106+
107+
if(c != target[index])
108+
index = 0; // reset index if any char does not match
109+
106110
if( c == target[index]){
107-
//////Serial.print("found "); Serial.write(c); Serial.print("index now"); Serial.println(index+1);
111+
//////Serial.print("found "); Serial.write(c); Serial.print("index now"); Serial.println(index+1);
108112
if(++index >= targetLen){ // return true if all chars in the target match
109113
return true;
110114
}
111115
}
112-
else{
113-
index = 0; // reset index if any char does not match
114-
}
116+
115117
if(termLen > 0 && c == terminator[termIndex]){
116-
if(++termIndex >= termLen)
117-
return false; // return false if terminate string found before target string
118+
if(++termIndex >= termLen)
119+
return false; // return false if terminate string found before target string
118120
}
119121
else
120-
termIndex = 0;
122+
termIndex = 0;
121123
}
122124
return false;
123125
}

0 commit comments

Comments
 (0)