1
1
/*
2
- Copyright (c) 2014 Arduino. All right reserved.
2
+ Stream.cpp - adds parsing methods to Stream class
3
+ Copyright (c) 2008 David A. Mellis. All right reserved.
3
4
4
- This library is free software; you can redistribute it and/or
5
- modify it under the terms of the GNU Lesser General Public
6
- License as published by the Free Software Foundation; either
7
- version 2.1 of the License, or (at your option) any later version.
5
+ This library is free software; you can redistribute it and/or
6
+ modify it under the terms of the GNU Lesser General Public
7
+ License as published by the Free Software Foundation; either
8
+ version 2.1 of the License, or (at your option) any later version.
8
9
9
- This library is distributed in the hope that it will be useful,
10
- but WITHOUT ANY WARRANTY; without even the implied warranty of
11
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12
- See the GNU Lesser General Public License for more details.
10
+ This library is distributed in the hope that it will be useful,
11
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13
+ Lesser General Public License for more details.
13
14
14
- You should have received a copy of the GNU Lesser General Public
15
- License along with this library; if not, write to the Free Software
16
- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17
- */
15
+ You should have received a copy of the GNU Lesser General Public
16
+ License along with this library; if not, write to the Free Software
17
+ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18
+
19
+ Created July 2011
20
+ parsing functions based on TextFinder library by Michael Margolis
21
+ */
18
22
19
23
#include " Arduino.h"
20
24
#include " Stream.h"
@@ -71,7 +75,7 @@ void Stream::setTimeout(unsigned long timeout) // sets the maximum number of mi
71
75
// find returns true if the target string is found
72
76
bool Stream::find (char *target)
73
77
{
74
- return findUntil (target, " " );
78
+ return findUntil (target, ( char *) " " );
75
79
}
76
80
77
81
// reads data from the stream until the target string of given length is found
@@ -95,21 +99,21 @@ bool Stream::findUntil(char *target, size_t targetLen, char *terminator, size_t
95
99
size_t index = 0 ; // maximum target string length is 64k bytes!
96
100
size_t termIndex = 0 ;
97
101
int c;
98
-
102
+
99
103
if ( *target == 0 )
100
104
return true ; // return true if target is a null string
101
105
while ( (c = timedRead ()) > 0 ){
102
-
106
+
103
107
if (c != target[index])
104
108
index = 0 ; // reset index if any char does not match
105
-
109
+
106
110
if ( c == target[index]){
107
111
// ////Serial.print("found "); Serial.write(c); Serial.print("index now"); Serial.println(index+1);
108
112
if (++index >= targetLen){ // return true if all chars in the target match
109
113
return true ;
110
114
}
111
115
}
112
-
116
+
113
117
if (termLen > 0 && c == terminator[termIndex]){
114
118
if (++termIndex >= termLen)
115
119
return false ; // return false if terminate string found before target string
0 commit comments