Documentation TYPO3 par Ameos

string.lib.php

00001 <?php
00002 /* $Id: string.lib.php,v 2.10 2005/07/16 12:20:59 lem9 Exp $ */
00003 // vim: expandtab sw=4 ts=4 sts=4:
00004 
00017 /* Try to load mbstring, unless we're using buggy php version */
00018 if (PMA_PHP_INT_VERSION != 40203) {
00019     if (!@extension_loaded('mbstring')) {
00020         //PMA_dl('mbstring');
00021     }
00022 }
00023 
00024 /* windows-* and tis-620 are not supported and are not multibyte,
00025  * others can be ignored as they're not multibyte */
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     // the hebrew lang file uses iso-8859-8-i, encoded RTL,
00037     // but mb_internal_encoding only supports iso-8859-8
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 // This is for handling input better
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     // windows-* charsets are not multibyte and not supported by mb_*
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     // $GLOBALS['PMA_strpos']($haystack, $needle) !== FALSE
00111     // return (is_integer($GLOBALS['PMA_strpos']($haystack, $needle)));
00112     return $GLOBALS['PMA_strpos'](' ' . $haystack, $needle);
00113 } // end of the "PMA_STR_strInStr()" function
00114 
00115 
00125 function PMA_STR_charIsEscaped($string, $pos, $start = 0)
00126 {
00127     $len = PMA_strlen($string);
00128     // Base case:
00129     // Check for string length or invalid input or special case of input
00130     // (pos == $start)
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     } // end while
00141 
00142     if ($pos < $start) {
00143         // throw error about strings
00144     }
00145 
00146     return $escaped;
00147 } // end of the "PMA_STR_charIsEscaped()" function
00148 
00149 
00159 function PMA_STR_numberInRangeInclusive($num, $lower, $upper)
00160 {
00161     return (($num >= $lower) && ($num <= $upper));
00162 } // end of the "PMA_STR_numberInRangeInclusive()" function
00163 
00164 
00174 function PMA_STR_isDigit($c)
00175 {
00176     $ord_zero = 48; //ord('0');
00177     $ord_nine = 57; //ord('9');
00178     $ord_c    = ord($c);
00179 
00180     return PMA_STR_numberInRangeInclusive($ord_c, $ord_zero, $ord_nine);
00181 } // end of the "PMA_STR_isDigit()" function
00182 
00183 
00193 function PMA_STR_isHexDigit($c)
00194 {
00195     $ord_Aupper = 65;  //ord('A');
00196     $ord_Fupper = 70;  //ord('F');
00197     $ord_Alower = 97;  //ord('a');
00198     $ord_Flower = 102; //ord('f');
00199     $ord_zero   = 48;  //ord('0');
00200     $ord_nine   = 57;  //ord('9');
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 } // end of the "PMA_STR_isHexDigit()" function
00207 
00208 
00219 function PMA_STR_isUpper($c)
00220 {
00221     $ord_zero = 65; //ord('A');
00222     $ord_nine = 90; //ord('Z');
00223     $ord_c    = ord($c);
00224 
00225     return PMA_STR_numberInRangeInclusive($ord_c, $ord_zero, $ord_nine);
00226 } // end of the "PMA_STR_isUpper()" function
00227 
00228 
00239 function PMA_STR_isLower($c)
00240 {
00241     $ord_zero = 97;  //ord('a');
00242     $ord_nine = 122; //ord('z');
00243     $ord_c    = ord($c);
00244 
00245     return PMA_STR_numberInRangeInclusive($ord_c, $ord_zero, $ord_nine);
00246 } // end of the "PMA_STR_isLower()" function
00247 
00248 
00259 function PMA_STR_isAlpha($c)
00260 {
00261     return (PMA_STR_isUpper($c) || PMA_STR_isLower($c));
00262 } // end of the "PMA_STR_isAlpha()" function
00263 
00264 
00276 function PMA_STR_isAlnum($c)
00277 {
00278     return (PMA_STR_isUpper($c) || PMA_STR_isLower($c) || PMA_STR_isDigit($c));
00279 } // end of the "PMA_STR_isAlnum()" function
00280 
00281 
00291 function PMA_STR_isSpace($c)
00292 {
00293     $ord_space = 32; //ord(' ')
00294     $ord_tab   = 9; //ord('\t')
00295     $ord_CR    = 13; //ord('\n')
00296     $ord_NOBR  = 160; //ord('U+00A0);
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 } // end of the "PMA_STR_isSpace()" function
00303 
00304 
00318 function PMA_STR_isAccented($c)
00319 {
00320     $ord_min1 = 192; //ord('A');
00321     $ord_max1 = 214; //ord('Z');
00322     $ord_min2 = 216; //ord('A');
00323     $ord_max2 = 246; //ord('Z');
00324     $ord_min3 = 248; //ord('A');
00325     $ord_max3 = 255; //ord('Z');
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 } // end of the "PMA_STR_isAccented()" function
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 } // end of the "PMA_STR_isSqlIdentifier()" function
00352 
00353 
00363 function PMA_STR_binarySearchInArr($str, $arr, $arrsize)
00364 {
00365     // $arr MUST be sorted, due to binary search
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     } // end while
00381 
00382     return $found;
00383 } // end of the "PMA_STR_binarySearchInArr()" function
00384 
00385 ?>


Généré par TYPO3 Ameos avec  doxygen 1.4.6