Documentation TYPO3 par Ameos |
00001 <?php 00002 /* $Id: string.lib.php,v 2.2 2003/11/26 22:52:23 rabus Exp $ */ 00003 // vim: expandtab sw=4 ts=4 sts=4: 00004 00005 00019 // This is for handling input better 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 // $GLOBALS['PMA_strpos']($haystack, $needle) !== FALSE 00046 // return (is_integer($GLOBALS['PMA_strpos']($haystack, $needle))); 00047 return $GLOBALS['PMA_strpos'](' ' . $haystack, $needle); 00048 } // end of the "PMA_STR_strInStr()" function 00049 00050 00060 function PMA_STR_charIsEscaped($string, $pos, $start = 0) 00061 { 00062 $len = $GLOBALS['PMA_strlen']($string); 00063 // Base case: 00064 // Check for string length or invalid input or special case of input 00065 // (pos == $start) 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 } // end while 00076 00077 if ($pos < $start) { 00078 // throw error about strings 00079 } 00080 00081 return $escaped; 00082 } // end of the "PMA_STR_charIsEscaped()" function 00083 00084 00094 function PMA_STR_numberInRangeInclusive($num, $lower, $upper) 00095 { 00096 return (($num >= $lower) && ($num <= $upper)); 00097 } // end of the "PMA_STR_numberInRangeInclusive()" function 00098 00099 00109 function PMA_STR_isDigit($c) 00110 { 00111 $ord_zero = 48; //ord('0'); 00112 $ord_nine = 57; //ord('9'); 00113 $ord_c = ord($c); 00114 00115 return PMA_STR_numberInRangeInclusive($ord_c, $ord_zero, $ord_nine); 00116 } // end of the "PMA_STR_isDigit()" function 00117 00118 00128 function PMA_STR_isHexDigit($c) 00129 { 00130 $ord_Aupper = 65; //ord('A'); 00131 $ord_Fupper = 70; //ord('F'); 00132 $ord_Alower = 97; //ord('a'); 00133 $ord_Flower = 102; //ord('f'); 00134 $ord_zero = 48; //ord('0'); 00135 $ord_nine = 57; //ord('9'); 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 } // end of the "PMA_STR_isHexDigit()" function 00142 00143 00154 function PMA_STR_isUpper($c) 00155 { 00156 $ord_zero = 65; //ord('A'); 00157 $ord_nine = 90; //ord('Z'); 00158 $ord_c = ord($c); 00159 00160 return PMA_STR_numberInRangeInclusive($ord_c, $ord_zero, $ord_nine); 00161 } // end of the "PMA_STR_isUpper()" function 00162 00163 00174 function PMA_STR_isLower($c) 00175 { 00176 $ord_zero = 97; //ord('a'); 00177 $ord_nine = 122; //ord('z'); 00178 $ord_c = ord($c); 00179 00180 return PMA_STR_numberInRangeInclusive($ord_c, $ord_zero, $ord_nine); 00181 } // end of the "PMA_STR_isLower()" function 00182 00183 00194 function PMA_STR_isAlpha($c) 00195 { 00196 return (PMA_STR_isUpper($c) || PMA_STR_isLower($c)); 00197 } // end of the "PMA_STR_isAlpha()" function 00198 00199 00211 function PMA_STR_isAlnum($c) 00212 { 00213 return (PMA_STR_isUpper($c) || PMA_STR_isLower($c) || PMA_STR_isDigit($c)); 00214 } // end of the "PMA_STR_isAlnum()" function 00215 00216 00226 function PMA_STR_isSpace($c) 00227 { 00228 $ord_space = 32; //ord(' ') 00229 $ord_tab = 9; //ord('\t') 00230 $ord_CR = 13; //ord('\n') 00231 $ord_NOBR = 160; //ord('U+00A0); 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 } // end of the "PMA_STR_isSpace()" function 00238 00239 00253 function PMA_STR_isAccented($c) 00254 { 00255 $ord_min1 = 192; //ord('A'); 00256 $ord_max1 = 214; //ord('Z'); 00257 $ord_min2 = 216; //ord('A'); 00258 $ord_max2 = 246; //ord('Z'); 00259 $ord_min3 = 248; //ord('A'); 00260 $ord_max3 = 255; //ord('Z'); 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 } // end of the "PMA_STR_isAccented()" function 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 } // end of the "PMA_STR_isSqlIdentifier()" function 00287 00288 00298 function PMA_STR_binarySearchInArr($str, $arr, $arrsize) 00299 { 00300 // $arr NUST be sorted, due to binary search 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 } // end while 00316 00317 return $found; 00318 } // end of the "PMA_STR_binarySearchInArr()" function 00319 00320 ?>