<?

# token class for queries
# Copyright (c) Adriane Boyd

# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA

class Token
{
    var 
$val;    # value of this token
    
var $isOp;    # 1 if this token is an operator

    
function Token($value ""$type 0)
    {
        
$this->val $value;
        if(
$type 0)
        {
            
$this->isOp 1;
        }
        else
        {
            
$this->isOp 0;
        }
    }

    function 
getValue()
    {
        return 
$this->val;
    }

    
# return value, properly escaped for mysql
    # if $rel is like, * becomes %
    # if $rel is regexp or rlike, * becomes .*
    # all problem characters are backslashed
    
function getEValue($rel)
    {
        
$val $this->val;
        if(
preg_match("/regexp|rlike/"$rel))
        {
            
$val preg_quote($val);
            
$val preg_replace("/\*/""%"$val);
        }
        else if(
preg_match("/like/"$rel))
        {
            
$val preg_replace("/\*/""%"$val);
        }
        
$val addslashes($val);
        if(
preg_match("/regexp|rlike/"$rel))
        {
            
$val preg_replace("/\\\\\\\\%/"".*"$val);
        }
        return 
$val;
    }

    function 
getType()
    {
        return 
$this->isOp;
    }

    function 
setValue($value)
    {
        
$this->val $value;
    }

    function 
setOperator()
    {
        
$this->isOp 1;
    }

    function 
isOperator()
    {
        if(
$this->isOp 0)
        {
            return 
1;
        }
        else
        {
            return 
0;
        }
    }
}

?>