Skip to content

Commit 1ebf4cd

Browse files
bblanchonfacchinm
authored andcommitted
Use const pointer in Stream::find() and Stream::findUntil()
1 parent ca41f33 commit 1ebf4cd

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

api/Stream.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -90,28 +90,28 @@ void Stream::setTimeout(unsigned long timeout) // sets the maximum number of mi
9090
}
9191

9292
// find returns true if the target string is found
93-
bool Stream::find(char *target)
93+
bool Stream::find(const char *target)
9494
{
9595
return findUntil(target, strlen(target), NULL, 0);
9696
}
9797

9898
// reads data from the stream until the target string of given length is found
9999
// returns true if target string is found, false if timed out
100-
bool Stream::find(char *target, size_t length)
100+
bool Stream::find(const char *target, size_t length)
101101
{
102102
return findUntil(target, length, NULL, 0);
103103
}
104104

105105
// as find but search ends if the terminator string is found
106-
bool Stream::findUntil(char *target, char *terminator)
106+
bool Stream::findUntil(const char *target, const char *terminator)
107107
{
108108
return findUntil(target, strlen(target), terminator, strlen(terminator));
109109
}
110110

111111
// reads data from the stream until the target string of the given length is found
112112
// search terminated if the terminator string is found
113113
// returns true if target string is found, false if terminated or timed out
114-
bool Stream::findUntil(char *target, size_t targetLen, char *terminator, size_t termLen)
114+
bool Stream::findUntil(const char *target, size_t targetLen, const char *terminator, size_t termLen)
115115
{
116116
if (terminator == NULL) {
117117
MultiTarget t[1] = {{target, targetLen, 0}};

api/Stream.h

+8-8
Original file line numberDiff line numberDiff line change
@@ -67,21 +67,21 @@ class Stream : public Print
6767
void setTimeout(unsigned long timeout); // sets maximum milliseconds to wait for stream data, default is 1 second
6868
unsigned long getTimeout(void) { return _timeout; }
6969

70-
bool find(char *target); // reads data from the stream until the target string is found
71-
bool find(uint8_t *target) { return find ((char *)target); }
70+
bool find(const char *target); // reads data from the stream until the target string is found
71+
bool find(const uint8_t *target) { return find ((const char *)target); }
7272
// returns true if target string is found, false if timed out (see setTimeout)
7373

74-
bool find(char *target, size_t length); // reads data from the stream until the target string of given length is found
75-
bool find(uint8_t *target, size_t length) { return find ((char *)target, length); }
74+
bool find(const char *target, size_t length); // reads data from the stream until the target string of given length is found
75+
bool find(const uint8_t *target, size_t length) { return find ((const char *)target, length); }
7676
// returns true if target string is found, false if timed out
7777

7878
bool find(char target) { return find (&target, 1); }
7979

80-
bool findUntil(char *target, char *terminator); // as find but search ends if the terminator string is found
81-
bool findUntil(uint8_t *target, char *terminator) { return findUntil((char *)target, terminator); }
80+
bool findUntil(const char *target, const char *terminator); // as find but search ends if the terminator string is found
81+
bool findUntil(const uint8_t *target, const char *terminator) { return findUntil((const char *)target, terminator); }
8282

83-
bool findUntil(char *target, size_t targetLen, char *terminate, size_t termLen); // as above but search ends if the terminate string is found
84-
bool findUntil(uint8_t *target, size_t targetLen, char *terminate, size_t termLen) {return findUntil((char *)target, targetLen, terminate, termLen); }
83+
bool findUntil(const char *target, size_t targetLen, const char *terminate, size_t termLen); // as above but search ends if the terminate string is found
84+
bool findUntil(const uint8_t *target, size_t targetLen, const char *terminate, size_t termLen) {return findUntil((const char *)target, targetLen, terminate, termLen); }
8585

8686
long parseInt(LookaheadMode lookahead = SKIP_ALL, char ignore = NO_IGNORE_CHAR);
8787
// returns the first valid (long) integer value from the current position.

0 commit comments

Comments
 (0)