1. Check existence of mb_string, mysql and xml extensions before installation.
[openemr.git] / phpmyadmin / libraries / String.class.php
blob3d1ed821fe556a31a2304fd38b6b893da36c5d7a
1 <?php
2 /**
3 * Specialized string class for phpMyAdmin.
4 * The SQL Parser code relies heavily on these functions.
6 * @package PhpMyAdmin-String
7 */
8 if (! defined('PHPMYADMIN')) {
9 exit;
12 require_once 'libraries/StringType.int.php';
13 require_once 'libraries/StringByte.int.php';
14 /**
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
22 /**
23 * @var PMA_StringType
25 private $_type;
27 /**
28 * Constructor
30 public function __construct()
32 if (@extension_loaded('ctype')) {
33 include_once 'libraries/StringCType.class.php';
34 $this->_type = new PMA_StringCType();
35 } else {
36 include_once 'libraries/StringNativeType.class.php';
37 $this->_type = new PMA_StringNativeType();
41 /**
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);
55 // Base case:
56 // Check for string length or invalid input or special case of input
57 // (pos == $start)
58 if ($pos <= $start || $len <= max($pos, $start)) {
59 return false;
62 $pos--;
63 $escaped = false;
64 while ($pos >= $start && /*overload*/mb_substr($string, $pos, 1) == '\\') {
65 $escaped = !$escaped;
66 $pos--;
67 } // end while
69 return $escaped;
72 /**
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 &&
84 $ord_c != 249
85 || $c == '_'
86 || $c == '$'
87 || ($dot_is_valid != false && $c == '.'));
90 /**
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);