5 * @copyright 2012-2019 Leaf Corcoran
7 * @license http://opensource.org/licenses/MIT MIT
9 * @link http://scssphp.github.io/scssphp
12 namespace ScssPhp\ScssPhp
;
14 use ScssPhp\ScssPhp\Base\Range
;
15 use ScssPhp\ScssPhp\Exception\RangeException
;
20 * @author Anthon Pang <anthon.pang@gmail.com>
25 * Asserts that `value` falls within `range` (inclusive), leaving
26 * room for slight floating-point errors.
28 * @param string $name The name of the value. Used in the error message.
29 * @param \ScssPhp\ScssPhp\Base\Range $range Range of values.
30 * @param array $value The value to check.
31 * @param string $unit The unit of the value. Used in error reporting.
33 * @return mixed `value` adjusted to fall within range, if it was outside by a floating-point margin.
35 * @throws \ScssPhp\ScssPhp\Exception\RangeException
37 public static function checkRange($name, Range
$range, $value, $unit = '')
40 $grace = new Range(-0.00001, 0.00001);
42 if ($range->includes($val)) {
46 if ($grace->includes($val - $range->first
)) {
50 if ($grace->includes($val - $range->last
)) {
54 throw new RangeException("$name {$val} must be between {$range->first} and {$range->last}$unit");
58 * Encode URI component
60 * @param string $string
64 public static function encodeURIComponent($string)
66 $revert = ['%21' => '!', '%2A' => '*', '%27' => "'", '%28' => '(', '%29' => ')'];
68 return strtr(rawurlencode($string), $revert);