3 * Specialized string class for phpMyAdmin.
4 * The SQL Parser code relies heavily on these functions.
6 * @package PhpMyAdmin-String
8 if (! defined('PHPMYADMIN')) {
12 require_once 'libraries/StringType.int.php';
13 require_once 'libraries/StringByte.int.php';
15 * Specialized string class for phpMyAdmin.
16 * The SQL Parser code relies heavily on these functions.
18 * @package PhpMyAdmin-String
20 class PMA_String
implements PMA_StringType
30 public function __construct()
32 if (@extension_loaded
('ctype')) {
33 include_once 'libraries/StringCType.class.php';
34 $this->_type
= new PMA_StringCType();
36 include_once 'libraries/StringNativeType.class.php';
37 $this->_type
= new PMA_StringNativeType();
42 * Checks if a given character position in the string is escaped or not
44 * @param string $string string to check for
45 * @param integer $pos the character to check for
46 * @param integer $start starting position in the string
48 * @return boolean whether the character is escaped or not
50 public function charIsEscaped($string, $pos, $start = 0)
52 $pos = max(intval($pos), 0);
53 $start = max(intval($start), 0);
54 $len = /*overload*/mb_strlen($string);
56 // Check for string length or invalid input or special case of input
58 if ($pos <= $start ||
$len <= max($pos, $start)) {
64 while ($pos >= $start && /*overload*/mb_substr($string, $pos, 1) == '\\') {
73 * Checks if a character is an SQL identifier
75 * @param string $c character to check for
76 * @param boolean $dot_is_valid whether the dot character is valid or not
78 * @return boolean whether the character is an SQL identifier or not
80 public function isSqlIdentifier($c, $dot_is_valid = false)
82 return ($this->isAlnum($c)
83 ||
($ord_c = /*overload*/mb_ord($c)) && $ord_c >= 192 && $ord_c != 215 &&
87 ||
($dot_is_valid != false && $c == '.'));
91 * Checks if a character is an alphanumeric one
93 * @param string $c character to check for
95 * @return boolean whether the character is an alphanumeric one or not
97 public function isAlnum($c)
99 return $this->_type
->isAlnum($c);
103 * Checks if a character is an alphabetic one
105 * @param string $c character to check for
107 * @return boolean whether the character is an alphabetic one or not
109 public function isAlpha($c)
111 return $this->_type
->isAlpha($c);
115 * Checks if a character is a digit
117 * @param string $c character to check for
119 * @return boolean whether the character is a digit or not
121 public function isDigit($c)
123 return $this->_type
->isDigit($c);
127 * Checks if a character is an upper alphabetic one
129 * @param string $c character to check for
131 * @return boolean whether the character is an upper alphabetic one or not
133 public function isUpper($c)
135 return $this->_type
->isUpper($c);
139 * Checks if a character is a lower alphabetic one
141 * @param string $c character to check for
143 * @return boolean whether the character is a lower alphabetic one or not
145 public function isLower($c)
147 return $this->_type
->isLower($c);
151 * Checks if a character is a space one
153 * @param string $c character to check for
155 * @return boolean whether the character is a space one or not
157 public function isSpace($c)
159 return $this->_type
->isSpace($c);
163 * Checks if a character is an hexadecimal digit
165 * @param string $c character to check for
167 * @return boolean whether the character is an hexadecimal digit or not
169 public function isHexDigit($c)
171 return $this->_type
->isHexDigit($c);
175 * Checks if a number is in a range
177 * @param integer $num number to check for
178 * @param integer $lower lower bound
179 * @param integer $upper upper bound
181 * @return boolean whether the number is in the range or not
183 public function numberInRangeInclusive($num, $lower, $upper)
185 return $this->_type
->numberInRangeInclusive($num, $lower, $upper);