static function parseContentRange()

in src/Utils.php [352:400]


    static function parseContentRange($range)
    {
        // doesn't start with 'bytes ' or empty
        if (strncmp($range, 'bytes ', 6) != 0) {
            return false;
        }
        $range = substr($range, 6);

        // contains no '-'
        $vals = explode('-', $range);
        if (count($vals) != 2) {
            return false;
        }

        // start
        $vals[0] = trim($vals[0]);
        if ($vals[0] == '') {
            return false;
        }
        $start = intval($vals[0]);
        if ($start < 0 || ($start == 0 && $vals[0] != '0')) {
            return false;
        }

        $vals = explode('/', $vals[1]);

        // end
        $vals[0] = trim($vals[0]);
        if ($vals[0] == '') {
            return false;
        }
        $end = intval($vals[0]);
        if ($end < 0 || ($end == 0 && $vals[0] != '0')) {
            return false;
        }

        // total
        $vals[1] = trim($vals[1]);
        if ($vals[1] == '*') {
            $total = -1;
        } else {
            $total = intval($vals[1]);
            if ($total < 0 || ($total == 0 && $vals[1] != '0')) {
                return false;
            }
        }

        return [$start, $end, $total];
    }