diff --git a/include/ctype.h b/include/ctype.h index d3d62b53fd..49cc47f030 100644 --- a/include/ctype.h +++ b/include/ctype.h @@ -1,7 +1,7 @@ /**************************************************************************** * include/ctype.h * - * Copyright (C) 2007-2009, 2011, 2014 Gregory Nutt. All rights reserved. + * Copyright (C) 2007-2009, 2011, 2014, 2016 Gregory Nutt. All rights reserved. * Author: Gregory Nutt * * Redistribution and use in source and binary forms, with or without @@ -45,6 +45,8 @@ * Included Files ****************************************************************************/ +#include + /**************************************************************************** * Pre-processor Definitions ****************************************************************************/ @@ -59,9 +61,17 @@ * ****************************************************************************/ -#define isspace(c) \ - ((c) == ' ' || (c) == '\t' || (c) == '\n' || \ - (c) == '\r' || (c) == '\f' || c== '\v') +#if defined(CONFIG_HAVE_INLINE) || defined(__cplusplus) +static inline int isspace(int c) +{ + return c == ' ' || c == '\t' || c == '\n' || c == '\r' || + c == '\f' || c == '\v'; +} +#else +# define isspace(c) \ + ((c) == ' ' || (c) == '\t' || (c) == '\n' || (c) == '\r' || \ + (c) == '\f' || c== '\v') +#endif /**************************************************************************** * Name: isascii @@ -72,7 +82,14 @@ * ****************************************************************************/ -#define isascii(c) ((c) >= 0 && (c) <= 0x7f) +#if defined(CONFIG_HAVE_INLINE) || defined(__cplusplus) +static inline int isascii(int c) +{ + return c >= 0 && c <= 0x7f; +} +#else +# define isascii(c) ((c) >= 0 && (c) <= 0x7f) +#endif /**************************************************************************** * Name: isprint @@ -82,7 +99,14 @@ * ****************************************************************************/ -#define isprint(c) ((c) >= 0x20 && (c) < 0x7f) +#if defined(CONFIG_HAVE_INLINE) || defined(__cplusplus) +static inline int isprint(int c) +{ + return c >= 0x20 && c < 0x7f; +} +#else +# define isprint(c) ((c) >= 0x20 && (c) < 0x7f) +#endif /**************************************************************************** * Name: isgraph @@ -92,7 +116,14 @@ * ****************************************************************************/ -#define isgraph(c) ((c) > 0x20 && (c) < 0x7f) +#if defined(CONFIG_HAVE_INLINE) || defined(__cplusplus) +static inline int isgraph(int c) +{ + return c > 0x20 && c < 0x7f; +} +#else +# define isgraph(c) ((c) > 0x20 && (c) < 0x7f) +#endif /**************************************************************************** * Name: iscntrl @@ -102,7 +133,14 @@ * ****************************************************************************/ -#define iscntrl(c) (!isprint(c)) +#if defined(CONFIG_HAVE_INLINE) || defined(__cplusplus) +static inline int iscntrl(int c) +{ + return !isprint(c); +} +#else +# define iscntrl(c) (!isprint(c)) +#endif /**************************************************************************** * Name: islower @@ -112,7 +150,14 @@ * ****************************************************************************/ -#define islower(c) ((c) >= 'a' && (c) <= 'z') +#if defined(CONFIG_HAVE_INLINE) || defined(__cplusplus) +static inline int islower(int c) +{ + return c >= 'a' && c <= 'z'; +} +#else +# define islower(c) ((c) >= 'a' && (c) <= 'z') +#endif /**************************************************************************** * Name: isupper @@ -122,7 +167,14 @@ * ****************************************************************************/ -#define isupper(c) ((c) >= 'A' && (c) <= 'Z') +#if defined(CONFIG_HAVE_INLINE) || defined(__cplusplus) +static inline int isupper(int c) +{ + return c >= 'A' && c <= 'Z'; +} +#else +# define isupper(c) ((c) >= 'A' && (c) <= 'Z') +#endif /**************************************************************************** * Name: isalpha @@ -132,17 +184,31 @@ * ****************************************************************************/ -#define isalpha(c) (islower(c) || isupper(c)) +#if defined(CONFIG_HAVE_INLINE) || defined(__cplusplus) +static inline int isalpha(int c) +{ + return islower(c) || isupper(c); +} +#else +# define isalpha(c) (islower(c) || isupper(c)) +#endif /**************************************************************************** * Name: isblank * * Description: - * Checks for blank characters (space or tab) + * Checks for blank characters (space or tab). C++11 * ****************************************************************************/ -#define isblank(c) (isspace(c) || (c) == '\t') +#if defined(CONFIG_HAVE_INLINE) || defined(__cplusplus) +static inline int isblank(int c) +{ + return c == ' ' || c == '\t'; +} +#else +# define isblank(c) ((c) == ' ' || (c) == '\t') +#endif /**************************************************************************** * Name: isdigit @@ -152,7 +218,14 @@ * ****************************************************************************/ -#define isdigit(c) ((c) >= '0' && (c) <= '9') +#if defined(CONFIG_HAVE_INLINE) || defined(__cplusplus) +static inline int isdigit(int c) +{ + return c >= '0' && c <= '9'; +} +#else +# define isdigit(c) ((c) >= '0' && (c) <= '9') +#endif /**************************************************************************** * Name: isalnum @@ -162,7 +235,14 @@ * ****************************************************************************/ -#define isalnum(c) (isalpha(c) || isdigit(c)) +#if defined(CONFIG_HAVE_INLINE) || defined(__cplusplus) +static inline int isalnum(int c) +{ + return isalpha(c) || isdigit(c); +} +#else +# define isalnum(c) (isalpha(c) || isdigit(c)) +#endif /**************************************************************************** * Name: ispunct @@ -173,7 +253,14 @@ * ****************************************************************************/ -#define ispunct(c) (isgraph(c) && !isalnum(c)) +#if defined(CONFIG_HAVE_INLINE) || defined(__cplusplus) +static inline int ispunct(int c) +{ + return isgraph(c) && !isalnum(c); +} +#else +# define ispunct(c) (isgraph(c) && !isalnum(c)) +#endif /**************************************************************************** * Name: isxdigit @@ -183,10 +270,19 @@ * ****************************************************************************/ -#define isxdigit(c) \ - (((c) >= '0' && (c) <= '9') || \ - ((c) >= 'a' && (c) <= 'f') || \ - ((c) >= 'A' && (c) <= 'F')) +#if defined(CONFIG_HAVE_INLINE) || defined(__cplusplus) +static inline int isxdigit(int c) +{ + return (c >= '0' && c <= '9') || + (c >= 'a' && c <= 'f') || + (c >= 'A' && c <= 'F'); +} +#else +# define isxdigit(c) \ + (((c) >= '0' && (c) <= '9') || \ + ((c) >= 'a' && (c) <= 'f') || \ + ((c) >= 'A' && (c) <= 'F')) +#endif /**************************************************************************** * Name: toupper @@ -196,8 +292,15 @@ * ****************************************************************************/ -#define toupper(c) \ - (((c) >= 'a' && (c) <= 'z') ? ((c) - 'a' + 'A') : (c)) +#if defined(CONFIG_HAVE_INLINE) || defined(__cplusplus) +static inline int toupper(int c) +{ + return (c >= 'a' && c <= 'z') ? c - 'a' + 'A' : c; +} +#else +# define toupper(c) \ + (((c) >= 'a' && (c) <= 'z') ? ((c) - 'a' + 'A') : (c)) +#endif /**************************************************************************** * Name: tolower @@ -207,8 +310,16 @@ * ****************************************************************************/ -#define tolower(c) \ - (((c) >= 'A' && (c) <= 'Z') ? ((c) - 'A' + 'a') : (c)) +#if defined(CONFIG_HAVE_INLINE) || defined(__cplusplus) +static inline int tolower(int c) +{ + return (c >= 'A' && c <= 'Z') ? (c - 'A' + 'a') : c; +} +#else +# define tolower(c) \ + (((c) >= 'A' && (c) <= 'Z') ? ((c) - 'A' + 'a') : (c)) +# define +#endif /**************************************************************************** * Public Type Definitions diff --git a/include/cxx/cctype b/include/cxx/cctype index 36b62ca8c5..52c4c86ba7 100644 --- a/include/cxx/cctype +++ b/include/cxx/cctype @@ -1,7 +1,7 @@ //*************************************************************************** // include/cxx/cctype // -// Copyright (C) 2009 Gregory Nutt. All rights reserved. +// Copyright (C) 2009, 2016 Gregory Nutt. All rights reserved. // Author: Gregory Nutt // // Redistribution and use in source and binary forms, with or without @@ -42,29 +42,27 @@ #include -// Remove macros in favor of builtin implementations - -#if !defined(CONFIG_UCLIBCXX) - -#undef isalnum -#undef isalpha -#undef iscntrl -#undef isdigit -#undef isgraph -#undef islower -#undef isprint -#undef ispunct -#undef isspace -#undef isblank -#undef isupper -#undef isxdigit -#undef tolower -#undef toupper - -#endif - //*************************************************************************** // Namespace //*************************************************************************** +namespace std +{ + using ::isspace; + using ::isascii; + using ::isprint; + using ::isgraph; + using ::iscntrl; + using ::islower; + using ::isupper; + using ::isalpha; + using ::isblank; + using ::isdigit; + using ::isalnum; + using ::ispunct; + using ::isxdigit; + using ::toupper; + using ::tolower; +} + #endif // __INCLUDE_CXX_CCTYPE