2 /* vim: set expandtab sw=4 ts=4 sts=4: */
4 * Specialized String Functions for phpMyAdmin
6 * Copyright 2002 Robin Johnson <robbat2@users.sourceforge.net>
7 * http://www.orbis-terrarum.net/?l=people.robbat2
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
13 * The SQL Parser code relies heavily on these functions.
15 * @todo a .lib filename should not have code in main(), split or rename file
18 if (! defined('PHPMYADMIN')) {
23 * Load proper code for handling input.
25 if (@function_exists
('mb_strlen')) {
26 mb_internal_encoding('utf-8');
27 include './libraries/string_mb.lib.php';
29 include './libraries/string_native.lib.php';
35 if (@extension_loaded
('ctype')) {
36 include './libraries/string_type_ctype.lib.php';
38 include './libraries/string_type_native.lib.php';
42 * Checks if a given character position in the string is escaped or not
44 * @param string string to check for
45 * @param integer the character to check for
46 * @param integer starting position in the string
47 * @return boolean whether the character is escaped or not
49 function PMA_STR_charIsEscaped($string, $pos, $start = 0)
51 $pos = max(intval($pos), 0);
52 $start = max(intval($start), 0);
53 $len = PMA_strlen($string);
55 // Check for string length or invalid input or special case of input
57 if ($pos <= $start ||
$len <= max($pos, $start)) {
63 while ($pos >= $start && PMA_substr($string, $pos, 1) == '\\') {
69 } // end of the "PMA_STR_charIsEscaped()" function
73 * Checks if a number is in a range
75 * @param integer number to check for
76 * @param integer lower bound
77 * @param integer upper bound
78 * @return boolean whether the number is in the range or not
80 function PMA_STR_numberInRangeInclusive($num, $lower, $upper)
82 return ($num >= $lower && $num <= $upper);
83 } // end of the "PMA_STR_numberInRangeInclusive()" function
86 * Checks if a character is an SQL identifier
88 * @param string character to check for
89 * @param boolean 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
98 ||
($dot_is_valid != false && $c == '.'));
99 } // end of the "PMA_STR_isSqlIdentifier()" function