AceCommon
1.1.2
Arduino library for low-level common functions and features with no external dependencies
src
pstrings
pstrings.cpp
1
/*
2
MIT License
3
4
Copyright (c) 2018, 2020 Brian T. Park
5
6
Permission is hereby granted, free of charge, to any person obtaining a copy
7
of this software and associated documentation files (the "Software"), to deal
8
in the Software without restriction, including without limitation the rights
9
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
copies of the Software, and to permit persons to whom the Software is
11
furnished to do so, subject to the following conditions:
12
13
The above copyright notice and this permission notice shall be included in all
14
copies or substantial portions of the Software.
15
16
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
SOFTWARE.
23
*/
24
25
#include <stdint.h>
26
#include <Arduino.h>
27
#include "
pstrings.h
"
28
29
namespace
ace_common {
30
31
int
strcmp_PP(
const
char
* a,
const
char
* b) {
32
if
(a == b) {
return
0; }
33
if
(a ==
nullptr
) {
return
-1; }
34
if
(b ==
nullptr
) {
return
1; }
35
36
while
(
true
) {
37
uint8_t ca = pgm_read_byte(a);
38
uint8_t cb = pgm_read_byte(b);
39
if
(ca != cb)
return
(
int
) ca - (int) cb;
40
if
(ca ==
'\0'
)
return
0;
41
a++;
42
b++;
43
}
44
}
45
46
#if defined(ESP8266) || defined(ESP32)
47
48
const
char
* strchr_P(
const
char
* s,
int
c) {
49
char
cc = c;
50
while
(
true
) {
51
char
d = pgm_read_byte(s);
52
if
(cc == d)
return
s;
53
if
(!d)
return
nullptr
;
54
s++;
55
}
56
}
57
58
const
char
* strrchr_P(
const
char
* s,
int
c) {
59
char
cc = c;
60
const
char
* found =
nullptr
;
61
while
(
true
) {
62
char
d = pgm_read_byte(s);
63
if
(cc == d) found = s;
64
if
(!d)
break
;
65
s++;
66
}
67
return
found;
68
}
69
70
#endif
71
72
}
pstrings.h
Generated by
1.8.17