Build a array from a postgres' hstore string representation
@param string
@return array
171853
private function fromStringToArray( $str )
    {

        $p = 0;

        // Leading spaces.
        $c = $this->charAfterSpaces( $str, $p );
        if( $c === false ) {
            return array();
        }

        $result = [];

        while (true) {

            $c = $this->charAfterSpaces($str, $p);

            // end of string
            if ($c === false) {
                break;
            }

            // next element
            if ($c == ',') {
                $p++;
                continue;
            }

            // key
            $key = $this->readKeyValue($str, $p);

            // '=>' sequence.
            $this->charAfterSpaces($str, $p);
            if (substr($str, $p, 2) != '=>') {
                throw new \Exception("Was expecting a `=>` {$str} when passing hstore's value");
            }
            $p += 2;
            $this->charAfterSpaces($str, $p);

            // value, null safe
            $value = $this->readKeyValue($str, $p);
            if (!strcasecmp($value, "null")) {
                $result[$key] = null;
            } else {
                $result[$key] = $value;
            }

        }

        return $result;
    }
725423
private function arrayToString($array, $timestamp)
    {
        $string = [];

        foreach ($array as $component) {
            $item = [];
            foreach ($component as $key => $value) {
                if ($key == 'migration') {
                    $value = $timestamp;
                }

                if ($value != null){
                    $item[] = '"'.$key.'" => "'.$value.'"';
                } else {
                    $item[] = '"'.$key.'" => null';
                }

            }

            $string[] = "[".implode(",", $item)."]\n";
        }

        return "[\n            ".implode("            ,", $string)."        ]";
    }
264573
function parse($str) {
		preg_match_all('/(\w+|\*)\h*=\h*(?:\[(.+?)\]|(.+?))(?=,|$)/',
			$str,$pairs,PREG_SET_ORDER);
		$out=[];
		foreach ($pairs as $pair)
			if ($pair[2]) {
				$out[$pair[1]]=[];
				foreach (explode(',',$pair[2]) as $val)
					array_push($out[$pair[1]],$val);
			}
			else
				$out[$pair[1]]=trim($pair[3]);
		return $out;
	}
751125
public static String[] buildArrayWithDelimiter(String stringWithDelimiter,
            String delimiter) {
        return toArray(JMCollections
                .buildListWithDelimiter(stringWithDelimiter, delimiter));
    }
347882
protected static function getStringTypeArray($type, $string, array &$matches)
    {
        return [
            Tokenizer::TOKEN_TYPE => $type,
            Tokenizer::TOKEN_VALUE => \substr($string, 0, \strlen($matches[1])),
        ];
    }
421186
public function decodeArray($string, $fieldName = null, $assoc = false)
    {
        if (empty($string)) {
            return [];
        }
        $array = self::decode($string, $fieldName, $assoc);
        if (is_string($array)) {
            $array = self::decode($array, $fieldName, $assoc);
        }
        if (!is_array($array)) {
            throw new \Exception('The field '.$fieldName.' is not a JSON array as expected.');
        }

        return $array;
    }
188724
static function toArray($kvs, $strict=false)
    {
        $lines = explode("\n", $kvs);

        $last = array_pop($lines);
        if ($last !== '') {
            array_push($lines, $last);
            if ($strict) {
                return false;
            }
        }

        $values = array();

        for ($lineno = 0; $lineno < count($lines); $lineno++) {
            $line = $lines[$lineno];
            $kv = explode(':', $line, 2);
            if (count($kv) != 2) {
                if ($strict) {
                    return false;
                }
                continue;
            }

            $key = $kv[0];
            $tkey = trim($key);
            if ($tkey != $key) {
                if ($strict) {
                    return false;
                }
            }

            $value = $kv[1];
            $tval = trim($value);
            if ($tval != $value) {
                if ($strict) {
                    return false;
                }
            }

            $values[$tkey] = $tval;
        }

        return $values;
    }
1238410
public static function stringToValueAndUnit(string $string): array
    {
        preg_match('/^([0-9.]+)([a-zA-Z]+)$/', $string, $matches);
        $value = (float) $matches[1];
        $unit = Mapper::getUnitFromAbbreviation($matches[2]);
        return [$value, $unit];
    }
66888
function toArray($crlf = true)
    {
        $headers = array();

        foreach ($this->_headers as $header) {
            $string = $header->__toString();
            $headers[] = $crlf ? $string : rtrim($string);
        }

        return $headers;
    }
562016
public function parse(string $string)
    {
        $array = [];

        foreach ($this->splitItems($string) as $item) {
            $array[] = $this->splitItem($item);
        }

        return $array;
    }
259005
function stringToHash(hashAsString) {
        var entries = {};
        if (hashAsString) {
            var text = decodeURI(hashAsString);
            var items = text.split('&');
            angular.forEach(items, function (item) {
                var kv = item.split('=');
                var key = kv[0];
                var value = kv[1] || key;
                entries[key] = value;
            });
        }
        return entries;
    }
787723
private function parseQuery($string)
    {
        $return = array();
        $parts = explode("&", $string);
        foreach ($parts as $part) {
            list($key, $value) = explode('=', $part, 2);
            $value = urldecode($value);
            if (isset($return[$key])) {
                if (!is_array($return[$key])) {
                    $return[$key] = array($return[$key]);
                }
                $return[$key][] = $value;
                continue;
            }
            $return[$key] = $value;
        }
        return $return;
    }
921313
public static function unpack($string)
    {
        if (strlen($string) !== 8) {
            throw new StorageException("The string is not 64 bit long.");
        }
        $unpack = unpack("d", $string);
        if (!is_array($unpack) || !array_key_exists(1, $unpack)) {
            throw new StorageException("Could not unpack string.");
        }
        return $unpack[1];
    }
1025845
private function buildSetPart($values)
    {
        $result = [];
        foreach ($values as $columnName => $value) {
            $value = $this->protectExpressionValue($value);
            $result[] = $this->quoteIdentifier($columnName) . ' = ' . $value;
        }

        return implode(', ', $result);
    }
473194
private function convertHashToArrayOfBoolean()
    {
        $matches = str_split($this->hash, 1);
        foreach ($matches as $i => $match) {
            $index = (int) ($i / $this->block);
            $data = $this->convertHexaToBool($match);
            $items = [
                0 => [0, 2],
                1 => [1, 4],
                2 => [2, 6],
                3 => [3, 8],
            ];
            foreach ($items[$i % $this->block] as $item) {
                $this->arrayOfSquare[$index][$item] = $data;
            }

            ksort($this->arrayOfSquare[$index]);
        }
        preg_match_all('/(\d)[\w]/', $this->hash, $matches);
        $this->color = array_map(function ($data) {
            return hexdec($data) * 16;
        }, array_reverse($matches[1]));

        return $this;
    }
955545
public static function convertPingppObjectToArray($values, $keep_object = false)
    {
        $results = array();
        foreach ($values as $k => $v) {
            // FIXME: this is an encapsulation violation
            if ($k[0] == '_') {
                continue;
            }
            if ($v instanceof PingppObject) {
                $results[$k] = $keep_object ? $v->__toStdObject(true) : $v->__toArray(true);
            } else if (is_array($v)) {
                $results[$k] = self::convertPingppObjectToArray($v, $keep_object);
            } else {
                $results[$k] = $v;
            }
        }
        return $results;
    }
183094
private static function mbStringToArray($string)
    {
        $stop   = mb_strlen($string, 'utf-8');
        $result = array();

        for ($idx = 0; $idx < $stop; $idx++) {
            $result[] = mb_substr($string, $idx, 1, 'utf-8');
        }

        return $result;
    }