VirtualBox

Changeset 5968 in vbox for trunk/include


Ignore:
Timestamp:
Dec 5, 2007 5:54:38 PM (17 years ago)
Author:
vboxsync
Message:

Added a bunch of RT_C_IS/TO macros that mimics the C (aka POSIX) locale assuming an ASCII like character set. No tables or helper code, so, it's safe to use in all contexts.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/iprt/ctype.h

    r5967 r5968  
    11/** @file
    2  * innotek Portable Runtime - ctype.h wrapper and ascii variants.
     2 * innotek Portable Runtime - ctype.h wrapper and C locale variants.
    33 */
    44
     
    1919
    2020#ifdef IN_RING3
    21 #include <ctype.h>
     21# include <ctype.h>
    2222
    2323# if defined(_MSC_VER) && !defined(isblank)
     
    2727#endif /* IN_RING3 */
    2828
     29/** @name C locale macros.
     30 *
     31 * @remarks The macros may reference the character more than once.
     32 * @remarks Assumes a charset similar to ASCII.
     33 * @remarks Can probably be optimized if someone has time.
     34 * @{ */
     35#define RT_C_IS_BLANK(ch)   ( (ch) == ' ' || (ch) == '\t' )
     36#define RT_C_IS_ALNUM(ch)   ( RT_C_IS_DIGIT(ch) || RT_C_IS_ALPHA(ch) )
     37#define RT_C_IS_ALPHA(ch)   ( RT_C_IS_LOWER(ch) || RT_C_IS_UPPER(ch) )
     38#define RT_C_IS_CNTRL(ch)   ( (ch) >= 0   && (ch) <  32 )
     39#define RT_C_IS_DIGIT(ch)   ( (ch) >= '0' && (ch) <= '9' )
     40#define RT_C_IS_LOWER(ch)   ( (ch) >= 'a' && (ch) <= 'z' )
     41#define RT_C_IS_GRAPH(ch)   ( RT_C_IS_PRINT(ch) && !RT_C_IS_BLANK(ch) )
     42#define RT_C_IS_PRINT(ch)   ( (ch) >= 32  && (ch) < 127 ) /**< @todo possibly incorrect */
     43#define RT_C_IS_PUNCT(ch)   ( (ch) == ',' || (ch) == '.'  || (ch) == ':'  || (ch) == ';'  || (ch) == '!'  || (ch) == '?' ) /**< @todo possibly incorrect */
     44#define RT_C_IS_SPACE(ch)   ( (ch) == ' ' || (ch) == '\t' || (ch) == '\n' || (ch) == '\r' || (ch) == '\f' || (ch) == '\v' )
     45#define RT_C_IS_UPPER(ch)   ( (ch) >= 'A' && (ch) <= 'Z' )
     46#define RT_C_IS_XDIGIT(ch)  ( RT_C_IS_DIGIT(ch) || ((ch) >= 'a' && (ch) <= 'f') || ((ch) >= 'A' && (ch) <= 'F') )
     47
     48#define RT_C_TO_LOWER(ch)   ( RT_C_IS_UPPER(ch) ? (ch) + ('a' - 'A') : (ch) )
     49#define RT_C_TO_UPPER(ch)   ( RT_C_IS_LOWER(ch) ? (ch) - ('a' - 'A') : (ch) )
     50/** @} */
     51
    2952#endif
    3053
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette