|
|
|
|
|
|
|
|
// 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; |
|
|
|
|
|
size_t tlen = (terminator==NULL)?0:strlen(terminator); |
|
|
|
|
|
|
|
|
if(target == nullptr) return true; |
|
|
|
|
|
size_t tlen = (terminator==nullptr)?0:strlen(terminator); |
|
|
return findUntil(target, strlen(target), terminator, tlen); |
|
|
return findUntil(target, strlen(target), terminator, tlen); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
size_t termIndex = 0; |
|
|
size_t termIndex = 0; |
|
|
int c; |
|
|
int c; |
|
|
|
|
|
|
|
|
if( target == NULL) return true; |
|
|
|
|
|
|
|
|
if( target == nullptr) return true; |
|
|
if( *target == 0) return true; // return true if target is a null string |
|
|
if( *target == 0) return true; // return true if target is a null string |
|
|
if (terminator == NULL) termLen = 0; |
|
|
|
|
|
|
|
|
if (terminator == nullptr) termLen = 0; |
|
|
|
|
|
|
|
|
while( (c = timedRead()) > 0){ |
|
|
while( (c = timedRead()) > 0){ |
|
|
if( c == target[index]){ |
|
|
if( c == target[index]){ |
|
|
|
|
|
|
|
|
// |
|
|
// |
|
|
size_t Stream::readBytes(char *buffer, size_t length) |
|
|
size_t Stream::readBytes(char *buffer, size_t length) |
|
|
{ |
|
|
{ |
|
|
|
|
|
if (buffer == nullptr) return 0; |
|
|
size_t count = 0; |
|
|
size_t count = 0; |
|
|
while (count < length) { |
|
|
while (count < length) { |
|
|
int c = timedRead(); |
|
|
int c = timedRead(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
size_t Stream::readBytesUntil(char terminator, char *buffer, size_t length) |
|
|
size_t Stream::readBytesUntil(char terminator, char *buffer, size_t length) |
|
|
{ |
|
|
{ |
|
|
|
|
|
if (buffer == nullptr) return 0; |
|
|
if (length < 1) return 0; |
|
|
if (length < 1) return 0; |
|
|
length--; |
|
|
length--; |
|
|
size_t index = 0; |
|
|
size_t index = 0; |