00001 <?php
00002
00003
00004
00017
00018 if (PMA_PHP_INT_VERSION != 40203) {
00019 if (!@extension_loaded('mbstring')) {
00020
00021 }
00022 }
00023
00024
00025
00026 $GLOBALS['using_mb_charset'] =
00027 substr($GLOBALS['charset'], 0, 8) != 'windows-' &&
00028 substr($GLOBALS['charset'], 0, 9) != 'iso-8859-' &&
00029 substr($GLOBALS['charset'], 0, 3) != 'cp-' &&
00030 $GLOBALS['charset'] != 'koi8-r' &&
00031 $GLOBALS['charset'] != 'tis-620';
00032
00033 $GLOBALS['PMA_allow_mbstr'] = @function_exists('mb_strlen') && $GLOBALS['using_mb_charset'];
00034
00035 if ($GLOBALS['PMA_allow_mbstr']) {
00036
00037
00038 if ($GLOBALS['charset'] == 'iso-8859-8-i'){
00039 mb_internal_encoding('iso-8859-8');
00040 } else {
00041 mb_internal_encoding($GLOBALS['charset']);
00042 }
00043 }
00044
00045
00046 if (defined('PMA_MULTIBYTE_ENCODING') || $GLOBALS['PMA_allow_mbstr']) {
00047 $GLOBALS['PMA_strpos'] = 'mb_strpos';
00048 $GLOBALS['PMA_strrpos'] = 'mb_strrpos';
00049 } else {
00050 $GLOBALS['PMA_strpos'] = 'strpos';
00051 $GLOBALS['PMA_strrpos'] = 'strrpos';
00052 }
00053
00065 function PMA_strlen($string)
00066 {
00067
00068 if (defined('PMA_MULTIBYTE_ENCODING') || $GLOBALS['PMA_allow_mbstr']) {
00069 return mb_strlen($string);
00070 } else {
00071 return strlen($string);
00072 }
00073 }
00074
00088 function PMA_substr($string, $start, $length = 2147483647)
00089 {
00090 if (defined('PMA_MULTIBYTE_ENCODING') || $GLOBALS['PMA_allow_mbstr']) {
00091 return mb_substr($string, $start, $length);
00092 } else {
00093 return substr($string, $start, $length);
00094 }
00095 }
00096
00097
00108 function PMA_STR_strInStr($needle, $haystack)
00109 {
00110
00111
00112 return $GLOBALS['PMA_strpos'](' ' . $haystack, $needle);
00113 }
00114
00115
00125 function PMA_STR_charIsEscaped($string, $pos, $start = 0)
00126 {
00127 $len = PMA_strlen($string);
00128
00129
00130
00131 if (($pos == $start) || ($len <= $pos)) {
00132 return FALSE;
00133 }
00134
00135 $p = $pos - 1;
00136 $escaped = FALSE;
00137 while (($p >= $start) && ($string[$p] == '\\')) {
00138 $escaped = !$escaped;
00139 $p--;
00140 }
00141
00142 if ($pos < $start) {
00143
00144 }
00145
00146 return $escaped;
00147 }
00148
00149
00159 function PMA_STR_numberInRangeInclusive($num, $lower, $upper)
00160 {
00161 return (($num >= $lower) && ($num <= $upper));
00162 }
00163
00164
00174 function PMA_STR_isDigit($c)
00175 {
00176 $ord_zero = 48;
00177 $ord_nine = 57;
00178 $ord_c = ord($c);
00179
00180 return PMA_STR_numberInRangeInclusive($ord_c, $ord_zero, $ord_nine);
00181 }
00182
00183
00193 function PMA_STR_isHexDigit($c)
00194 {
00195 $ord_Aupper = 65;
00196 $ord_Fupper = 70;
00197 $ord_Alower = 97;
00198 $ord_Flower = 102;
00199 $ord_zero = 48;
00200 $ord_nine = 57;
00201 $ord_c = ord($c);
00202
00203 return (PMA_STR_numberInRangeInclusive($ord_c, $ord_zero, $ord_nine)
00204 || PMA_STR_numberInRangeInclusive($ord_c, $ord_Aupper, $ord_Fupper)
00205 || PMA_STR_numberInRangeInclusive($ord_c, $ord_Alower, $ord_Flower));
00206 }
00207
00208
00219 function PMA_STR_isUpper($c)
00220 {
00221 $ord_zero = 65;
00222 $ord_nine = 90;
00223 $ord_c = ord($c);
00224
00225 return PMA_STR_numberInRangeInclusive($ord_c, $ord_zero, $ord_nine);
00226 }
00227
00228
00239 function PMA_STR_isLower($c)
00240 {
00241 $ord_zero = 97;
00242 $ord_nine = 122;
00243 $ord_c = ord($c);
00244
00245 return PMA_STR_numberInRangeInclusive($ord_c, $ord_zero, $ord_nine);
00246 }
00247
00248
00259 function PMA_STR_isAlpha($c)
00260 {
00261 return (PMA_STR_isUpper($c) || PMA_STR_isLower($c));
00262 }
00263
00264
00276 function PMA_STR_isAlnum($c)
00277 {
00278 return (PMA_STR_isUpper($c) || PMA_STR_isLower($c) || PMA_STR_isDigit($c));
00279 }
00280
00281
00291 function PMA_STR_isSpace($c)
00292 {
00293 $ord_space = 32;
00294 $ord_tab = 9;
00295 $ord_CR = 13;
00296 $ord_NOBR = 160;
00297 $ord_c = ord($c);
00298
00299 return (($ord_c == $ord_space)
00300 || ($ord_c == $ord_NOBR)
00301 || PMA_STR_numberInRangeInclusive($ord_c, $ord_tab, $ord_CR));
00302 }
00303
00304
00318 function PMA_STR_isAccented($c)
00319 {
00320 $ord_min1 = 192;
00321 $ord_max1 = 214;
00322 $ord_min2 = 216;
00323 $ord_max2 = 246;
00324 $ord_min3 = 248;
00325 $ord_max3 = 255;
00326
00327 $ord_c = ord($c);
00328
00329 return PMA_STR_numberInRangeInclusive($ord_c, $ord_min1, $ord_max1)
00330 || PMA_STR_numberInRangeInclusive($ord_c, $ord_min2, $ord_max2)
00331 || PMA_STR_numberInRangeInclusive($ord_c, $ord_min2, $ord_max2);
00332 }
00333
00334
00345 function PMA_STR_isSqlIdentifier($c, $dot_is_valid = FALSE)
00346 {
00347 return (PMA_STR_isAlnum($c)
00348 || PMA_STR_isAccented($c)
00349 || ($c == '_') || ($c == '$')
00350 || (($dot_is_valid != FALSE) && ($c == '.')));
00351 }
00352
00353
00363 function PMA_STR_binarySearchInArr($str, $arr, $arrsize)
00364 {
00365
00366 $top = $arrsize - 1;
00367 $bottom = 0;
00368 $found = FALSE;
00369
00370 while (($top >= $bottom) && ($found == FALSE)) {
00371 $mid = intval(($top + $bottom) / 2);
00372 $res = strcmp($str, $arr[$mid]);
00373 if ($res == 0) {
00374 $found = TRUE;
00375 } else if ($res < 0) {
00376 $top = $mid - 1;
00377 } else {
00378 $bottom = $mid + 1;
00379 }
00380 }
00381
00382 return $found;
00383 }
00384
00385 ?>