ソースを参照

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

Stream find fix handle more cases
main
Paul Stoffregen 5年前
コミット
c1b42a3b2c
コミッターのメールアドレスに関連付けられたアカウントが存在しません
2個のファイルの変更13行の追加9行の削除
  1. +6
    -4
      teensy3/Stream.cpp
  2. +7
    -5
      teensy4/Stream.cpp

+ 6
- 4
teensy3/Stream.cpp ファイルの表示

@@ -89,8 +89,8 @@ bool Stream::find(const char *target, size_t length)
// as find but search ends if the terminator string is found
bool Stream::findUntil(const char *target, const char *terminator)
{
if(target == NULL) return true;
if(terminator == NULL) return true;
if(target == nullptr) return true;
size_t tlen = (terminator==nullptr)?0:strlen(terminator);
return findUntil(target, strlen(target), terminator, strlen(terminator));
}

@@ -102,9 +102,9 @@ bool Stream::findUntil(const char *target, size_t targetLen, const char *termina
size_t index = 0; // maximum target string length is 64k bytes!
size_t termIndex = 0;
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(terminator == NULL) return true;
if (terminator == nullptr) termLen = 0;

while( (c = timedRead()) > 0){
if( c == target[index]){
@@ -218,6 +218,7 @@ float Stream::parseFloat(char skipChar){
//
size_t Stream::readBytes(char *buffer, size_t length)
{
if (buffer == nullptr) return 0;
size_t count = 0;
while (count < length) {
int c = timedRead();
@@ -238,6 +239,7 @@ size_t Stream::readBytes(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;
length--;
size_t index = 0;

+ 7
- 5
teensy4/Stream.cpp ファイルの表示

@@ -89,9 +89,9 @@ bool Stream::find(const char *target, size_t length)
// as find but search ends if the terminator string is found
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));
if(target == nullptr) return true;
size_t tlen = (terminator==nullptr)?0:strlen(terminator);
return findUntil(target, strlen(target), terminator, tlen);
}

// reads data from the stream until the target string of the given length is found
@@ -103,9 +103,9 @@ bool Stream::findUntil(const char *target, size_t targetLen, const char *termina
size_t termIndex = 0;
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(terminator == NULL) return true;
if (terminator == nullptr) termLen = 0;
while( (c = timedRead()) > 0){
if( c == target[index]){
@@ -219,6 +219,7 @@ float Stream::parseFloat(char skipChar){
//
size_t Stream::readBytes(char *buffer, size_t length)
{
if (buffer == nullptr) return 0;
size_t count = 0;
while (count < length) {
int c = timedRead();
@@ -239,6 +240,7 @@ size_t Stream::readBytes(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;
length--;
size_t index = 0;

読み込み中…
キャンセル
保存