Remove padding.

@param string $data
@throws \UnexpectedValueException
@return string
516120
public function remove(string $data): string
    {
        $len = strlen($data);
        if (!$len) {
            throw new \UnexpectedValueException("No padding.");
        }
        $n = ord($data[$len - 1]);
        if ($len < $n || $n > $this->_blocksize) {
            throw new \UnexpectedValueException("Invalid padding length.");
        }
        $ps = substr($data, -$n);
        if ($ps !== str_repeat(chr($n), $n)) {
            throw new \UnexpectedValueException("Invalid padding string.");
        }
        return substr($data, 0, -$n);
    }
103798
public static function encodeUrlSafeWithoutPadding($data) {
		$encoded = self::encode($data);

		$encoded = \rtrim(
			$encoded,
			\substr(self::LAST_THREE_STANDARD, -1)
		);

		return \strtr(
			$encoded,
			\substr(self::LAST_THREE_STANDARD, 0, -1),
			\substr(self::LAST_THREE_URL_SAFE, 0, -1)
		);
	}
836176
protected static function unpad($value)
        {
            $pad = ord($value[($length = Inflector::length($value)) - 1]);
            if ($pad and $pad < static::$block) {
                // If the correct padding is present on the string, we will remove
                // it and return the value. Otherwise, we'll throw an exception
                // as the padding appears to have been changed.
                if (preg_match('/' . chr($pad) . '{' . $pad . '}$/', $value)) {
                    return substr($value, 0, $length - $pad);
                } else {
                    throw new Exception("Decryption error. Padding is invalid.");
                }
            }

            return $value;
        }
458662
public function filterProtectedData($data)
    {
        if ($data && isset($this['fields']) && isset($this['protected_fields']) && $this['protected_fields']) {
            if (isset($data[0]) || is_numeric(key($data))) {
                foreach ($data as $k => $v) {
                    $data[$k] = static::filterProtectedData($v);
                }
            } else {
                $fields = array_keys($this['fields']);
                $pfields = StringHelper::toArray($this['protected_fields']);
                foreach ($data as $k => $v) {
                    if (in_array($k, $fields) && in_array($k, $pfields)) {
                        unset($data[$k]);
                    }
                }
            }
        }
        
        return $data;
    }
1361321
public function fix($data)
    {
        $regex = '~(?P<header>^\s*<\?php(?:(?:(?:/\*.*?\*/)|(?:(?://|#).*?\n{1})|(?:\s*))*))(?P<declare>\s*declare\(\s*strict_types\s*=\s*[01]{1}\s*\)\s*;\s*\n*)?(?P<other>.*)~s';
        preg_match($regex, $data, $results);

        if (!isset($results['header'])) {
            return false;
        }

        $header = $results['header'];
        $other = isset($results['other']) ? $results['other'] : '';

        $fixedData = trim($header) . rtrim("\n\n" . $this->strict . "\n\n") . "\n\n" . ltrim($other);

        return $fixedData !== $data
            ? $fixedData
            : false;
    }
731935
protected function encodeMessageBody($data)
    {
        switch ($this->contentType) {
            case 'application/json':
                return json_encode($data);
            case 'application/x-httpd-php-source':
                return var_export($data, true);
            case 'vnd.php.serialized':
                return serialize($data);
            default:
                throw new \UnexpectedValueException("Serialization format unsupported: " . $this->contentType);
        }
    }
792403
public function format($data)
    {
        $data->loopThrough(function ($key, $value) use ($data) {
            if (!in_array($key, $this->fields)) {
                $data->setProperty($key, null);
            }
        });

        $data->unsetNull();

        return $data;
    }
1296707
private static function unsetValues(array &$data, array &$removeValues)
    {
        foreach ($removeValues as $value) {
            $position = \array_search($value, $data);
            if ($position !== false) {
                unset($data[$position]);
            }
        }
        return $data;
    }
47401
public function cleanKeys($data)
    {
        $pregMatches = (bool) preg_match(self::PREG_PROPERTIES, '?');
        $chars = '';
        $chars = $pregMatches ? '\pL' : 'a-zA-Z';


        if (!preg_match('#^['.$chars.'0-9:_.-]++$#uD', $data)) {
            throw new \Exception('Illegal key characters in global data');
        }

        return $data;
    }
744975
public function convertToString($data) {
		if (!is_string($data)) {
			$data = @json_encode($data, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
			// Removing null byte and double slashes from object properties
			$data = str_replace(['\\u0000', '\\\\'], ["", "\\"], $data);
		}

		return $data;
	}
1023606
protected function cleanData($data)
    {
        $replacementChars = array(
            "\xe2\x80\x98" => "'",   // ‘
            "\xe2\x80\x99" => "'",   // ’
            "\xe2\x80\x9a" => "'",   // ‚
            "\xe2\x80\x9b" => "'",   // ‛
            "\xe2\x80\x9c" => '"',   // “
            "\xe2\x80\x9d" => '"',   // ”
            "\xe2\x80\x9e" => '"',   // „
            "\xe2\x80\x9f" => '"',   // ‟
            "\xe2\x80\x93" => '-',   // –
            "\xe2\x80\x94" => '--',  // —
            "\xe2\x80\xa6" => '...', // …
            "\xc2\xa0"     => ' ',
        );
        // Replace UTF-8 characters
        $cleanedData = strtr($data, $replacementChars);

        // Replace Windows-1252 equivalents
        $charsToReplace = array_map(function ($code) {
            return $this->mb_chr($code);
        }, array(133, 145, 146, 147, 148, 150, 151, 194));
        $cleanedData = $this->mb_str_replace($charsToReplace, $replacementChars, $cleanedData);

        return $cleanedData;
    }
658149
protected function unpadString($string)
    {
        $len = strlen($string);
        $pad = ord($string[$len - 1]);

        return substr($string, 0, $len - $pad);
    }
796706
public function parseReadData($data)
	{
		$results = array();

		foreach ($data as $row) {
			if (is_array($row)) {
				$key = $row[$this->keyColumn];
				$value = $row[$this->valueColumn];
			} elseif (is_object($row)) {
				$key = $row->{$this->keyColumn};
				$value = $row->{$this->valueColumn};
			} else {
				$msg = 'Expected array or object, got '.gettype($row);
				throw new \UnexpectedValueException($msg);
			}

			ArrayUtil::set($results, $key, $value);
		}

		return $results;
	}
963990
public function withoutFalseyValues($data)
    {
        for ($i = 0; $i < count($data[ClientResource::FIELD_RESOURCES]); $i++) {
            if (!$data[ClientResource::FIELD_RESOURCES][$i]['value']) {
                unset($data[ClientResource::FIELD_RESOURCES][$i]);
            }
        }

        // Resort array
        $data[ClientResource::FIELD_RESOURCES] = array_values($data[ClientResource::FIELD_RESOURCES]);

        return $data;
    }
121995
private function fixIe($data)
    {
        $data = preg_replace(
            '#(<[^>]+?)style[\x00-\x20]*=[\x00-\x20]*[`\'"]*.*?expression[\x00-\x20]*\([^>]*+>#i',
            '$1>',
            $data
        );
        $data = preg_replace(
            '#(<[^>]+?)style[\x00-\x20]*=[\x00-\x20]*[`\'"]*.*?behaviour[\x00-\x20]*\([^>]*+>#i',
            '$1>',
            $data
        );
        $data = preg_replace(
            '#(<[^>]+?)style[\x00-\x20]*=[\x00-\x20]*[`\'"]*.*?s[\x00-\x20]*c[\x00-\x20]*r[\x00-\x20]*i
            [\x00-\x20]*p[\x00-\x20]*t[\x00-\x20]*:*[^>]*+>#iu',
            '$1>',
            $data
        );

        return $data;
    }
912706
public function format(&$data) {
		$data = $this->normalize($data);
		$data = $this->convertToString($data);

		return $data;
	}
60398
protected function removeMissingValues($data)
    {
        $numericKeys = true;

        foreach ($data as $key => $value) {
            if (($value instanceof PotentiallyMissing && $value->isMissing()) ||
                ($value instanceof self &&
                $value->resource instanceof PotentiallyMissing &&
                $value->isMissing())) {
                unset($data[$key]);
            } else {
                $numericKeys = $numericKeys && is_numeric($key);
            }
        }

        if (property_exists($this, 'preserveKeys') && $this->preserveKeys === true) {
            return $data;
        }

        return $numericKeys ? array_values($data) : $data;
    }