PageRenderTime 56ms CodeModel.GetById 30ms RepoModel.GetById 0ms app.codeStats 0ms

/phpmyadmin/libraries/string_type_native.lib.php

https://bitbucket.org/DenizYldrm/openemr
PHP | 140 lines | 55 code | 13 blank | 72 comment | 9 complexity | 29196abb251bdf9e995f6c337f8bafa1 MD5 | raw file
Possible License(s): AGPL-1.0, GPL-2.0, MPL-2.0, LGPL-2.1
  1. <?php
  2. /* vim: set expandtab sw=4 ts=4 sts=4: */
  3. /**
  4. * Specialized String Functions for phpMyAdmin
  5. *
  6. * Copyright 2002 Robin Johnson <robbat2@users.sourceforge.net>
  7. * http://www.orbis-terrarum.net/?l=people.robbat2
  8. *
  9. * Defines a set of function callbacks that have a pure C version available if
  10. * the "ctype" extension is available, but otherwise have PHP versions to use
  11. * (that are slower).
  12. *
  13. * The SQL Parser code relies heavily on these functions.
  14. *
  15. * @version $Id$
  16. */
  17. /**
  18. * Checks if a character is an alphanumeric one
  19. *
  20. * @uses PMA_STR_isUpper()
  21. * @uses PMA_STR_isLower()
  22. * @uses PMA_STR_isDigit()
  23. * @param string character to check for
  24. * @return boolean whether the character is an alphanumeric one or not
  25. */
  26. function PMA_STR_isAlnum($c)
  27. {
  28. return (PMA_STR_isUpper($c) || PMA_STR_isLower($c) || PMA_STR_isDigit($c));
  29. } // end of the "PMA_STR_isAlnum()" function
  30. /**
  31. * Checks if a character is an alphabetic one
  32. *
  33. * @uses PMA_STR_isUpper()
  34. * @uses PMA_STR_isLower()
  35. * @param string character to check for
  36. * @return boolean whether the character is an alphabetic one or not
  37. */
  38. function PMA_STR_isAlpha($c)
  39. {
  40. return (PMA_STR_isUpper($c) || PMA_STR_isLower($c));
  41. } // end of the "PMA_STR_isAlpha()" function
  42. /**
  43. * Checks if a character is a digit
  44. *
  45. * @uses PMA_STR_numberInRangeInclusive()
  46. * @uses ord()
  47. * @param string character to check for
  48. * @return boolean whether the character is a digit or not
  49. */
  50. function PMA_STR_isDigit($c)
  51. {
  52. $ord_zero = 48; //ord('0');
  53. $ord_nine = 57; //ord('9');
  54. $ord_c = ord($c);
  55. return PMA_STR_numberInRangeInclusive($ord_c, $ord_zero, $ord_nine);
  56. } // end of the "PMA_STR_isDigit()" function
  57. /**
  58. * Checks if a character is an upper alphabetic one
  59. *
  60. * @uses PMA_STR_numberInRangeInclusive()
  61. * @uses ord()
  62. * @param string character to check for
  63. * @return boolean whether the character is an upper alphabetic one or not
  64. */
  65. function PMA_STR_isUpper($c)
  66. {
  67. $ord_zero = 65; //ord('A');
  68. $ord_nine = 90; //ord('Z');
  69. $ord_c = ord($c);
  70. return PMA_STR_numberInRangeInclusive($ord_c, $ord_zero, $ord_nine);
  71. } // end of the "PMA_STR_isUpper()" function
  72. /**
  73. * Checks if a character is a lower alphabetic one
  74. *
  75. * @uses PMA_STR_numberInRangeInclusive()
  76. * @uses ord()
  77. * @param string character to check for
  78. * @return boolean whether the character is a lower alphabetic one or not
  79. */
  80. function PMA_STR_isLower($c)
  81. {
  82. $ord_zero = 97; //ord('a');
  83. $ord_nine = 122; //ord('z');
  84. $ord_c = ord($c);
  85. return PMA_STR_numberInRangeInclusive($ord_c, $ord_zero, $ord_nine);
  86. } // end of the "PMA_STR_isLower()" function
  87. /**
  88. * Checks if a character is a space one
  89. *
  90. * @uses PMA_STR_numberInRangeInclusive()
  91. * @uses ord()
  92. * @param string character to check for
  93. * @return boolean whether the character is a space one or not
  94. */
  95. function PMA_STR_isSpace($c)
  96. {
  97. $ord_space = 32; //ord(' ')
  98. $ord_tab = 9; //ord('\t')
  99. $ord_CR = 13; //ord('\n')
  100. $ord_NOBR = 160; //ord('U+00A0);
  101. $ord_c = ord($c);
  102. return ($ord_c == $ord_space
  103. || $ord_c == $ord_NOBR
  104. || PMA_STR_numberInRangeInclusive($ord_c, $ord_tab, $ord_CR));
  105. } // end of the "PMA_STR_isSpace()" function
  106. /**
  107. * Checks if a character is an hexadecimal digit
  108. *
  109. * @uses PMA_STR_numberInRangeInclusive()
  110. * @uses ord()
  111. * @param string character to check for
  112. * @return boolean whether the character is an hexadecimal digit or not
  113. */
  114. function PMA_STR_isHexDigit($c)
  115. {
  116. $ord_Aupper = 65; //ord('A');
  117. $ord_Fupper = 70; //ord('F');
  118. $ord_Alower = 97; //ord('a');
  119. $ord_Flower = 102; //ord('f');
  120. $ord_zero = 48; //ord('0');
  121. $ord_nine = 57; //ord('9');
  122. $ord_c = ord($c);
  123. return (PMA_STR_numberInRangeInclusive($ord_c, $ord_zero, $ord_nine)
  124. || PMA_STR_numberInRangeInclusive($ord_c, $ord_Aupper, $ord_Fupper)
  125. || PMA_STR_numberInRangeInclusive($ord_c, $ord_Alower, $ord_Flower));
  126. } // end of the "PMA_STR_isHexDigit()" function
  127. ?>