Skip to content

Commit 6f92ac5

Browse files
committed
move strrstr() to stdlib_noniso.h
1 parent fcd214b commit 6f92ac5

File tree

4 files changed

+37
-83
lines changed

4 files changed

+37
-83
lines changed

cores/esp8266/core_esp8266_noniso.cpp

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,4 +117,36 @@ char * dtostrf(double number, signed char width, unsigned char prec, char *s) {
117117
return s;
118118
}
119119

120+
/*
121+
strrstr (static)
122+
123+
Backwards search for p_pcPattern in p_pcString
124+
Based on: https://stackoverflow.com/a/1634398/2778898
125+
126+
*/
127+
const char* strrstr(const char*__restrict p_pcString,
128+
const char*__restrict p_pcPattern)
129+
{
130+
const char* pcResult = 0;
131+
132+
size_t stStringLength = (p_pcString ? strlen(p_pcString) : 0);
133+
size_t stPatternLength = (p_pcPattern ? strlen(p_pcPattern) : 0);
134+
135+
if ((stStringLength) &&
136+
(stPatternLength) &&
137+
(stPatternLength <= stStringLength))
138+
{
139+
// Pattern is shorter or has the same length than the string
140+
for (const char* s = (p_pcString + stStringLength - stPatternLength); s >= p_pcString; --s)
141+
{
142+
if (0 == strncmp(s, p_pcPattern, stPatternLength))
143+
{
144+
pcResult = s;
145+
break;
146+
}
147+
}
148+
}
149+
return pcResult;
150+
}
151+
120152
};

cores/esp8266/stdlib_noniso.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ char* dtostrf (double val, signed char width, unsigned char prec, char *s);
4444

4545
void reverse(char* begin, char* end);
4646

47+
const char* strrstr(const char*__restrict p_pcString,
48+
const char*__restrict p_pcPattern);
49+
4750
#ifdef __cplusplus
4851
} // extern "C"
4952
#endif

libraries/ESP8266mDNS/src/LEAmDNS2Host.cpp

Lines changed: 1 addition & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
#include <algorithm>
2626
#include <LwipIntf.h> // LwipIntf::stateUpCB()
27+
#include <stdlib_noniso.h> // strrstr()
2728

2829
#include "ESP8266mDNS.h"
2930
#include "LEAmDNS2Host.h"
@@ -46,45 +47,6 @@
4647
#define STRINGIZE_VALUE_OF(x) STRINGIZE(x)
4748
#endif
4849

49-
namespace // anonymous
50-
{
51-
52-
/*
53-
strrstr (static)
54-
55-
Backwards search for p_pcPattern in p_pcString
56-
Based on: https://stackoverflow.com/a/1634398/2778898
57-
58-
*/
59-
const char* strrstr(const char*__restrict p_pcString,
60-
const char*__restrict p_pcPattern)
61-
{
62-
const char* pcResult = 0;
63-
64-
size_t stStringLength = (p_pcString ? strlen(p_pcString) : 0);
65-
size_t stPatternLength = (p_pcPattern ? strlen(p_pcPattern) : 0);
66-
67-
if ((stStringLength) &&
68-
(stPatternLength) &&
69-
(stPatternLength <= stStringLength))
70-
{
71-
// Pattern is shorter or has the same length than the string
72-
for (const char* s = (p_pcString + stStringLength - stPatternLength); s >= p_pcString; --s)
73-
{
74-
if (0 == strncmp(s, p_pcPattern, stPatternLength))
75-
{
76-
pcResult = s;
77-
break;
78-
}
79-
}
80-
}
81-
return pcResult;
82-
}
83-
84-
85-
} // anonymous
86-
87-
8850
namespace esp8266
8951
{
9052

libraries/ESP8266mDNS/src/LEAmDNS_Helpers.cpp

Lines changed: 1 addition & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -23,55 +23,12 @@
2323
*/
2424

2525
#include <lwip/igmp.h>
26+
#include <stdlib_noniso.h> // strrstr()
2627

2728
#include "ESP8266mDNS.h"
2829
#include "LEAmDNS_lwIPdefs.h"
2930
#include "LEAmDNS_Priv.h"
3031

31-
32-
namespace
33-
{
34-
35-
/*
36-
strrstr (static)
37-
38-
Backwards search for p_pcPattern in p_pcString
39-
Based on: https://stackoverflow.com/a/1634398/2778898
40-
41-
*/
42-
const char* strrstr(const char*__restrict p_pcString, const char*__restrict p_pcPattern)
43-
{
44-
45-
const char* pcResult = 0;
46-
47-
size_t stStringLength = (p_pcString ? strlen(p_pcString) : 0);
48-
size_t stPatternLength = (p_pcPattern ? strlen(p_pcPattern) : 0);
49-
50-
if ((stStringLength) &&
51-
(stPatternLength) &&
52-
(stPatternLength <= stStringLength))
53-
{
54-
// Pattern is shorter or has the same length tham the string
55-
56-
for (const char* s = (p_pcString + stStringLength - stPatternLength); s >= p_pcString; --s)
57-
{
58-
if (0 == strncmp(s, p_pcPattern, stPatternLength))
59-
{
60-
pcResult = s;
61-
break;
62-
}
63-
}
64-
}
65-
return pcResult;
66-
}
67-
68-
69-
} // anonymous
70-
71-
72-
73-
74-
7532
namespace esp8266
7633
{
7734

0 commit comments

Comments
 (0)