Translated using Weblate.
[phpmyadmin.git] / libraries / string.lib.php
blob09e0780f7ef372ae4f4560dd90aa1912aa870f05
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 /**
23 * Load proper code for handling input.
25 if (@function_exists('mb_strlen')) {
26 mb_internal_encoding('utf-8');
27 include './libraries/string_mb.lib.php';
28 } else {
29 include './libraries/string_native.lib.php';
32 /**
33 * Load ctype handler.
35 if (@extension_loaded('ctype')) {
36 include './libraries/string_type_ctype.lib.php';
37 } else {
38 include './libraries/string_type_native.lib.php';
41 /**
42 * Checks if a given character position in the string is escaped or not
44 * @param string string to check for
45 * @param integer the character to check for
46 * @param integer starting position in the string
47 * @return boolean whether the character is escaped or not
49 function PMA_STR_charIsEscaped($string, $pos, $start = 0)
51 $pos = max(intval($pos), 0);
52 $start = max(intval($start), 0);
53 $len = PMA_strlen($string);
54 // Base case:
55 // Check for string length or invalid input or special case of input
56 // (pos == $start)
57 if ($pos <= $start || $len <= max($pos, $start)) {
58 return false;
61 $pos--;
62 $escaped = false;
63 while ($pos >= $start && PMA_substr($string, $pos, 1) == '\\') {
64 $escaped = !$escaped;
65 $pos--;
66 } // end while
68 return $escaped;
69 } // end of the "PMA_STR_charIsEscaped()" function
72 /**
73 * Checks if a number is in a range
75 * @param integer number to check for
76 * @param integer lower bound
77 * @param integer upper bound
78 * @return boolean whether the number is in the range or not
80 function PMA_STR_numberInRangeInclusive($num, $lower, $upper)
82 return ($num >= $lower && $num <= $upper);
83 } // end of the "PMA_STR_numberInRangeInclusive()" function
85 /**
86 * Checks if a character is an SQL identifier
88 * @param string character to check for
89 * @param boolean whether the dot character is valid or not
90 * @return boolean whether the character is an SQL identifier or not
92 function PMA_STR_isSqlIdentifier($c, $dot_is_valid = false)
94 return (PMA_STR_isAlnum($c)
95 || ($ord_c = ord($c)) && $ord_c >= 192 && $ord_c != 215 && $ord_c != 249
96 || $c == '_'
97 || $c == '$'
98 || ($dot_is_valid != false && $c == '.'));
99 } // end of the "PMA_STR_isSqlIdentifier()" function