Fix WS2812 led definition
[inav.git] / src / main / common / string_light.c
blobc4dd795ac3628f39d492da28d91d4db2b5bbe8af
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_light.h"
21 #include "typeconversion.h"
23 int sl_isalnum(int c)
25 return sl_isdigit(c) || sl_isupper(c) || sl_islower(c);
28 int sl_isdigit(int c)
30 return (c >= '0' && c <= '9');
33 int sl_isupper(int c)
35 return (c >= 'A' && c <= 'Z');
38 int sl_islower(int c)
40 return (c >= 'a' && c <= 'z');
43 int sl_tolower(int c)
45 return sl_isupper(c) ? (c) - 'A' + 'a' : c;
48 int sl_toupper(int c)
50 return sl_islower(c) ? (c) - 'a' + 'A' : c;
53 int sl_strcasecmp(const char * s1, const char * s2)
55 return sl_strncasecmp(s1, s2, INT_MAX);
58 int sl_strncasecmp(const char * s1, const char * s2, int n)
60 const unsigned char * ucs1 = (const unsigned char *) s1;
61 const unsigned char * ucs2 = (const unsigned char *) s2;
63 int d = 0;
65 for ( ; n != 0; n--) {
66 const int c1 = sl_tolower(*ucs1++);
67 const int c2 = sl_tolower(*ucs2++);
68 if (((d = c1 - c2) != 0) || (c2 == '\0')) {
69 break;
73 return d;