Blackbox device type 'file' (SITL) considered working when file handler is available
[inav.git] / src / main / common / string_light.c
blobb99dbe7581cf63cb8e44be3eddfa264f0eabf477
1 /*
2 * This file is part of INAV.
4 * INAV is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * INAV is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with INAV. If not, see <http://www.gnu.org/licenses/>.
18 #include <limits.h>
20 #include "string.h"
21 #include "string_light.h"
22 #include "typeconversion.h"
24 int sl_isalnum(int c)
26 return sl_isdigit(c) || sl_isupper(c) || sl_islower(c);
29 int sl_isdigit(int c)
31 return (c >= '0' && c <= '9');
34 int sl_isupper(int c)
36 return (c >= 'A' && c <= 'Z');
39 int sl_islower(int c)
41 return (c >= 'a' && c <= 'z');
44 int sl_tolower(int c)
46 return sl_isupper(c) ? (c) - 'A' + 'a' : c;
49 int sl_toupper(int c)
51 return sl_islower(c) ? (c) - 'a' + 'A' : c;
54 void sl_toupperptr(char * c)
56 for (unsigned int i = 0; i < strlen(c); i++) {
57 if (c[i] >= 'a' && c[i] <= 'z') {
58 c[i] = c[i] - 'a' + 'A';
63 int sl_strcasecmp(const char * s1, const char * s2)
65 return sl_strncasecmp(s1, s2, INT_MAX);
68 int sl_strncasecmp(const char * s1, const char * s2, int n)
70 const unsigned char * ucs1 = (const unsigned char *) s1;
71 const unsigned char * ucs2 = (const unsigned char *) s2;
73 int d = 0;
75 for ( ; n != 0; n--) {
76 const int c1 = sl_tolower(*ucs1++);
77 const int c2 = sl_tolower(*ucs2++);
78 if (((d = c1 - c2) != 0) || (c2 == '\0')) {
79 break;
83 return d;