VirtualBox

Changeset 39246 in vbox


Ignore:
Timestamp:
Nov 9, 2011 10:25:42 AM (13 years ago)
Author:
vboxsync
Message:

iprt/ctype.h: Corrected bugs and adding a complete testcase.

Location:
trunk
Files:
1 added
2 edited

Legend:

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

    r36573 r39246  
    6565DECL_FORCE_INLINE(bool) RTLocCIsBlank(int ch)
    6666{
    67     return ch == ' ' || ch == '\t';
     67    return ch == 0x20  /* space */
     68        || ch == 0x09; /* horizontal tab */
    6869}
    6970
     
    7677DECL_FORCE_INLINE(bool) RTLocCIsCntrl(int ch)
    7778{
    78     return (ch) >= 0   && (ch) <  32;
     79    return (unsigned)ch < 32U /* 0..2f */
     80        || ch == 0x7f;
    7981}
    8082
     
    8789DECL_FORCE_INLINE(bool) RTLocCIsDigit(int ch)
    8890{
    89     return (ch) >= '0' && (ch) <= '9';
     91    return (unsigned)ch - 0x30 < 10U; /* 30..39 */
    9092}
    9193
     
    98100DECL_FORCE_INLINE(bool) RTLocCIsLower(int ch)
    99101{
    100     return (ch) >= 'a' && (ch) <= 'z';
     102    return (unsigned)ch - 0x61U < 26U; /* 61..7a */
    101103}
    102104
     
    109111DECL_FORCE_INLINE(bool) RTLocCIsODigit(int ch)
    110112{
    111     return (ch) >= '0' && (ch) <= '7';
     113    return (unsigned)ch - 0x30 < 8U; /* 30..37 */
    112114}
    113115
     
    120122DECL_FORCE_INLINE(bool) RTLocCIsPrint(int ch)
    121123{
    122     /** @todo quite possibly incorrect */
    123     return (ch) >= 32  && (ch) < 127;
     124    return (unsigned)ch - 0x20U < 95U; /* 20..7e */
    124125}
    125126
     
    132133DECL_FORCE_INLINE(bool) RTLocCIsPunct(int ch)
    133134{
    134     /** @todo possibly incorrect */
    135     return (ch) == ',' || (ch) == '.'  || (ch) == ':'  || (ch) == ';'  || (ch) == '!'  || (ch) == '?';
     135    return (unsigned)ch - 0x21U < 15U /* 21..2f */
     136        || (unsigned)ch - 0x2aU <  6U /* 2a..2f */
     137        || (unsigned)ch - 0x3aU <  7U /* 3a..40 */
     138        || (unsigned)ch - 0x5bU <  6U /* 5a..60 */
     139        || (unsigned)ch - 0x7bU <  4U /* 7b..7e */;
    136140}
    137141
     
    144148DECL_FORCE_INLINE(bool) RTLocCIsSpace(int ch)
    145149{
    146     /* \t (9), \n (10), \v (11), \f (12), \r (13), ' ' (32). */
    147     return (ch) == ' ' || ((ch) >= 9 && (ch) <= 13);
     150    return ch == 0x20                 /* 20 (space) */
     151        || (unsigned)ch - 0x09U < 5U; /* 09..0d */
    148152}
    149153
     
    156160DECL_FORCE_INLINE(bool) RTLocCIsUpper(int ch)
    157161{
    158     return (ch) >= 'A' && (ch) <= 'Z';
     162    return (unsigned)ch - 0x41 < 26U; /* 41..5a */
    159163}
    160164
     
    167171DECL_FORCE_INLINE(bool) RTLocCIsXDigit(int ch)
    168172{
    169     return RTLocCIsDigit(ch) || ((ch) >= 'a' && (ch) <= 'f') || ((ch) >= 'A' && (ch) <= 'F');
     173    return (unsigned)ch - 0x30 < 10U /* 30..39 (0-9) */
     174        || (unsigned)ch - 0x41 < 6   /* 41..46 (A-F) */
     175        || (unsigned)ch - 0x61 < 6;  /* 61..66 (a-f) */
    170176}
    171177
     
    212218DECL_FORCE_INLINE(int) RTLocCToLower(int ch)
    213219{
    214     return RTLocCIsUpper(ch) ? (ch) + ('a' - 'A') : (ch);
     220    return RTLocCIsUpper(ch) ? (ch) + 0x20 : (ch);
    215221}
    216222
     
    223229DECL_FORCE_INLINE(int) RTLocCToUpper(int ch)
    224230{
    225     return RTLocCIsLower(ch) ? (ch) - ('a' - 'A') : (ch);
     231    return RTLocCIsLower(ch) ? (ch) - 0x20 : (ch);
    226232}
    227233
  • trunk/src/VBox/Runtime/testcase/Makefile.kmk

    r39027 r39246  
    5151        tstRTCidr \
    5252        tstRTCritSect \
     53        tstRTCType \
    5354        tstRTDigest \
    5455        tstDir \
     
    209210tstRTCritSectW32_DEFS = TRY_WIN32_CRIT
    210211
     212tstRTCType_TEMPLATE = VBOXR3TSTEXE
     213tstRTCType_SOURCES = tstRTCType.cpp
     214
    211215tstRTDigest_SOURCES = tstRTDigest.cpp
    212216
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