Ignore:
Timestamp:
Nov 20, 2005 7:55:42 PM (18 years ago)
Author:
bennylp
Message:

Added hex character conversion utility in ctype

File:
1 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjlib/include/pj/ctype.h

    r51 r62  
    2525 */ 
    2626 
     27#include <pj/types.h> 
    2728#include <pj/compat/ctype.h> 
     29 
     30PJ_BEGIN_DECL 
    2831 
    2932/** 
     
    100103 
    101104/** 
    102  * Returns a non-zero value if c is a particular representation of  
    103  * an hexadecimal digit character. 
    104  * @param c     The integer character to test. 
    105  * @return      Non-zero value if c is a particular representation of  
    106  *              an hexadecimal digit character. 
    107  */ 
    108 PJ_INLINE(int) pj_isxdigit(int c){ return isxdigit(c); } 
    109  
    110 /** 
    111105 * Returns a non-zero value if c is a either a space (' ') or horizontal 
    112106 * tab ('\\t') character. 
     
    131125PJ_INLINE(int) pj_toupper(int c) { return toupper(c); } 
    132126 
     127/** 
     128 * Returns a non-zero value if c is a particular representation of  
     129 * an hexadecimal digit character. 
     130 * @param c     The integer character to test. 
     131 * @return      Non-zero value if c is a particular representation of  
     132 *              an hexadecimal digit character. 
     133 */ 
     134PJ_INLINE(int) pj_isxdigit(int c){ return isxdigit(c); } 
     135 
     136/** 
     137 * Array of hex digits, in lowerspace. 
     138 */ 
     139extern char pj_hex_digits[]; 
     140 
     141/** 
     142 * Convert a value to hex representation. 
     143 * @param value     Integral value to convert. 
     144 * @param p         Buffer to hold the hex representation, which must be 
     145 *                  at least two bytes length. 
     146 */ 
     147PJ_INLINE(void) pj_val_to_hex_digit(unsigned value, char *p) 
     148{ 
     149    *p++ = pj_hex_digits[ (value & 0xF0) >> 4 ]; 
     150    *p   = pj_hex_digits[ (value & 0x0F) ]; 
     151} 
     152 
     153/** 
     154 * Convert hex digit c to integral value. 
     155 * @param c     The hex digit character. 
     156 * @return      The integral value between 0 and 15. 
     157 */ 
     158PJ_INLINE(unsigned) pj_hex_digit_to_val(unsigned c) 
     159{ 
     160    if (c <= '9') 
     161        return (c-'0') & 0x0F; 
     162    else if (c <= 'F') 
     163        return  (c-'A'+10) & 0x0F; 
     164    else 
     165        return (c-'a'+10) & 0x0F; 
     166} 
     167 
    133168/** @} */ 
     169 
     170PJ_END_DECL 
    134171 
    135172#endif  /* __PJ_CTYPE_H__ */ 
Note: See TracChangeset for help on using the changeset viewer.