Browse Source

Merge pull request #331 from FrankBoesing/stream-find-fix

Stream find Bugfix
main
Paul Stoffregen 5 years ago
parent
commit
2008540dd9
No account linked to committer's email address
2 changed files with 12 additions and 5 deletions
  1. +5
    -2
      teensy3/Stream.cpp
  2. +7
    -3
      teensy4/Stream.cpp

+ 5
- 2
teensy3/Stream.cpp View File

// as find but search ends if the terminator string is found // as find but search ends if the terminator string is found
bool Stream::findUntil(const char *target, const char *terminator) bool Stream::findUntil(const char *target, const char *terminator)
{ {
if(target == NULL) return true;
if(terminator == NULL) return true;
return findUntil(target, strlen(target), terminator, strlen(terminator)); return findUntil(target, strlen(target), terminator, strlen(terminator));
} }


size_t index = 0; // maximum target string length is 64k bytes! size_t index = 0; // maximum target string length is 64k bytes!
size_t termIndex = 0; size_t termIndex = 0;
int c; int c;
if( target == NULL) return true;
if( *target == 0) return true; // return true if target is a null string
if(terminator == NULL) return true;


if( *target == 0)
return true; // return true if target is a null string
while( (c = timedRead()) > 0){ while( (c = timedRead()) > 0){
if( c == target[index]){ 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);

+ 7
- 3
teensy4/Stream.cpp View File



// find returns true if the target string is found // find returns true if the target string is found
bool Stream::find(const char *target) bool Stream::find(const char *target)
{
{
return findUntil(target, NULL); return findUntil(target, NULL);
} }


// as find but search ends if the terminator string is found // as find but search ends if the terminator string is found
bool Stream::findUntil(const char *target, const char *terminator) bool Stream::findUntil(const char *target, const char *terminator)
{ {
if(target == NULL) return true;
if(terminator == NULL) return true;
return findUntil(target, strlen(target), terminator, strlen(terminator)); return findUntil(target, strlen(target), terminator, strlen(terminator));
} }


size_t termIndex = 0; size_t termIndex = 0;
int c; int c;


if( *target == 0)
return true; // return true if target is a null string
if( target == NULL) return true;
if( *target == 0) return true; // return true if target is a null string
if(terminator == NULL) return true;
while( (c = timedRead()) > 0){ while( (c = timedRead()) > 0){
if( c == target[index]){ 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);

Loading…
Cancel
Save