2 * This file is part of Cleanflight and Betaflight.
4 * Cleanflight and Betaflight are free software. You can redistribute
5 * this software and/or modify this software under the terms of the
6 * GNU General Public License as published by the Free Software
7 * Foundation, either version 3 of the License, or (at your option)
10 * Cleanflight and Betaflight are distributed in the hope that they
11 * will be useful, but WITHOUT ANY WARRANTY; without even the implied
12 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 * See the GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this software.
18 * If not, see <http://www.gnu.org/licenses/>.
27 #include "typeconversion.h"
31 return isdigit(c
) || isupper(c
) || islower(c
);
36 return (c
>= '0' && c
<= '9');
41 return (c
>= 'A' && c
<= 'Z');
46 return (c
>= 'a' && c
<= 'z');
51 return (c
== ' ' || c
== '\t' || c
== '\n' || c
== '\r' || c
== '\f' || c
== '\v');
56 return isupper(c
) ? (c
) - 'A' + 'a' : c
;
61 return islower(c
) ? (c
) - 'a' + 'A' : c
;
64 int strcasecmp(const char * s1
, const char * s2
)
66 return strncasecmp(s1
, s2
, (size_t)INT_MAX
);
69 int strncasecmp(const char * s1
, const char * s2
, size_t n
)
71 const unsigned char * ucs1
= (const unsigned char *) s1
;
72 const unsigned char * ucs2
= (const unsigned char *) s2
;
76 for ( ; n
!= 0; n
--) {
77 const int c1
= tolower(*ucs1
++);
78 const int c2
= tolower(*ucs2
++);
79 if (((d
= c1
- c2
) != 0) || (c2
== '\0')) {
87 char *strcasestr(const char *haystack
, const char *needle
)
89 int nLen
= strlen(needle
);
91 if (!strncasecmp(haystack
, needle
, nLen
)) {
92 return (char *)haystack
;