summaryrefslogtreecommitdiff
path: root/pjlib/include/pj/ctype.h
diff options
context:
space:
mode:
authorBenny Prijono <bennylp@teluu.com>2005-11-20 19:55:42 +0000
committerBenny Prijono <bennylp@teluu.com>2005-11-20 19:55:42 +0000
commita605c06e12510600a67aaa86ea349037f613e53d (patch)
treecb001ad89f212ffaf6985eadc673230ccd25d7b9 /pjlib/include/pj/ctype.h
parent66864977389a1a59bf7a5d38fcd62559190bb93e (diff)
Added hex character conversion utility in ctype
git-svn-id: http://svn.pjsip.org/repos/pjproject/trunk@62 74dad513-b988-da41-8d7b-12977e46ad98
Diffstat (limited to 'pjlib/include/pj/ctype.h')
-rw-r--r--pjlib/include/pj/ctype.h55
1 files changed, 46 insertions, 9 deletions
diff --git a/pjlib/include/pj/ctype.h b/pjlib/include/pj/ctype.h
index 96e0b78b..e2ab1033 100644
--- a/pjlib/include/pj/ctype.h
+++ b/pjlib/include/pj/ctype.h
@@ -24,8 +24,11 @@
* @brief C type helper macros.
*/
+#include <pj/types.h>
#include <pj/compat/ctype.h>
+PJ_BEGIN_DECL
+
/**
* @defgroup pj_ctype ctype - Character Type
* @ingroup PJ_MISC
@@ -99,15 +102,6 @@ PJ_INLINE(int) pj_islower(int c) { return islower(c); }
PJ_INLINE(int) pj_isupper(int c) { return isupper(c); }
/**
- * Returns a non-zero value if c is a particular representation of
- * an hexadecimal digit character.
- * @param c The integer character to test.
- * @return Non-zero value if c is a particular representation of
- * an hexadecimal digit character.
- */
-PJ_INLINE(int) pj_isxdigit(int c){ return isxdigit(c); }
-
-/**
* Returns a non-zero value if c is a either a space (' ') or horizontal
* tab ('\\t') character.
* @param c The integer character to test.
@@ -130,7 +124,50 @@ PJ_INLINE(int) pj_tolower(int c) { return tolower(c); }
*/
PJ_INLINE(int) pj_toupper(int c) { return toupper(c); }
+/**
+ * Returns a non-zero value if c is a particular representation of
+ * an hexadecimal digit character.
+ * @param c The integer character to test.
+ * @return Non-zero value if c is a particular representation of
+ * an hexadecimal digit character.
+ */
+PJ_INLINE(int) pj_isxdigit(int c){ return isxdigit(c); }
+
+/**
+ * Array of hex digits, in lowerspace.
+ */
+extern char pj_hex_digits[];
+
+/**
+ * Convert a value to hex representation.
+ * @param value Integral value to convert.
+ * @param p Buffer to hold the hex representation, which must be
+ * at least two bytes length.
+ */
+PJ_INLINE(void) pj_val_to_hex_digit(unsigned value, char *p)
+{
+ *p++ = pj_hex_digits[ (value & 0xF0) >> 4 ];
+ *p = pj_hex_digits[ (value & 0x0F) ];
+}
+
+/**
+ * Convert hex digit c to integral value.
+ * @param c The hex digit character.
+ * @return The integral value between 0 and 15.
+ */
+PJ_INLINE(unsigned) pj_hex_digit_to_val(unsigned c)
+{
+ if (c <= '9')
+ return (c-'0') & 0x0F;
+ else if (c <= 'F')
+ return (c-'A'+10) & 0x0F;
+ else
+ return (c-'a'+10) & 0x0F;
+}
+
/** @} */
+PJ_END_DECL
+
#endif /* __PJ_CTYPE_H__ */