swchar.h 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /************************************************************************
  2. * AUTHOR: NiuJiuRu
  3. * FILENAME: swchar.h
  4. * DESCRIPTION: 字符操作扩展函数
  5. * NOTE:
  6. * HISTORY:
  7. * 1, [2010-08-17] created by NiuJiuRu
  8. ***********************************************************************/
  9. #ifndef __SWCHAR_H__
  10. #define __SWCHAR_H__
  11. // 判断字符c是否为"a-z"或"A-Z"的英文字符
  12. #ifndef xisalpha
  13. #define xisalpha(c) (((c) >= 'a' && (c) <= 'z') || ((c) >= 'A' && (c) <= 'Z'))
  14. #endif
  15. // 判断字符c是否为"a-z"的小写英文字符
  16. #ifndef xislower
  17. #define xislower(c) ((c) >= 'a' && (c) <= 'z')
  18. #endif
  19. // 判断字符c是否为"A-Z"的大写英文字符
  20. #ifndef xisupper
  21. #define xisupper(c) ((c) >= 'A' && (c) <= 'Z')
  22. #endif
  23. // 判断字符c是否为"0-9"的数字字符
  24. #ifndef xisdigit
  25. #define xisdigit(c) ((c) >= '0' && (c) <= '9')
  26. #endif
  27. // 判断字符c是否为"0-9"或"a-f"或"A-F"的16进制数字字符
  28. #ifndef xisxdigit
  29. #define xisxdigit(c) (((c) >= '0' && (c) <= '9') || ((c) >= 'a' && (c) <= 'f') || ((c) >='A' && (c) <= 'F'))
  30. #endif
  31. // 判断字符c是否是控制字符(0x00-0x1F、0x7F)
  32. #ifndef xiscntrl
  33. #define xiscntrl(c) (((c) >= 0x00 && (c) <= 0x1F) || (c) == 0x7F)
  34. #endif
  35. // 判断字符c是否为标点符号或特殊符号
  36. #ifndef xispunct
  37. #define xispunct ispunct
  38. #endif
  39. // 判断字符c是否是空白字符(0x09-0x0D、0x20)
  40. #ifndef xisspace
  41. #define xisspace(c) (((c) >= 0x09 && (c) <= 0x0D) || (c) == 0x20)
  42. #endif
  43. #ifdef __cplusplus
  44. extern "C"
  45. {
  46. #endif
  47. /* 在一个char内, 根据外部输入的位置信息(0 <= pos <= 7), 得到它所对应的二进制位的值 */
  48. char sw_char_getBit(char c, int pos);
  49. /* 在一个char内, 根据外部输入的位置信息(0 <= pos <= 7), 设置它所对应的二进制位的值 */
  50. bool sw_char_setBit(char *c, int pos, char bit);
  51. /* 在一个char数组内, 根据外部输入的位置信息(pos >= 0), 得到它所对应的二进制位的值 */
  52. char sw_chararry_getBit(const char *buf, int bufSize, int pos);
  53. /* 在一个char数组内, 根据外部输入的位置信息(pos >= 0), 设置它所对应的二进制位的值 */
  54. bool sw_chararry_setBit(char *buf, int bufSize, int pos, char bit);
  55. #ifdef __cplusplus
  56. }
  57. #endif
  58. #endif /* __SWCHAR_H__ */