Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

10 лет назад
10 лет назад
10 лет назад
10 лет назад
10 лет назад
10 лет назад
10 лет назад
10 лет назад
10 лет назад
10 лет назад
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. /*
  2. WCharacter.h - Character utility functions for Wiring & Arduino
  3. Copyright (c) 2010 Hernando Barragan. All right reserved.
  4. This library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Lesser General Public
  6. License as published by the Free Software Foundation; either
  7. version 2.1 of the License, or (at your option) any later version.
  8. This library is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public
  13. License along with this library; if not, write to the Free Software
  14. Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  15. */
  16. #ifndef Character_h
  17. #define Character_h
  18. #include <ctype.h>
  19. // WCharacter.h prototypes
  20. inline boolean isAlphaNumeric(int c) __attribute__((always_inline));
  21. inline boolean isAlpha(int c) __attribute__((always_inline));
  22. inline boolean isAscii(int c) __attribute__((always_inline));
  23. inline boolean isWhitespace(int c) __attribute__((always_inline));
  24. inline boolean isControl(int c) __attribute__((always_inline));
  25. inline boolean isDigit(int c) __attribute__((always_inline));
  26. inline boolean isGraph(int c) __attribute__((always_inline));
  27. inline boolean isLowerCase(int c) __attribute__((always_inline));
  28. inline boolean isPrintable(int c) __attribute__((always_inline));
  29. inline boolean isPunct(int c) __attribute__((always_inline));
  30. inline boolean isSpace(int c) __attribute__((always_inline));
  31. inline boolean isUpperCase(int c) __attribute__((always_inline));
  32. inline boolean isHexadecimalDigit(int c) __attribute__((always_inline));
  33. inline int toAscii(int c) __attribute__((always_inline));
  34. inline int toLowerCase(int c) __attribute__((always_inline));
  35. inline int toUpperCase(int c)__attribute__((always_inline));
  36. // Checks for an alphanumeric character.
  37. // It is equivalent to (isalpha(c) || isdigit(c)).
  38. inline boolean isAlphaNumeric(int c)
  39. {
  40. return ( isalnum(c) == 0 ? false : true);
  41. }
  42. // Checks for an alphabetic character.
  43. // It is equivalent to (isupper(c) || islower(c)).
  44. inline boolean isAlpha(int c)
  45. {
  46. return ( isalpha(c) == 0 ? false : true);
  47. }
  48. // Checks whether c is a 7-bit unsigned char value
  49. // that fits into the ASCII character set.
  50. inline boolean isAscii(int c)
  51. {
  52. return ((c & ~0x7F) != 0 ? false : true);
  53. }
  54. // Checks for a blank character, that is, a space or a tab.
  55. inline boolean isWhitespace(int c)
  56. {
  57. return ( isblank (c) == 0 ? false : true);
  58. }
  59. // Checks for a control character.
  60. inline boolean isControl(int c)
  61. {
  62. return ( iscntrl (c) == 0 ? false : true);
  63. }
  64. // Checks for a digit (0 through 9).
  65. inline boolean isDigit(int c)
  66. {
  67. return ( isdigit (c) == 0 ? false : true);
  68. }
  69. // Checks for any printable character except space.
  70. inline boolean isGraph(int c)
  71. {
  72. return ( isgraph (c) == 0 ? false : true);
  73. }
  74. // Checks for a lower-case character.
  75. inline boolean isLowerCase(int c)
  76. {
  77. return (islower (c) == 0 ? false : true);
  78. }
  79. // Checks for any printable character including space.
  80. inline boolean isPrintable(int c)
  81. {
  82. return ( isprint (c) == 0 ? false : true);
  83. }
  84. // Checks for any printable character which is not a space
  85. // or an alphanumeric character.
  86. inline boolean isPunct(int c)
  87. {
  88. return ( ispunct (c) == 0 ? false : true);
  89. }
  90. // Checks for white-space characters. For the avr-libc library,
  91. // these are: space, formfeed ('\f'), newline ('\n'), carriage
  92. // return ('\r'), horizontal tab ('\t'), and vertical tab ('\v').
  93. inline boolean isSpace(int c)
  94. {
  95. return ( isspace (c) == 0 ? false : true);
  96. }
  97. // Checks for an uppercase letter.
  98. inline boolean isUpperCase(int c)
  99. {
  100. return ( isupper (c) == 0 ? false : true);
  101. }
  102. // Checks for a hexadecimal digits, i.e. one of 0 1 2 3 4 5 6 7
  103. // 8 9 a b c d e f A B C D E F.
  104. inline boolean isHexadecimalDigit(int c)
  105. {
  106. return ( isxdigit (c) == 0 ? false : true);
  107. }
  108. // Converts c to a 7-bit unsigned char value that fits into the
  109. // ASCII character set, by clearing the high-order bits.
  110. inline int toAscii(int c)
  111. {
  112. return (c & 0x7F);
  113. }
  114. // Warning:
  115. // Many people will be unhappy if you use this function.
  116. // This function will convert accented letters into random
  117. // characters.
  118. // Converts the letter c to lower case, if possible.
  119. inline int toLowerCase(int c)
  120. {
  121. return tolower (c);
  122. }
  123. // Converts the letter c to upper case, if possible.
  124. inline int toUpperCase(int c)
  125. {
  126. return toupper (c);
  127. }
  128. #endif