PageRenderTime 13ms CodeModel.GetById 8ms app.highlight 2ms RepoModel.GetById 2ms app.codeStats 0ms

/phpmyadmin/libraries/string_type_native.lib.php

https://bitbucket.org/DenizYldrm/openemr
PHP | 140 lines | 55 code | 13 blank | 72 comment | 9 complexity | 29196abb251bdf9e995f6c337f8bafa1 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 * @version $Id$
 16 */
 17
 18/**
 19 * Checks if a character is an alphanumeric one
 20 *
 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
 26 */
 27function PMA_STR_isAlnum($c)
 28{
 29    return (PMA_STR_isUpper($c) || PMA_STR_isLower($c) || PMA_STR_isDigit($c));
 30} // end of the "PMA_STR_isAlnum()" function
 31
 32/**
 33 * Checks if a character is an alphabetic one
 34 *
 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
 39 */
 40function PMA_STR_isAlpha($c)
 41{
 42    return (PMA_STR_isUpper($c) || PMA_STR_isLower($c));
 43} // end of the "PMA_STR_isAlpha()" function
 44
 45/**
 46 * Checks if a character is a digit
 47 *
 48 * @uses    PMA_STR_numberInRangeInclusive()
 49 * @uses    ord()
 50 * @param   string   character to check for
 51 * @return  boolean  whether the character is a digit or not
 52 */
 53function PMA_STR_isDigit($c)
 54{
 55    $ord_zero = 48; //ord('0');
 56    $ord_nine = 57; //ord('9');
 57    $ord_c    = ord($c);
 58
 59    return PMA_STR_numberInRangeInclusive($ord_c, $ord_zero, $ord_nine);
 60} // end of the "PMA_STR_isDigit()" function
 61
 62/**
 63 * Checks if a character is an upper alphabetic one
 64 *
 65 * @uses    PMA_STR_numberInRangeInclusive()
 66 * @uses    ord()
 67 * @param   string   character to check for
 68 * @return  boolean  whether the character is an upper alphabetic one or not
 69 */
 70function PMA_STR_isUpper($c)
 71{
 72    $ord_zero = 65; //ord('A');
 73    $ord_nine = 90; //ord('Z');
 74    $ord_c    = ord($c);
 75
 76    return PMA_STR_numberInRangeInclusive($ord_c, $ord_zero, $ord_nine);
 77} // end of the "PMA_STR_isUpper()" function
 78
 79/**
 80 * Checks if a character is a lower alphabetic one
 81 *
 82 * @uses    PMA_STR_numberInRangeInclusive()
 83 * @uses    ord()
 84 * @param   string   character to check for
 85 * @return  boolean  whether the character is a lower alphabetic one or not
 86 */
 87function PMA_STR_isLower($c)
 88{
 89    $ord_zero = 97;  //ord('a');
 90    $ord_nine = 122; //ord('z');
 91    $ord_c    = ord($c);
 92
 93    return PMA_STR_numberInRangeInclusive($ord_c, $ord_zero, $ord_nine);
 94} // end of the "PMA_STR_isLower()" function
 95
 96/**
 97 * Checks if a character is a space one
 98 *
 99 * @uses    PMA_STR_numberInRangeInclusive()
100 * @uses    ord()
101 * @param   string   character to check for
102 * @return  boolean  whether the character is a space one or not
103 */
104function PMA_STR_isSpace($c)
105{
106    $ord_space = 32;    //ord(' ')
107    $ord_tab   = 9;     //ord('\t')
108    $ord_CR    = 13;    //ord('\n')
109    $ord_NOBR  = 160;   //ord('U+00A0);
110    $ord_c     = ord($c);
111
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
116
117/**
118 * Checks if a character is an hexadecimal digit
119 *
120 * @uses    PMA_STR_numberInRangeInclusive()
121 * @uses    ord()
122 * @param   string   character to check for
123 * @return  boolean  whether the character is an hexadecimal digit or not
124 */
125function PMA_STR_isHexDigit($c)
126{
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');
133    $ord_c      = ord($c);
134
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
139
140?>