00001 <?php
00002
00003
00004
00005
00019
00020 if (defined('PMA_MULTIBYTE_ENCODING')) {
00021 $GLOBALS['PMA_strlen'] = 'mb_strlen';
00022 $GLOBALS['PMA_strpos'] = 'mb_strpos';
00023 $GLOBALS['PMA_strrpos'] = 'mb_strrpos';
00024 $GLOBALS['PMA_substr'] = 'mb_substr';
00025 } else {
00026 $GLOBALS['PMA_strlen'] = 'strlen';
00027 $GLOBALS['PMA_strpos'] = 'strpos';
00028 $GLOBALS['PMA_strrpos'] = 'strrpos';
00029 $GLOBALS['PMA_substr'] = 'substr';
00030 }
00031
00032
00043 function PMA_STR_strInStr($needle, $haystack)
00044 {
00045
00046
00047 return $GLOBALS['PMA_strpos'](' ' . $haystack, $needle);
00048 }
00049
00050
00060 function PMA_STR_charIsEscaped($string, $pos, $start = 0)
00061 {
00062 $len = $GLOBALS['PMA_strlen']($string);
00063
00064
00065
00066 if (($pos == $start) || ($len <= $pos)) {
00067 return FALSE;
00068 }
00069
00070 $p = $pos - 1;
00071 $escaped = FALSE;
00072 while (($p >= $start) && ($string[$p] == '\\')) {
00073 $escaped = !$escaped;
00074 $p--;
00075 }
00076
00077 if ($pos < $start) {
00078
00079 }
00080
00081 return $escaped;
00082 }
00083
00084
00094 function PMA_STR_numberInRangeInclusive($num, $lower, $upper)
00095 {
00096 return (($num >= $lower) && ($num <= $upper));
00097 }
00098
00099
00109 function PMA_STR_isDigit($c)
00110 {
00111 $ord_zero = 48;
00112 $ord_nine = 57;
00113 $ord_c = ord($c);
00114
00115 return PMA_STR_numberInRangeInclusive($ord_c, $ord_zero, $ord_nine);
00116 }
00117
00118
00128 function PMA_STR_isHexDigit($c)
00129 {
00130 $ord_Aupper = 65;
00131 $ord_Fupper = 70;
00132 $ord_Alower = 97;
00133 $ord_Flower = 102;
00134 $ord_zero = 48;
00135 $ord_nine = 57;
00136 $ord_c = ord($c);
00137
00138 return (PMA_STR_numberInRangeInclusive($ord_c, $ord_zero, $ord_nine)
00139 || PMA_STR_numberInRangeInclusive($ord_c, $ord_Aupper, $ord_Fupper)
00140 || PMA_STR_numberInRangeInclusive($ord_c, $ord_Alower, $ord_Flower));
00141 }
00142
00143
00154 function PMA_STR_isUpper($c)
00155 {
00156 $ord_zero = 65;
00157 $ord_nine = 90;
00158 $ord_c = ord($c);
00159
00160 return PMA_STR_numberInRangeInclusive($ord_c, $ord_zero, $ord_nine);
00161 }
00162
00163
00174 function PMA_STR_isLower($c)
00175 {
00176 $ord_zero = 97;
00177 $ord_nine = 122;
00178 $ord_c = ord($c);
00179
00180 return PMA_STR_numberInRangeInclusive($ord_c, $ord_zero, $ord_nine);
00181 }
00182
00183
00194 function PMA_STR_isAlpha($c)
00195 {
00196 return (PMA_STR_isUpper($c) || PMA_STR_isLower($c));
00197 }
00198
00199
00211 function PMA_STR_isAlnum($c)
00212 {
00213 return (PMA_STR_isUpper($c) || PMA_STR_isLower($c) || PMA_STR_isDigit($c));
00214 }
00215
00216
00226 function PMA_STR_isSpace($c)
00227 {
00228 $ord_space = 32;
00229 $ord_tab = 9;
00230 $ord_CR = 13;
00231 $ord_NOBR = 160;
00232 $ord_c = ord($c);
00233
00234 return (($ord_c == $ord_space)
00235 || ($ord_c == $ord_NOBR)
00236 || PMA_STR_numberInRangeInclusive($ord_c, $ord_tab, $ord_CR));
00237 }
00238
00239
00253 function PMA_STR_isAccented($c)
00254 {
00255 $ord_min1 = 192;
00256 $ord_max1 = 214;
00257 $ord_min2 = 216;
00258 $ord_max2 = 246;
00259 $ord_min3 = 248;
00260 $ord_max3 = 255;
00261
00262 $ord_c = ord($c);
00263
00264 return PMA_STR_numberInRangeInclusive($ord_c, $ord_min1, $ord_max1)
00265 || PMA_STR_numberInRangeInclusive($ord_c, $ord_min2, $ord_max2)
00266 || PMA_STR_numberInRangeInclusive($ord_c, $ord_min2, $ord_max2);
00267 }
00268
00269
00280 function PMA_STR_isSqlIdentifier($c, $dot_is_valid = FALSE)
00281 {
00282 return (PMA_STR_isAlnum($c)
00283 || PMA_STR_isAccented($c)
00284 || ($c == '_') || ($c == '$')
00285 || (($dot_is_valid != FALSE) && ($c == '.')));
00286 }
00287
00288
00298 function PMA_STR_binarySearchInArr($str, $arr, $arrsize)
00299 {
00300
00301 $top = $arrsize - 1;
00302 $bottom = 0;
00303 $found = FALSE;
00304
00305 while (($top >= $bottom) && ($found == FALSE)) {
00306 $mid = intval(($top + $bottom) / 2);
00307 $res = strcmp($str, $arr[$mid]);
00308 if ($res == 0) {
00309 $found = TRUE;
00310 } else if ($res < 0) {
00311 $top = $mid - 1;
00312 } else {
00313 $bottom = $mid + 1;
00314 }
00315 }
00316
00317 return $found;
00318 }
00319
00320 ?>