Merge pull request #11198 from SteveCEvans/sce_rc2
[betaflight.git] / src / main / common / string_light.c
blobba18f2d4a2aff712664f75d671b4c355157089aa
1 /*
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)
8 * any later version.
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/>.
21 #include <limits.h>
22 #include <ctype.h>
23 #include <string.h>
25 #include "platform.h"
27 #include "typeconversion.h"
29 int isalnum(int c)
31 return isdigit(c) || isupper(c) || islower(c);
34 int isdigit(int c)
36 return (c >= '0' && c <= '9');
39 int isupper(int c)
41 return (c >= 'A' && c <= 'Z');
44 int islower(int c)
46 return (c >= 'a' && c <= 'z');
49 int isspace(int c)
51 return (c == ' ' || c == '\t' || c == '\n' || c == '\r' || c == '\f' || c == '\v');
54 int tolower(int c)
56 return isupper(c) ? (c) - 'A' + 'a' : c;
59 int toupper(int 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;
74 int d = 0;
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')) {
80 break;
84 return d;
87 char *strcasestr(const char *haystack, const char *needle)
89 int nLen = strlen(needle);
90 do {
91 if (!strncasecmp(haystack, needle, nLen)) {
92 return (char *)haystack;
94 haystack++;
95 } while (*haystack);
96 return NULL;