Upgraded phpmyadmin to 4.0.4 (All Languages) - No modifications yet
[openemr.git] / phpmyadmin / libraries / string.lib.php
blob604501689fc535041623be01812cc837ca8ccedf
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * Specialized String Functions for phpMyAdmin
6 * Defines a set of function callbacks that have a pure C version available if
7 * the "ctype" extension is available, but otherwise have PHP versions to use
8 * (that are slower).
10 * The SQL Parser code relies heavily on these functions.
12 * @todo a .lib filename should not have code in main(), split or rename file
13 * @package PhpMyAdmin-String
15 if (! defined('PHPMYADMIN')) {
16 exit;
19 /**
20 * Load proper code for handling input.
22 if (@function_exists('mb_strlen')) {
23 mb_internal_encoding('utf-8');
24 include './libraries/string_mb.lib.php';
25 } else {
26 include './libraries/string_native.lib.php';
29 /**
30 * Load ctype handler.
32 if (@extension_loaded('ctype')) {
33 include './libraries/string_type_ctype.lib.php';
34 } else {
35 include './libraries/string_type_native.lib.php';
38 /**
39 * Checks if a given character position in the string is escaped or not
41 * @param string $string string to check for
42 * @param integer $pos the character to check for
43 * @param integer $start starting position in the string
45 * @return boolean whether the character is escaped or not
47 function PMA_STR_charIsEscaped($string, $pos, $start = 0)
49 $pos = max(intval($pos), 0);
50 $start = max(intval($start), 0);
51 $len = PMA_strlen($string);
52 // Base case:
53 // Check for string length or invalid input or special case of input
54 // (pos == $start)
55 if ($pos <= $start || $len <= max($pos, $start)) {
56 return false;
59 $pos--;
60 $escaped = false;
61 while ($pos >= $start && PMA_substr($string, $pos, 1) == '\\') {
62 $escaped = !$escaped;
63 $pos--;
64 } // end while
66 return $escaped;
67 } // end of the "PMA_STR_charIsEscaped()" function
70 /**
71 * Checks if a number is in a range
73 * @param integer $num number to check for
74 * @param integer $lower lower bound
75 * @param integer $upper upper bound
77 * @return boolean whether the number is in the range or not
79 function PMA_STR_numberInRangeInclusive($num, $lower, $upper)
81 return ($num >= $lower && $num <= $upper);
82 } // end of the "PMA_STR_numberInRangeInclusive()" function
84 /**
85 * Checks if a character is an SQL identifier
87 * @param string $c character to check for
88 * @param boolean $dot_is_valid whether the dot character is valid or not
90 * @return boolean whether the character is an SQL identifier or not
92 function PMA_STR_isSqlIdentifier($c, $dot_is_valid = false)
94 return (PMA_STR_isAlnum($c)
95 || ($ord_c = ord($c)) && $ord_c >= 192 && $ord_c != 215 && $ord_c != 249
96 || $c == '_'
97 || $c == '$'
98 || ($dot_is_valid != false && $c == '.'));
99 } // end of the "PMA_STR_isSqlIdentifier()" function