Deconstruct $cspString into a CSP config array

@param string $cspString
@return array
329535
public static function deconstructCSP($cspString)
    {
        $csp = [];

        $directivesAndSources = explode(';', $cspString);

        foreach ($directivesAndSources as $directiveAndSources)
        {
            $directiveAndSources = ltrim($directiveAndSources);

            $list = explode(' ', $directiveAndSources, 2);

            $directive = strtolower($list[0]);

            if (isset($csp[$directive]))
            {
                continue;
            }

            if (isset($list[1]) and trim($list[1]) !== '')
            {
                $sourcesString = $list[1];

                $sources = explode(' ', $sourcesString);

                self::removeEmptySources($sources);
            }
            else
            {
                $sources = true;
            }

            $csp[$directive] = $sources;
        }

        return $csp;
    }
779246
protected function _ucs4_string_to_ucs4($input)
    {
        $output  = [];
        $inp_len = self::byteLength($input);
        // Input length must be dividable by 4
        if ($inp_len % 4) {
            $this->_error('Input UCS4 string is broken');

            return false;
        }
        // Empty input - return empty output
        if (!$inp_len) {
            return $output;
        }
        for ($i = 0, $out_len = -1; $i < $inp_len; ++$i) {
            // Increment output position every 4 input bytes
            if (!($i % 4)) {
                $out_len++;
                $output[$out_len] = 0;
            }
            $output[$out_len] += ord($input{$i}) << (8 * (3 - ($i % 4)));
        }

        return $output;
    }
238531
private function decodeRFC2231(\SplString $string)
    {
        if (1 !== preg_match("/^(.*?)'.*?'(.*?)$/", $string, $matches)) {
            return $string;
        }

        $encoding = $matches[1];
        $data = $matches[2];

        if (false === $this->urlHelper->isUrlEncoded($data)) {
            return $string;
        }

        $string = $this->encodingConverter->convertStringEncoding(
            urldecode($data),
            $encoding,
            $this->serverEncoding
        );

        return new \SplString($string);
    }
1205846
public function obfuscate(string $string, array $options = []): string
    {
        $options = array_merge([
            'start'       => 0,
            'end'         => 3,
            'replacement' => '*',
        ], $options);

        return StringUtils::obfuscate($string, $options['start'], $options['end'], $options['replacement']);
    }
1207400
protected function getCsvControls(array $options)
    {
        $csvControls = $this->csvControls;
        if (isset($options['delimiter'])) {
            $csvControls['delimiter'] = $options['delimiter'];
        }
        if (isset($options['enclosure'])) {
            $csvControls['enclosure'] = $options['enclosure'];
        }
        if (isset($options['escape'])) {
            $csvControls['escape'] = $options['escape'];
        }
        return $csvControls;
    }
184572
private function parseHeaders($headerContent)
    {
        $headers = [];
        $headerParts = preg_split('/\\R/s', $headerContent, -1, PREG_SPLIT_NO_EMPTY);
        foreach ($headerParts as $headerPart) {
            if (strpos($headerPart, ':') === false) {
                continue;
            }

            [$headerName, $headerValue] = explode(':', $headerPart, 2);
            $headerName = strtolower(trim($headerName));
            $headerValue = trim($headerValue);

            if (strpos($headerValue, ';') === false) {
                $headers[$headerName] = $headerValue;
            } else {
                $headers[$headerName] = [];
                foreach (explode(';', $headerValue) as $part) {
                    $part = trim($part);
                    if (strpos($part, '=') === false) {
                        $headers[$headerName][] = $part;
                    } else {
                        [$name, $value] = explode('=', $part, 2);
                        $name = strtolower(trim($name));
                        $value = trim(trim($value), '"');
                        $headers[$headerName][$name] = $value;
                    }
                }
            }
        }

        return $headers;
    }
289716
public function decodeNULstrings($data, $limit = 1, &$p = 0)
    {
        $r = [];

        for ($i = 0; $i < $limit; ++$i) {
            $pos = mb_orig_strpos($data, "\x00", $p);

            if ($pos === false) {
                break;
            }

            $r[] = mb_orig_substr($data, $p, $pos - $p);

            $p = $pos + 1;
        }

        return $r;
    }
818799
private function decodeStruct($struct) {

        $return_value = array();

        foreach ( $struct->member as $member ) {

            $name = $member->name."";
            $value = $this->decodeValue($member->value);
            $return_value[$name] = $value;

        }

        return $return_value;

    }
409732
protected function decodeJson($jsonString)
    {
        $jsonErrors = [
            \JSON_ERROR_DEPTH => 'JSON_ERROR_DEPTH - Maximum stack depth exceeded',
            \JSON_ERROR_STATE_MISMATCH => 'JSON_ERROR_STATE_MISMATCH - Underflow or the modes mismatch',
            \JSON_ERROR_CTRL_CHAR => 'JSON_ERROR_CTRL_CHAR - Unexpected control character found',
            \JSON_ERROR_SYNTAX => 'JSON_ERROR_SYNTAX - Syntax error, malformed JSON',
            \JSON_ERROR_UTF8 => 'JSON_ERROR_UTF8 - Malformed UTF-8 characters, possibly incorrectly encoded'
        ];

        // Can we use JSON_BIGINT_AS_STRING?
        $options = (version_compare(\PHP_VERSION, '5.4.0', '>=') and ! (defined('JSON_C_VERSION') and \PHP_INT_SIZE > 4)) ? \JSON_BIGINT_AS_STRING : 0;
        $data = json_decode($jsonString, false, 512, $options);

        if (json_last_error() !== \JSON_ERROR_NONE) {
            $last = json_last_error();

            $error = 'Unknown error';

            if (isset($jsonErrors[$last])) {
                $error = $jsonErrors[$last];
            }

            throw new InputException('Unable to parse JSON data: ' . $error);
        }

        return $data;
    }
156902
private static String decodeLineString(LineString lineString) {
		if (lineString == null || lineString.isEmpty()) {
			return "";
		}
		StringBuilder buffer = new StringBuilder();
		Coordinate[] coordinates = lineString.getCoordinates();
		for (int i = 0; i < coordinates.length; i++) {
			buffer.append(getX(coordinates[i]));
			buffer.append(" ");
			buffer.append(getY(coordinates[i]));
			if (i < (coordinates.length - 1)) {
				buffer.append(", ");
			}
		}
		return "M" + buffer.toString();
	}
837317
public static function structToString($struct, array $options = [])
    {
        $header = StructureHelper::getValue($options, 'header');
        $asArray = StructureHelper::getValue($options, 'as_array');
        $strict = StructureHelper::getValue($options, 'strict');

        // Build the object variables string
        $vars = '';

        foreach ($struct as $k => $v) {
            if (is_scalar($v)) {
                $vars .= sprintf("    '%s' => '%s',\n", $k, addcslashes($v, '\\\''));
            } elseif (is_array($v) || is_object($v)) {
                $vars .= sprintf("    '%s' => %s,\n", $k, static::getArrayString((array) $v));
            }
        }

        if (!$asArray) {
            if ($strict) {
                $str = "<?php declare(strict_types=1);\n";
            } else {
                $str = "<?php\n";
            }

            if ($header) {
                $str .= $header . "\n";
            }

            $str .= "\nreturn [\n";
        } else {
            $str = "[\n";
        }

        $str .= $vars;
        $str .= ']';

        if (!$asArray) {
            $str .= ";\n";

            // Use the closing tag if set to true in parameters.
            if (StructureHelper::getValue($options, 'closingtag', false)) {
                $str .= "\n?>";
            }
        }

        return $str;
    }
477424
protected function validateMultiLineStringValue(array $lineStrings)
    {
        foreach ($lineStrings as &$lineString) {
            $lineString = $this->validateLineStringValue($lineString);
        }

        return $lineStrings;
    }
27526
public function parsePhpDoc($pString)
    {
        preg_match('#^/\*\*(.*)\*/#s', trim($pString), $comment);

        if (0 === count($comment)) return array();

        $comment = trim($comment[1]);

        preg_match_all('/^\s*\*(.*)/m', $comment, $lines);
        $lines = $lines[1];

        $tags = array();
        $currentTag = '';
        $currentData = '';

        foreach ($lines as $line) {
            $line = trim($line);

            if (substr($line, 0, 1) == '@') {

                if ($currentTag)
                    $tags[$currentTag][] = $currentData;
                else
                    $tags['description'] = $currentData;

                $currentData = '';
                preg_match('/@([a-zA-Z_]*)/', $line, $match);
                $currentTag = $match[1];
            }

            $currentData = trim($currentData.' '.$line);

        }
        if ($currentTag)
            $tags[$currentTag][] = $currentData;
        else
            $tags['description'] = $currentData;

        //parse tags
        $regex = array(
            'param' => array('/^@param\s*\t*([a-zA-Z_\\\[\]]*)\s*\t*\$([a-zA-Z_]*)\s*\t*(.*)/', array('type', 'name', 'description')),
            'url' => array('/^@url\s*\t*(.+)/', array('url')),
            'return' => array('/^@return\s*\t*([a-zA-Z_\\\[\]]*)\s*\t*(.*)/', array('type', 'description')),
        );
        foreach ($tags as $tag => &$data) {
            if ($tag == 'description') continue;
            foreach ($data as &$item) {
                if (isset($regex[$tag])) {
                    preg_match($regex[$tag][0], $item, $match);
                    $item = array();
                    $c = count($match);
                    for ($i =1; $i < $c; $i++) {
                        if (isset($regex[$tag][1][$i-1])) {
                            $item[$regex[$tag][1][$i-1]] = $match[$i];
                        }
                    }
                }
            }
            if (count($data) == 1)
                $data = $data[0];
        }

        return $tags;
    }
120626
protected function stripExistingCssCharsets($css)
    {
        if (!($css = (string) $css)) {
            return $css; // Nothing to do.
        }
        $css        = preg_replace('/@(?:\-(?:'.$this->regex_vendor_css_prefixes.')\-)?charset(?:\s+[^;]*?)?;/ui', '', $css);
        return $css = $css ? trim($css) : $css;
    }
953972
public static function decode(array $headers = []): array
    {
        $encodedHeaders = [];
        $encodedProperties = [];
        $prefixLength = strlen(self::PROPERTY_PREFIX);

        // separate headers/properties
        foreach ($headers as $key => $value) {
            if (0 === strpos($key, self::PROPERTY_PREFIX)) {
                $encodedProperties[substr($key, $prefixLength)] = $value;
            } else {
                $encodedHeaders[$key] = $value;
            }
        }

        $decodedHeaders = self::doDecode($encodedHeaders);
        $decodedProperties = self::doDecode($encodedProperties);

        return [$decodedHeaders, $decodedProperties];
    }
1195408
public byte decodeBuffer(String inputString)[] throws IOException {
        byte    inputBuffer[] = new byte[inputString.length()];
        ByteArrayInputStream inStream;
        ByteArrayOutputStream outStream;

        inputString.getBytes(0, inputString.length(), inputBuffer, 0);
        inStream = new ByteArrayInputStream(inputBuffer);
        outStream = new ByteArrayOutputStream();
        decodeBuffer(inStream, outStream);
        return (outStream.toByteArray());
    }
201311
function _ucs4_string_to_ucs4($input)
    {
        $output = array();
        $inp_len = strlen($input);
        // Input length must be dividable by 4
        if ($inp_len % 4) {
            $this->_error('Input UCS4 string is broken');
            return false;
        }
        // Empty input - return empty output
        if (!$inp_len) return $output;
        for ($i = 0, $out_len = -1; $i < $inp_len; ++$i) {
            // Increment output position every 4 input bytes
            if (!($i % 4)) {
                $out_len++;
                $output[$out_len] = 0;
            }
            $output[$out_len] += ord($input{$i}) << (8 * (3 - ($i % 4) ) );
        }
        return $output;
    }