/CSipSimple/jni/pjsip/sources/pjlib/include/pj/ctype.h

https://bitbucket.org/bohlooli/csipsimple2 · C Header · 175 lines · 33 code · 23 blank · 119 comment · 3 complexity · b44a129d544501f65d9e37fe293e4c6d MD5 · raw file

  1. /* $Id: ctype.h 3553 2011-05-05 06:14:19Z nanang $ */
  2. /*
  3. * Copyright (C) 2008-2011 Teluu Inc. (http://www.teluu.com)
  4. * Copyright (C) 2003-2008 Benny Prijono <benny@prijono.org>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  19. */
  20. #ifndef __PJ_CTYPE_H__
  21. #define __PJ_CTYPE_H__
  22. /**
  23. * @file ctype.h
  24. * @brief C type helper macros.
  25. */
  26. #include <pj/types.h>
  27. #include <pj/compat/ctype.h>
  28. PJ_BEGIN_DECL
  29. /**
  30. * @defgroup pj_ctype ctype - Character Type
  31. * @ingroup PJ_MISC
  32. * @{
  33. *
  34. * This module contains several inline functions/macros for testing or
  35. * manipulating character types. It is provided in PJLIB because PJLIB
  36. * must not depend to LIBC.
  37. */
  38. /**
  39. * Returns a non-zero value if either isalpha or isdigit is true for c.
  40. * @param c The integer character to test.
  41. * @return Non-zero value if either isalpha or isdigit is true for c.
  42. */
  43. PJ_INLINE(int) pj_isalnum(unsigned char c) { return isalnum(c); }
  44. /**
  45. * Returns a non-zero value if c is a particular representation of an
  46. * alphabetic character.
  47. * @param c The integer character to test.
  48. * @return Non-zero value if c is a particular representation of an
  49. * alphabetic character.
  50. */
  51. PJ_INLINE(int) pj_isalpha(unsigned char c) { return isalpha(c); }
  52. /**
  53. * Returns a non-zero value if c is a particular representation of an
  54. * ASCII character.
  55. * @param c The integer character to test.
  56. * @return Non-zero value if c is a particular representation of
  57. * an ASCII character.
  58. */
  59. PJ_INLINE(int) pj_isascii(unsigned char c) { return c<128; }
  60. /**
  61. * Returns a non-zero value if c is a particular representation of
  62. * a decimal-digit character.
  63. * @param c The integer character to test.
  64. * @return Non-zero value if c is a particular representation of
  65. * a decimal-digit character.
  66. */
  67. PJ_INLINE(int) pj_isdigit(unsigned char c) { return isdigit(c); }
  68. /**
  69. * Returns a non-zero value if c is a particular representation of
  70. * a space character (0x09 - 0x0D or 0x20).
  71. * @param c The integer character to test.
  72. * @return Non-zero value if c is a particular representation of
  73. * a space character (0x09 - 0x0D or 0x20).
  74. */
  75. PJ_INLINE(int) pj_isspace(unsigned char c) { return isspace(c); }
  76. /**
  77. * Returns a non-zero value if c is a particular representation of
  78. * a lowercase character.
  79. * @param c The integer character to test.
  80. * @return Non-zero value if c is a particular representation of
  81. * a lowercase character.
  82. */
  83. PJ_INLINE(int) pj_islower(unsigned char c) { return islower(c); }
  84. /**
  85. * Returns a non-zero value if c is a particular representation of
  86. * a uppercase character.
  87. * @param c The integer character to test.
  88. * @return Non-zero value if c is a particular representation of
  89. * a uppercase character.
  90. */
  91. PJ_INLINE(int) pj_isupper(unsigned char c) { return isupper(c); }
  92. /**
  93. * Returns a non-zero value if c is a either a space (' ') or horizontal
  94. * tab ('\\t') character.
  95. * @param c The integer character to test.
  96. * @return Non-zero value if c is a either a space (' ') or horizontal
  97. * tab ('\\t') character.
  98. */
  99. PJ_INLINE(int) pj_isblank(unsigned char c) { return isblank(c); }
  100. /**
  101. * Converts character to lowercase.
  102. * @param c The integer character to convert.
  103. * @return Lowercase character of c.
  104. */
  105. PJ_INLINE(int) pj_tolower(unsigned char c) { return tolower(c); }
  106. /**
  107. * Converts character to uppercase.
  108. * @param c The integer character to convert.
  109. * @return Uppercase character of c.
  110. */
  111. PJ_INLINE(int) pj_toupper(unsigned char c) { return toupper(c); }
  112. /**
  113. * Returns a non-zero value if c is a particular representation of
  114. * an hexadecimal digit character.
  115. * @param c The integer character to test.
  116. * @return Non-zero value if c is a particular representation of
  117. * an hexadecimal digit character.
  118. */
  119. PJ_INLINE(int) pj_isxdigit(unsigned char c){ return isxdigit(c); }
  120. /**
  121. * Array of hex digits, in lowerspace.
  122. */
  123. /*extern char pj_hex_digits[];*/
  124. #define pj_hex_digits "0123456789abcdef"
  125. /**
  126. * Convert a value to hex representation.
  127. * @param value Integral value to convert.
  128. * @param p Buffer to hold the hex representation, which must be
  129. * at least two bytes length.
  130. */
  131. PJ_INLINE(void) pj_val_to_hex_digit(unsigned value, char *p)
  132. {
  133. *p++ = pj_hex_digits[ (value & 0xF0) >> 4 ];
  134. *p = pj_hex_digits[ (value & 0x0F) ];
  135. }
  136. /**
  137. * Convert hex digit c to integral value.
  138. * @param c The hex digit character.
  139. * @return The integral value between 0 and 15.
  140. */
  141. PJ_INLINE(unsigned) pj_hex_digit_to_val(unsigned char c)
  142. {
  143. if (c <= '9')
  144. return (c-'0') & 0x0F;
  145. else if (c <= 'F')
  146. return (c-'A'+10) & 0x0F;
  147. else
  148. return (c-'a'+10) & 0x0F;
  149. }
  150. /** @} */
  151. PJ_END_DECL
  152. #endif /* __PJ_CTYPE_H__ */