Translation update done using Pootle.
[phpmyadmin/ammaryasirr.git] / libraries / string.lib.php
blob0cfef414cbc3e0cffcbc4e4a7802e70e656f877b
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
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
11 * (that are slower).
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
16 * @package phpMyAdmin
18 if (! defined('PHPMYADMIN')) {
19 exit;
22 $GLOBALS['PMA_allow_mbstr'] = @function_exists('mb_strlen');
23 $GLOBALS['PMA_allow_ctype'] = @extension_loaded('ctype');
25 if ($GLOBALS['PMA_allow_mbstr']) {
26 mb_internal_encoding('utf-8');
29 /**
30 * Load proper code for handling input.
32 if ($GLOBALS['PMA_allow_mbstr']) {
33 $GLOBALS['PMA_strpos'] = 'mb_strpos';
34 $GLOBALS['PMA_substr'] = 'mb_substr';
35 require './libraries/string_mb.lib.php';
36 } else {
37 $GLOBALS['PMA_strpos'] = 'strpos';
38 $GLOBALS['PMA_substr'] = 'substr';
39 require './libraries/string_native.lib.php';
42 /**
43 * Load ctype handler.
45 if ($GLOBALS['PMA_allow_ctype']) {
46 $GLOBALS['PMA_STR_isAlnum'] = 'ctype_alnum';
47 $GLOBALS['PMA_STR_isDigit'] = 'ctype_digit';
48 $GLOBALS['PMA_STR_isSpace'] = 'ctype_space';
49 require './libraries/string_type_ctype.lib.php';
50 } else {
51 $GLOBALS['PMA_STR_isAlnum'] = 'PMA_STR_isAlnum';
52 $GLOBALS['PMA_STR_isDigit'] = 'PMA_STR_isDigit';
53 $GLOBALS['PMA_STR_isSpace'] = 'PMA_STR_isSpace';
54 require './libraries/string_type_native.lib.php';
57 /**
58 * Checks if a given character position in the string is escaped or not
60 * @param string string to check for
61 * @param integer the character to check for
62 * @param integer starting position in the string
63 * @return boolean whether the character is escaped or not
65 function PMA_STR_charIsEscaped($string, $pos, $start = 0)
67 $pos = max(intval($pos), 0);
68 $start = max(intval($start), 0);
69 $len = PMA_strlen($string);
70 // Base case:
71 // Check for string length or invalid input or special case of input
72 // (pos == $start)
73 if ($pos <= $start || $len <= max($pos, $start)) {
74 return false;
77 $pos--;
78 $escaped = false;
79 while ($pos >= $start && PMA_substr($string, $pos, 1) == '\\') {
80 $escaped = !$escaped;
81 $pos--;
82 } // end while
84 return $escaped;
85 } // end of the "PMA_STR_charIsEscaped()" function
88 /**
89 * Checks if a number is in a range
91 * @param integer number to check for
92 * @param integer lower bound
93 * @param integer upper bound
94 * @return boolean whether the number is in the range or not
96 function PMA_STR_numberInRangeInclusive($num, $lower, $upper)
98 return ($num >= $lower && $num <= $upper);
99 } // end of the "PMA_STR_numberInRangeInclusive()" function
102 * Checks if a character is an SQL identifier
104 * @param string character to check for
105 * @param boolean whether the dot character is valid or not
106 * @return boolean whether the character is an SQL identifier or not
108 function PMA_STR_isSqlIdentifier($c, $dot_is_valid = false)
110 return ($GLOBALS['PMA_STR_isAlnum']($c)
111 || ($ord_c = ord($c)) && $ord_c >= 192 && $ord_c != 215 && $ord_c != 249
112 || $c == '_'
113 || $c == '$'
114 || ($dot_is_valid != false && $c == '.'));
115 } // end of the "PMA_STR_isSqlIdentifier()" function