PageRenderTime 40ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/phpMyAdmin/libraries/string.lib.php

https://bitbucket.org/izubizarreta/https-bitbucket.org-bityvip
PHP | 101 lines | 64 code | 4 blank | 33 comment | 10 complexity | cec1ae8025e64828e0ae34e2c96fa2d1 MD5 | raw file
Possible License(s): LGPL-3.0, LGPL-2.0, JSON, GPL-2.0, BSD-3-Clause, LGPL-2.1, MIT
  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. * @todo a .lib filename should not have code in main(), split or rename file
  16. * @package PhpMyAdmin
  17. */
  18. if (! defined('PHPMYADMIN')) {
  19. exit;
  20. }
  21. /**
  22. * Load proper code for handling input.
  23. */
  24. if (@function_exists('mb_strlen')) {
  25. mb_internal_encoding('utf-8');
  26. include './libraries/string_mb.lib.php';
  27. } else {
  28. include './libraries/string_native.lib.php';
  29. }
  30. /**
  31. * Load ctype handler.
  32. */
  33. if (@extension_loaded('ctype')) {
  34. include './libraries/string_type_ctype.lib.php';
  35. } else {
  36. include './libraries/string_type_native.lib.php';
  37. }
  38. /**
  39. * Checks if a given character position in the string is escaped or not
  40. *
  41. * @param string string to check for
  42. * @param integer the character to check for
  43. * @param integer starting position in the string
  44. * @return boolean whether the character is escaped or not
  45. */
  46. function PMA_STR_charIsEscaped($string, $pos, $start = 0)
  47. {
  48. $pos = max(intval($pos), 0);
  49. $start = max(intval($start), 0);
  50. $len = PMA_strlen($string);
  51. // Base case:
  52. // Check for string length or invalid input or special case of input
  53. // (pos == $start)
  54. if ($pos <= $start || $len <= max($pos, $start)) {
  55. return false;
  56. }
  57. $pos--;
  58. $escaped = false;
  59. while ($pos >= $start && PMA_substr($string, $pos, 1) == '\\') {
  60. $escaped = !$escaped;
  61. $pos--;
  62. } // end while
  63. return $escaped;
  64. } // end of the "PMA_STR_charIsEscaped()" function
  65. /**
  66. * Checks if a number is in a range
  67. *
  68. * @param integer number to check for
  69. * @param integer lower bound
  70. * @param integer upper bound
  71. * @return boolean whether the number is in the range or not
  72. */
  73. function PMA_STR_numberInRangeInclusive($num, $lower, $upper)
  74. {
  75. return ($num >= $lower && $num <= $upper);
  76. } // end of the "PMA_STR_numberInRangeInclusive()" function
  77. /**
  78. * Checks if a character is an SQL identifier
  79. *
  80. * @param string character to check for
  81. * @param boolean whether the dot character is valid or not
  82. * @return boolean whether the character is an SQL identifier or not
  83. */
  84. function PMA_STR_isSqlIdentifier($c, $dot_is_valid = false)
  85. {
  86. return (PMA_STR_isAlnum($c)
  87. || ($ord_c = ord($c)) && $ord_c >= 192 && $ord_c != 215 && $ord_c != 249
  88. || $c == '_'
  89. || $c == '$'
  90. || ($dot_is_valid != false && $c == '.'));
  91. } // end of the "PMA_STR_isSqlIdentifier()" function
  92. ?>