PageRenderTime 152ms CodeModel.GetById 46ms app.highlight 3ms RepoModel.GetById 102ms app.codeStats 0ms

/phpMyAdmin/libraries/string_type_native.lib.php

https://bitbucket.org/tonnyz/scan_ccv
PHP | 125 lines | 55 code | 13 blank | 57 comment | 9 complexity | 4df8c104640e70b9321e05c13f46dfba MD5 | raw file
  1<?php
  2/* vim: set expandtab sw=4 ts=4 sts=4: */
  3/**
  4 * Specialized String Functions for phpMyAdmin
  5 *
  6 * Copyright 2002 Robin Johnson <robbat2@users.sourceforge.net>
  7 * http://www.orbis-terrarum.net/?l=people.robbat2
  8 *
  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).
 12 *
 13 * The SQL Parser code relies heavily on these functions.
 14 *
 15 * @package PhpMyAdmin-StringType-Native
 16 */
 17
 18/**
 19 * Checks if a character is an alphanumeric one
 20 *
 21 * @param string   character to check for
 22 * @return  boolean  whether the character is an alphanumeric one or not
 23 */
 24function PMA_STR_isAlnum($c)
 25{
 26    return (PMA_STR_isUpper($c) || PMA_STR_isLower($c) || PMA_STR_isDigit($c));
 27} // end of the "PMA_STR_isAlnum()" function
 28
 29/**
 30 * Checks if a character is an alphabetic one
 31 *
 32 * @param string   character to check for
 33 * @return  boolean  whether the character is an alphabetic one or not
 34 */
 35function PMA_STR_isAlpha($c)
 36{
 37    return (PMA_STR_isUpper($c) || PMA_STR_isLower($c));
 38} // end of the "PMA_STR_isAlpha()" function
 39
 40/**
 41 * Checks if a character is a digit
 42 *
 43 * @param string   character to check for
 44 * @return  boolean  whether the character is a digit or not
 45 */
 46function PMA_STR_isDigit($c)
 47{
 48    $ord_zero = 48; //ord('0');
 49    $ord_nine = 57; //ord('9');
 50    $ord_c    = ord($c);
 51
 52    return PMA_STR_numberInRangeInclusive($ord_c, $ord_zero, $ord_nine);
 53} // end of the "PMA_STR_isDigit()" function
 54
 55/**
 56 * Checks if a character is an upper alphabetic one
 57 *
 58 * @param string   character to check for
 59 * @return  boolean  whether the character is an upper alphabetic one or not
 60 */
 61function PMA_STR_isUpper($c)
 62{
 63    $ord_zero = 65; //ord('A');
 64    $ord_nine = 90; //ord('Z');
 65    $ord_c    = ord($c);
 66
 67    return PMA_STR_numberInRangeInclusive($ord_c, $ord_zero, $ord_nine);
 68} // end of the "PMA_STR_isUpper()" function
 69
 70/**
 71 * Checks if a character is a lower alphabetic one
 72 *
 73 * @param string   character to check for
 74 * @return  boolean  whether the character is a lower alphabetic one or not
 75 */
 76function PMA_STR_isLower($c)
 77{
 78    $ord_zero = 97;  //ord('a');
 79    $ord_nine = 122; //ord('z');
 80    $ord_c    = ord($c);
 81
 82    return PMA_STR_numberInRangeInclusive($ord_c, $ord_zero, $ord_nine);
 83} // end of the "PMA_STR_isLower()" function
 84
 85/**
 86 * Checks if a character is a space one
 87 *
 88 * @param string   character to check for
 89 * @return  boolean  whether the character is a space one or not
 90 */
 91function PMA_STR_isSpace($c)
 92{
 93    $ord_space = 32;    //ord(' ')
 94    $ord_tab   = 9;     //ord('\t')
 95    $ord_CR    = 13;    //ord('\n')
 96    $ord_NOBR  = 160;   //ord('U+00A0);
 97    $ord_c     = ord($c);
 98
 99    return ($ord_c == $ord_space
100         || $ord_c == $ord_NOBR
101         || PMA_STR_numberInRangeInclusive($ord_c, $ord_tab, $ord_CR));
102} // end of the "PMA_STR_isSpace()" function
103
104/**
105 * Checks if a character is an hexadecimal digit
106 *
107 * @param string   character to check for
108 * @return  boolean  whether the character is an hexadecimal digit or not
109 */
110function PMA_STR_isHexDigit($c)
111{
112    $ord_Aupper = 65;  //ord('A');
113    $ord_Fupper = 70;  //ord('F');
114    $ord_Alower = 97;  //ord('a');
115    $ord_Flower = 102; //ord('f');
116    $ord_zero   = 48;  //ord('0');
117    $ord_nine   = 57;  //ord('9');
118    $ord_c      = ord($c);
119
120    return (PMA_STR_numberInRangeInclusive($ord_c, $ord_zero, $ord_nine)
121         || PMA_STR_numberInRangeInclusive($ord_c, $ord_Aupper, $ord_Fupper)
122         || PMA_STR_numberInRangeInclusive($ord_c, $ord_Alower, $ord_Flower));
123} // end of the "PMA_STR_isHexDigit()" function
124
125?>