[gnoduino: 229/237] Fixing findUntil() problem with repeated initial characters. (Jeffery.zksun)
- From: Lucian Langa <lucilanga src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnoduino: 229/237] Fixing findUntil() problem with repeated initial characters. (Jeffery.zksun)
- Date: Sat, 31 Mar 2012 20:34:05 +0000 (UTC)
commit 7a5c1d79c9f66a5a859facc03e39775a1f5ccea3
Author: David A. Mellis <d mellis arduino cc>
Date: Mon Jan 2 13:49:59 2012 -0500
Fixing findUntil() problem with repeated initial characters. (Jeffery.zksun)
http://code.google.com/p/arduino/issues/detail?id=768
arduino/cores/arduino/Stream.cpp | 20 +++++++++++---------
1 files changed, 11 insertions(+), 9 deletions(-)
---
diff --git a/arduino/cores/arduino/Stream.cpp b/arduino/cores/arduino/Stream.cpp
index 5fad8dd..3d5b905 100644
--- a/arduino/cores/arduino/Stream.cpp
+++ b/arduino/cores/arduino/Stream.cpp
@@ -99,25 +99,27 @@ bool Stream::findUntil(char *target, size_t targetLen, char *terminator, size_t
size_t index = 0; // maximum target string length is 64k bytes!
size_t termIndex = 0;
int c;
-
+
if( *target == 0)
- return true; // return true if target is a null string
+ return true; // return true if target is a null string
while( (c = timedRead()) > 0){
+
+ if(c != target[index])
+ index = 0; // reset index if any char does not match
+
if( c == target[index]){
- //////Serial.print("found "); Serial.write(c); Serial.print("index now"); Serial.println(index+1);
+ //////Serial.print("found "); Serial.write(c); Serial.print("index now"); Serial.println(index+1);
if(++index >= targetLen){ // return true if all chars in the target match
return true;
}
}
- else{
- index = 0; // reset index if any char does not match
- }
+
if(termLen > 0 && c == terminator[termIndex]){
- if(++termIndex >= termLen)
- return false; // return false if terminate string found before target string
+ if(++termIndex >= termLen)
+ return false; // return false if terminate string found before target string
}
else
- termIndex = 0;
+ termIndex = 0;
}
return false;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]