Implement ctype.h functions as inline if possible. cctype can then properly select namespace.

This commit is contained in:
Gregory Nutt 2016-10-22 08:18:00 -06:00
parent 1e40e03c7f
commit c08cb7ddea
2 changed files with 155 additions and 46 deletions

View File

@ -1,7 +1,7 @@
/**************************************************************************** /****************************************************************************
* include/ctype.h * 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 <gnutt@nuttx.org> * Author: Gregory Nutt <gnutt@nuttx.org>
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@ -45,6 +45,8 @@
* Included Files * Included Files
****************************************************************************/ ****************************************************************************/
#include <nuttx/compiler.h>
/**************************************************************************** /****************************************************************************
* Pre-processor Definitions * Pre-processor Definitions
****************************************************************************/ ****************************************************************************/
@ -59,9 +61,17 @@
* *
****************************************************************************/ ****************************************************************************/
#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) \ # define isspace(c) \
((c) == ' ' || (c) == '\t' || (c) == '\n' || \ ((c) == ' ' || (c) == '\t' || (c) == '\n' || (c) == '\r' || \
(c) == '\r' || (c) == '\f' || c== '\v') (c) == '\f' || c== '\v')
#endif
/**************************************************************************** /****************************************************************************
* Name: isascii * Name: isascii
@ -72,7 +82,14 @@
* *
****************************************************************************/ ****************************************************************************/
#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) # define isascii(c) ((c) >= 0 && (c) <= 0x7f)
#endif
/**************************************************************************** /****************************************************************************
* Name: isprint * Name: isprint
@ -82,7 +99,14 @@
* *
****************************************************************************/ ****************************************************************************/
#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) # define isprint(c) ((c) >= 0x20 && (c) < 0x7f)
#endif
/**************************************************************************** /****************************************************************************
* Name: isgraph * Name: isgraph
@ -92,7 +116,14 @@
* *
****************************************************************************/ ****************************************************************************/
#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) # define isgraph(c) ((c) > 0x20 && (c) < 0x7f)
#endif
/**************************************************************************** /****************************************************************************
* Name: iscntrl * Name: iscntrl
@ -102,7 +133,14 @@
* *
****************************************************************************/ ****************************************************************************/
#if defined(CONFIG_HAVE_INLINE) || defined(__cplusplus)
static inline int iscntrl(int c)
{
return !isprint(c);
}
#else
# define iscntrl(c) (!isprint(c)) # define iscntrl(c) (!isprint(c))
#endif
/**************************************************************************** /****************************************************************************
* Name: islower * Name: islower
@ -112,7 +150,14 @@
* *
****************************************************************************/ ****************************************************************************/
#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') # define islower(c) ((c) >= 'a' && (c) <= 'z')
#endif
/**************************************************************************** /****************************************************************************
* Name: isupper * Name: isupper
@ -122,7 +167,14 @@
* *
****************************************************************************/ ****************************************************************************/
#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') # define isupper(c) ((c) >= 'A' && (c) <= 'Z')
#endif
/**************************************************************************** /****************************************************************************
* Name: isalpha * Name: isalpha
@ -132,17 +184,31 @@
* *
****************************************************************************/ ****************************************************************************/
#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)) # define isalpha(c) (islower(c) || isupper(c))
#endif
/**************************************************************************** /****************************************************************************
* Name: isblank * Name: isblank
* *
* Description: * 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 * Name: isdigit
@ -152,7 +218,14 @@
* *
****************************************************************************/ ****************************************************************************/
#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') # define isdigit(c) ((c) >= '0' && (c) <= '9')
#endif
/**************************************************************************** /****************************************************************************
* Name: isalnum * Name: isalnum
@ -162,7 +235,14 @@
* *
****************************************************************************/ ****************************************************************************/
#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)) # define isalnum(c) (isalpha(c) || isdigit(c))
#endif
/**************************************************************************** /****************************************************************************
* Name: ispunct * Name: ispunct
@ -173,7 +253,14 @@
* *
****************************************************************************/ ****************************************************************************/
#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)) # define ispunct(c) (isgraph(c) && !isalnum(c))
#endif
/**************************************************************************** /****************************************************************************
* Name: isxdigit * Name: isxdigit
@ -183,10 +270,19 @@
* *
****************************************************************************/ ****************************************************************************/
#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) \ # define isxdigit(c) \
(((c) >= '0' && (c) <= '9') || \ (((c) >= '0' && (c) <= '9') || \
((c) >= 'a' && (c) <= 'f') || \ ((c) >= 'a' && (c) <= 'f') || \
((c) >= 'A' && (c) <= 'F')) ((c) >= 'A' && (c) <= 'F'))
#endif
/**************************************************************************** /****************************************************************************
* Name: toupper * Name: toupper
@ -196,8 +292,15 @@
* *
****************************************************************************/ ****************************************************************************/
#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) \ # define toupper(c) \
(((c) >= 'a' && (c) <= 'z') ? ((c) - 'a' + 'A') : (c)) (((c) >= 'a' && (c) <= 'z') ? ((c) - 'a' + 'A') : (c))
#endif
/**************************************************************************** /****************************************************************************
* Name: tolower * Name: tolower
@ -207,8 +310,16 @@
* *
****************************************************************************/ ****************************************************************************/
#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) \ # define tolower(c) \
(((c) >= 'A' && (c) <= 'Z') ? ((c) - 'A' + 'a') : (c)) (((c) >= 'A' && (c) <= 'Z') ? ((c) - 'A' + 'a') : (c))
# define
#endif
/**************************************************************************** /****************************************************************************
* Public Type Definitions * Public Type Definitions

View File

@ -1,7 +1,7 @@
//*************************************************************************** //***************************************************************************
// include/cxx/cctype // include/cxx/cctype
// //
// Copyright (C) 2009 Gregory Nutt. All rights reserved. // Copyright (C) 2009, 2016 Gregory Nutt. All rights reserved.
// Author: Gregory Nutt <gnutt@nuttx.org> // Author: Gregory Nutt <gnutt@nuttx.org>
// //
// Redistribution and use in source and binary forms, with or without // Redistribution and use in source and binary forms, with or without
@ -42,29 +42,27 @@
#include <ctype.h> #include <ctype.h>
// 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
//*************************************************************************** //***************************************************************************
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 #endif // __INCLUDE_CXX_CCTYPE