Convert data value to binary format and add it to the object table
@param string $val The data value
@return integer The position in the object table
545486
public function dataToBinary($val)
    {
        $saved_object_count = $this->writtenObjectCount++;

        $bdata = self::typeBytes("4", strlen($val)); // a is 1000, type indicator for data
        $this->objectTable[$saved_object_count] = $bdata.$val;

        return $saved_object_count;
    }
5944
public static function fromCode($val)
    {
        $val = strtoupper($val);
        if (array_key_exists($val, self::$_languages)) {
            return self::$_languages[$val];
        }
        return null;
    }
925043
private static function parseInlineTable($val)
    {
        // Check valid inline table
        if($val[0] == '{' && substr($val, -1) == '}')
        {
            $val = substr($val, 1, -1);
        }
        else
        {
            throw new Exception('Invalid inline table definition: ' . $val);
        }

        $result = new stdClass();
        $openString = false;
        $openLString = false;
        $buffer = '';

        $strLen = strlen($val);
        for($i = 0; $i < $strLen; $i++)
        {
            // Handle strings
            if($val[$i] == '"' && $val[$i - 1] != "\\")
            {
                $openString = !$openString;
            }
            elseif($val[$i] == "'") {
                $openLString = !$openLString;
            }

            if( $val[$i] == ',' && !$openString && !$openLString )
            {
                // Parse buffer
                $kv = explode('=', $buffer, 2);
                $result->{trim($kv[0])} = self::parseValue( trim($kv[1]) );

                // Clear buffer
                $buffer = '';
            }
            else
            {
                $buffer .= $val[$i];
            }
        }

        // Parse last buffer
        $kv = explode('=', $buffer, 2);
        $result->{trim($kv[0])} = self::parseValue( trim($kv[1]) );

        return $result;
    }
1004922
protected function IDiv( $val )
	{
		$numerator = $this->_value;
		$denominator = $val->getValue();

		if ( $denominator == 0 )
			throw XPath2Exception::withErrorCode( "FOAR0001", Resources::FOAR0001 );

		if ( is_nan( $denominator ) )
			throw XPath2Exception::withErrorCode( "FOAR0002", Resources::FOAR0002 );

		if ( is_nan( $numerator ) || is_infinite( $numerator ) )
			throw XPath2Exception::withErrorCode( "FOAR0002", Resources::FOAR0002 );

		return Integer::FromValue( Convert::ToDecimal( $numerator / $denominator )->getIntegerPart() );
	}
341310
public function stringToBinary($val)
    {
        $saved_object_count = -1;

        if (!isset($this->uniqueTable[$val])) {
            $saved_object_count = $this->writtenObjectCount++;
            $this->uniqueTable[$val] = $saved_object_count;
            $utf16 = false;

            for ($i=0; $i<strlen($val); ++$i) {
                if (ord($val{$i}) >= 128) {
                    $utf16 = true;
                    break;
                }
            }

            if ($utf16) {
                $bdata = self::typeBytes("6", mb_strlen($val, 'UTF-8')); // 6 is 0110, unicode string (utf16be)
                $val = self::convertCharset($val, 'UTF-8', 'UTF-16BE');
                $this->objectTable[$saved_object_count] = $bdata.$val;
            } else {
                $bdata = self::typeBytes("5", strlen($val)); // 5 is 0101 which is an ASCII string (seems to be ASCII encoded)
                $this->objectTable[$saved_object_count] = $bdata.$val;
            }
        } else {
            $saved_object_count = $this->uniqueTable[$val];
        }

        return $saved_object_count;
    }
779231
public function storageVal($val)
    {
        $mode = $this->storageMode();

        if ($mode === self::STORAGE_MODE_INT) {
            return $this->intVal($val);
        } else {
            return $this->stringVal($val);
        }
    }
857965
protected function Add( $val )
	{
		if ( ! $val instanceof ValueProxy ) throw new \InvalidArgumentException();
		return new IntProxy( $this->_value + $val->getValue() );
	}
1061973
protected function Promote( $val )
	{
		if ( ! $val instanceof ValueProxy ) throw new \InvalidArgumentException();
		return new IntProxy( Convert::ToInt32( $val->getValue() ) );
	}
1329
protected function validateCastValue($val)
    {
        if (isset($this->descriptor()->bareNumber) && $this->descriptor()->bareNumber === false) {
            return mb_ereg_replace('((^\D*)|(\D*$))', '', $val);
        }
        $isPercent = false;
        if (is_string($val)) {
            if (substr($val, -1) == '%') {
                $val = rtrim($val, '%');
                $isPercent = true;
            }
            if (isset($this->descriptor()->groupChar)) {
                $val = str_replace($this->descriptor()->groupChar, '', $val);
            }
            if (isset($this->descriptor()->decimalChar) && $this->descriptor()->decimalChar != '.') {
                $val = str_replace($this->descriptor()->decimalChar, '.', $val);
            }
        }
        if (!is_numeric($val)) {
            throw $this->getValidationException('value must be numeric', $val);
        } else {
            $val = (float) $val;
            if ($isPercent) {
                $val = $val / 100;
            }

            return $val;
        }
    }
516645
def _to_binary(val):
    """"""
    if isinstance(val, text_type):
        return val.encode('utf-8')
    assert isinstance(val, binary_type)
    return val
893978
public static function create($val)
    {
        if (self::$_prefer) {
            switch (self::$_prefer) {
                case 'gmp':
                    $ret = new BigIntegerGmp();
                    break;
                case 'bcmath':
                    $ret = new BigIntegerBcmath();
                    break;
                default:
                    throw new \UnexpectedValueException('Unknown number implementation: ' . self::$_prefer);
            }
        }
        else {
            // autodetect
            if (extension_loaded('gmp')) {
                $ret = new BigIntegerGmp();
            }
            elseif (extension_loaded('bcmath')) {
                $ret = new BigIntegerBcmath();
            }
            else {
                // TODO: potentially offer pure php implementation?
                throw new \RuntimeException('Requires GMP or bcmath extension.');
            }
        }

        if (is_int($val)) {
            $ret->_fromInteger($val);
        }
        else {
            // convert to string, if not already one
            $val = (string)$val;

            // validate string
            if (!preg_match('/^-?[0-9]+$/', $val)) {
                throw new \InvalidArgumentException('Expects a string representation of an integer.');
            }
            $ret->_fromString($val);
        }

        return $ret;
    }
667941
protected function Add( $val )
	{
		$result = $this->_value->getValue() + $val->getValue()->getValue();
	    return new LongProxy( new Long( $result ) );
	}
138820
protected function serializedValue($val)
    {
        if (is_scalar($val)) {
            return $val;
        } elseif ($val instanceof DateTimeInterface) {
            return $val->format('Y-m-d H:i:s');
        } else {
            return json_decode(json_encode($val), true);
        }
    }
106621
protected function IDiv( $val )
	{
		return Integer::FromValue( floor( Convert::ToUInt32( $this->_value /  Convert::ToUInt32( $val->getValue() ) ) ) );
	}
885489
protected function Gt( $val )
	{
	    return $this->_value->NamespaceUri > $val->getValue()->NamespaceUri ||
	    	   ( $this->_value->NamespaceUri == $val->getValue()->NamespaceUri && $this->_value->LocalName > $val->getValue()->LocalName );
	}
1151314
protected function Div( $val )
	{
		if ( ! $val instanceof ValueProxy ) throw new \InvalidArgumentException();
		$numerator = Convert::ToDouble($this->_value);
		$denominator = Convert::ToDouble( $val->getValue() );

		if ( $denominator == 0 )
			throw XPath2Exception::withErrorCode( "FOAR0001", Resources::FOAR0001 );

		return new DecimalProxy( $numerator / $denominator );
	}
410542
public function getBytes($val)
    {
        $val = trim($val);
        if ($val !== '') {
            $last = strtolower($val[strlen($val) - 1]);
            if (!is_numeric($last)) {
                $num = trim(substr($val, 0, -1));
                switch ($last) {
                    case 'g':
                        $num *= 1024;
                    case 'm':
                        $num *= 1024;
                    case 'k':
                        $num *= 1024;
                        $val = $num;
                        break;
                }
            }
        }

        return $val;
    }