PhpOrient\Protocols\Binary\Serialization\CSV::eatNumber PHP Method

eatNumber() protected static method

If the number has a suffix, consume it also and instantiate the right type, e.g. for dates
protected static eatNumber ( string $input ) : array
$input string The input to consume
return array The collected number and any remaining content.
    protected static function eatNumber($input)
    {
        $length = strlen($input);
        $collected = '';
        $isFloat = false;
        for ($i = 0; $i < $length; $i++) {
            $c = $input[$i];
            if ($c === '-' || is_numeric($c) || $c == 'E') {
                $collected .= $c;
            } elseif ($c === '.') {
                $isFloat = true;
                $collected .= $c;
            } else {
                break;
            }
        }
        $input = substr($input, $i);
        if (!isset($input[0])) {
            return [$collected, $input];
        }
        $c = $input[0];
        $useStrings = PHP_INT_SIZE == 4;
        if ($c === 'a' || $c === 't') {
            # date / 1000
            $dt = new \DateTimeZone(date_default_timezone_get());
            $collected = \DateTime::createFromFormat('U', substr($collected, 0, -3));
            $collected->setTimeZone($dt);
            $input = substr($input, 1);
        } elseif ($c === 'f') {
            // float
            if (!$useStrings) {
                $collected = (double) $collected;
            }
            $input = substr($input, 1);
        } elseif ($c === 'b' || $c === 's' || $c === 'l') {
            if (!$useStrings) {
                $collected = (int) $collected;
            }
            $input = substr($input, 1);
        } elseif ($c === 'c' || $c === 'd') {
            if (!$useStrings) {
                $collected = (double) $collected;
            }
            $input = substr($input, 1);
        } elseif ($isFloat) {
            if (!$useStrings) {
                $collected = (double) $collected;
            }
        } else {
            if (!$useStrings) {
                $collected = (int) $collected;
            }
        }
        return [$collected, $input];
    }