1
0
Fork 0
mirror of https://github.com/betaflight/betaflight.git synced 2025-07-23 16:25:31 +03:00

Merge pull request #4653 from ledvinap/string_light

Use local implementation of some string functions
This commit is contained in:
Michael Keller 2017-11-26 02:04:30 +13:00 committed by GitHub
commit 9e06c65fc1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 55 additions and 43 deletions

View file

@ -13,6 +13,7 @@ COMMON_SRC = \
common/maths.c \
common/printf.c \
common/streambuf.c \
common/string_light.c \
common/time.c \
common/typeconversion.c \
config/config_eeprom.c \

View file

@ -16,46 +16,52 @@
*/
#include <limits.h>
#include <ctype.h>
#include <string.h>
#include "string_light.h"
#include "typeconversion.h"
int sl_isalnum(int c)
int isalnum(int c)
{
return sl_isdigit(c) || sl_isupper(c) || sl_islower(c);
return isdigit(c) || isupper(c) || islower(c);
}
int sl_isdigit(int c)
int isdigit(int c)
{
return (c >= '0' && c <= '9');
}
int sl_isupper(int c)
int isupper(int c)
{
return (c >= 'A' && c <= 'Z');
}
int sl_islower(int c)
int islower(int c)
{
return (c >= 'a' && c <= 'z');
}
int sl_tolower(int c)
int isspace(int c)
{
return sl_isupper(c) ? (c) - 'A' + 'a' : c;
return (c == ' ' || c == '\t' || c == '\n' || c == '\r' || c == '\f' || c == '\v');
}
int sl_toupper(int c)
int tolower(int c)
{
return sl_islower(c) ? (c) - 'a' + 'A' : c;
return isupper(c) ? (c) - 'A' + 'a' : c;
}
int sl_strcasecmp(const char * s1, const char * s2)
int toupper(int c)
{
return sl_strncasecmp(s1, s2, INT_MAX);
return islower(c) ? (c) - 'a' + 'A' : c;
}
int sl_strncasecmp(const char * s1, const char * s2, int n)
int strcasecmp(const char * s1, const char * s2)
{
return strncasecmp(s1, s2, (size_t)-1);
}
int strncasecmp(const char * s1, const char * s2, size_t n)
{
const unsigned char * ucs1 = (const unsigned char *) s1;
const unsigned char * ucs2 = (const unsigned char *) s2;
@ -63,8 +69,8 @@ int sl_strncasecmp(const char * s1, const char * s2, int n)
int d = 0;
for ( ; n != 0; n--) {
const int c1 = sl_tolower(*ucs1++);
const int c2 = sl_tolower(*ucs2++);
const int c1 = tolower(*ucs1++);
const int c2 = tolower(*ucs2++);
if (((d = c1 - c2) != 0) || (c2 == '\0')) {
break;
}

View file

@ -1,28 +0,0 @@
/*
* This file is part of Cleanflight.
*
* Cleanflight is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Cleanflight is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Cleanflight. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
int sl_isalnum(int c);
int sl_isdigit(int c);
int sl_isupper(int c);
int sl_islower(int c);
int sl_tolower(int c);
int sl_toupper(int c);
int sl_strcasecmp(const char * s1, const char * s2);
int sl_strncasecmp(const char * s1, const char * s2, int n);

33
src/main/ctype.h Normal file
View file

@ -0,0 +1,33 @@
/*
* Replacemnet for system header file <ctype.h> to avoid macro definitions
* Functions are implemented in common/string_light.c
*/
#ifdef __cplusplus
// use original implementation for C++
# include_next <ctype.h>
#endif
#ifndef _CTYPE_H_
#define _CTYPE_H_
#ifndef _EXFUN
# define _EXFUN(name,proto) name proto
#endif
int _EXFUN(isalnum, (int __c));
int _EXFUN(isalpha, (int __c));
int _EXFUN(iscntrl, (int __c));
int _EXFUN(isdigit, (int __c));
int _EXFUN(isgraph, (int __c));
int _EXFUN(islower, (int __c));
int _EXFUN(isprint, (int __c));
int _EXFUN(ispunct, (int __c));
int _EXFUN(isspace, (int __c));
int _EXFUN(isupper, (int __c));
int _EXFUN(isxdigit,(int __c));
int _EXFUN(tolower, (int __c));
int _EXFUN(toupper, (int __c));
int _EXFUN(isblank, (int __c));
#endif /* _CTYPE_H_ */