2 /* vim: set expandtab sw=4 ts=4 sts=4: */
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
13 * The SQL Parser code relies heavily on these functions.
19 * Checks if a character is an alphanumeric one
21 * @uses PMA_STR_isUpper()
22 * @uses PMA_STR_isLower()
23 * @uses PMA_STR_isDigit()
24 * @param string character to check for
25 * @return boolean whether the character is an alphanumeric one or not
27 function PMA_STR_isAlnum($c)
29 return (PMA_STR_isUpper($c) ||
PMA_STR_isLower($c) ||
PMA_STR_isDigit($c));
30 } // end of the "PMA_STR_isAlnum()" function
33 * Checks if a character is an alphabetic one
35 * @uses PMA_STR_isUpper()
36 * @uses PMA_STR_isLower()
37 * @param string character to check for
38 * @return boolean whether the character is an alphabetic one or not
40 function PMA_STR_isAlpha($c)
42 return (PMA_STR_isUpper($c) ||
PMA_STR_isLower($c));
43 } // end of the "PMA_STR_isAlpha()" function
46 * Checks if a character is a digit
48 * @uses PMA_STR_numberInRangeInclusive()
50 * @param string character to check for
51 * @return boolean whether the character is a digit or not
53 function PMA_STR_isDigit($c)
55 $ord_zero = 48; //ord('0');
56 $ord_nine = 57; //ord('9');
59 return PMA_STR_numberInRangeInclusive($ord_c, $ord_zero, $ord_nine);
60 } // end of the "PMA_STR_isDigit()" function
63 * Checks if a character is an upper alphabetic one
65 * @uses PMA_STR_numberInRangeInclusive()
67 * @param string character to check for
68 * @return boolean whether the character is an upper alphabetic one or not
70 function PMA_STR_isUpper($c)
72 $ord_zero = 65; //ord('A');
73 $ord_nine = 90; //ord('Z');
76 return PMA_STR_numberInRangeInclusive($ord_c, $ord_zero, $ord_nine);
77 } // end of the "PMA_STR_isUpper()" function
80 * Checks if a character is a lower alphabetic one
82 * @uses PMA_STR_numberInRangeInclusive()
84 * @param string character to check for
85 * @return boolean whether the character is a lower alphabetic one or not
87 function PMA_STR_isLower($c)
89 $ord_zero = 97; //ord('a');
90 $ord_nine = 122; //ord('z');
93 return PMA_STR_numberInRangeInclusive($ord_c, $ord_zero, $ord_nine);
94 } // end of the "PMA_STR_isLower()" function
97 * Checks if a character is a space one
99 * @uses PMA_STR_numberInRangeInclusive()
101 * @param string character to check for
102 * @return boolean whether the character is a space one or not
104 function PMA_STR_isSpace($c)
106 $ord_space = 32; //ord(' ')
107 $ord_tab = 9; //ord('\t')
108 $ord_CR = 13; //ord('\n')
109 $ord_NOBR = 160; //ord('U+00A0);
112 return ($ord_c == $ord_space
113 ||
$ord_c == $ord_NOBR
114 ||
PMA_STR_numberInRangeInclusive($ord_c, $ord_tab, $ord_CR));
115 } // end of the "PMA_STR_isSpace()" function
118 * Checks if a character is an hexadecimal digit
120 * @uses PMA_STR_numberInRangeInclusive()
122 * @param string character to check for
123 * @return boolean whether the character is an hexadecimal digit or not
125 function PMA_STR_isHexDigit($c)
127 $ord_Aupper = 65; //ord('A');
128 $ord_Fupper = 70; //ord('F');
129 $ord_Alower = 97; //ord('a');
130 $ord_Flower = 102; //ord('f');
131 $ord_zero = 48; //ord('0');
132 $ord_nine = 57; //ord('9');
135 return (PMA_STR_numberInRangeInclusive($ord_c, $ord_zero, $ord_nine)
136 ||
PMA_STR_numberInRangeInclusive($ord_c, $ord_Aupper, $ord_Fupper)
137 ||
PMA_STR_numberInRangeInclusive($ord_c, $ord_Alower, $ord_Flower));
138 } // end of the "PMA_STR_isHexDigit()" function