PageRenderTime 78ms CodeModel.GetById 14ms RepoModel.GetById 1ms app.codeStats 0ms

/sitemanager/phpmyadmin/libraries/string_type_native.lib.php

https://bitbucket.org/itoxable/chiron-gaming
PHP | 125 lines | 55 code | 13 blank | 57 comment | 9 complexity | ad6ae8016cae25c5792fc9cb0ff4b827 MD5 | raw file
Possible License(s): AGPL-1.0, GPL-2.0
  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. * @package PhpMyAdmin-StringType-Native
  16. */
  17. /**
  18. * Checks if a character is an alphanumeric one
  19. *
  20. * @param string character to check for
  21. * @return boolean whether the character is an alphanumeric one or not
  22. */
  23. function PMA_STR_isAlnum($c)
  24. {
  25. return (PMA_STR_isUpper($c) || PMA_STR_isLower($c) || PMA_STR_isDigit($c));
  26. } // end of the "PMA_STR_isAlnum()" function
  27. /**
  28. * Checks if a character is an alphabetic one
  29. *
  30. * @param string character to check for
  31. * @return boolean whether the character is an alphabetic one or not
  32. */
  33. function PMA_STR_isAlpha($c)
  34. {
  35. return (PMA_STR_isUpper($c) || PMA_STR_isLower($c));
  36. } // end of the "PMA_STR_isAlpha()" function
  37. /**
  38. * Checks if a character is a digit
  39. *
  40. * @param string character to check for
  41. * @return boolean whether the character is a digit or not
  42. */
  43. function PMA_STR_isDigit($c)
  44. {
  45. $ord_zero = 48; //ord('0');
  46. $ord_nine = 57; //ord('9');
  47. $ord_c = ord($c);
  48. return PMA_STR_numberInRangeInclusive($ord_c, $ord_zero, $ord_nine);
  49. } // end of the "PMA_STR_isDigit()" function
  50. /**
  51. * Checks if a character is an upper alphabetic one
  52. *
  53. * @param string character to check for
  54. * @return boolean whether the character is an upper alphabetic one or not
  55. */
  56. function PMA_STR_isUpper($c)
  57. {
  58. $ord_zero = 65; //ord('A');
  59. $ord_nine = 90; //ord('Z');
  60. $ord_c = ord($c);
  61. return PMA_STR_numberInRangeInclusive($ord_c, $ord_zero, $ord_nine);
  62. } // end of the "PMA_STR_isUpper()" function
  63. /**
  64. * Checks if a character is a lower alphabetic one
  65. *
  66. * @param string character to check for
  67. * @return boolean whether the character is a lower alphabetic one or not
  68. */
  69. function PMA_STR_isLower($c)
  70. {
  71. $ord_zero = 97; //ord('a');
  72. $ord_nine = 122; //ord('z');
  73. $ord_c = ord($c);
  74. return PMA_STR_numberInRangeInclusive($ord_c, $ord_zero, $ord_nine);
  75. } // end of the "PMA_STR_isLower()" function
  76. /**
  77. * Checks if a character is a space one
  78. *
  79. * @param string character to check for
  80. * @return boolean whether the character is a space one or not
  81. */
  82. function PMA_STR_isSpace($c)
  83. {
  84. $ord_space = 32; //ord(' ')
  85. $ord_tab = 9; //ord('\t')
  86. $ord_CR = 13; //ord('\n')
  87. $ord_NOBR = 160; //ord('U+00A0);
  88. $ord_c = ord($c);
  89. return ($ord_c == $ord_space
  90. || $ord_c == $ord_NOBR
  91. || PMA_STR_numberInRangeInclusive($ord_c, $ord_tab, $ord_CR));
  92. } // end of the "PMA_STR_isSpace()" function
  93. /**
  94. * Checks if a character is an hexadecimal digit
  95. *
  96. * @param string character to check for
  97. * @return boolean whether the character is an hexadecimal digit or not
  98. */
  99. function PMA_STR_isHexDigit($c)
  100. {
  101. $ord_Aupper = 65; //ord('A');
  102. $ord_Fupper = 70; //ord('F');
  103. $ord_Alower = 97; //ord('a');
  104. $ord_Flower = 102; //ord('f');
  105. $ord_zero = 48; //ord('0');
  106. $ord_nine = 57; //ord('9');
  107. $ord_c = ord($c);
  108. return (PMA_STR_numberInRangeInclusive($ord_c, $ord_zero, $ord_nine)
  109. || PMA_STR_numberInRangeInclusive($ord_c, $ord_Aupper, $ord_Fupper)
  110. || PMA_STR_numberInRangeInclusive($ord_c, $ord_Alower, $ord_Flower));
  111. } // end of the "PMA_STR_isHexDigit()" function
  112. ?>