Convert UCS-4 array into UCS-4 string

@access   private
169034
function _ucs4_to_ucs4_string($input)
    {
        $output = '';
        // Take array values and split output to 4 bytes per value
        // The bit mask is 255, which reads &11111111
        foreach ($input as $v) {
            $output .= chr(($v >> 24) & 255).chr(($v >> 16) & 255).chr(($v >> 8) & 255).chr($v & 255);
        }
        return $output;
    }
1021127
function typedArrayToUnicodeString(ua) {
    var binstr = Array.prototype.map.call(ua, function (ch) {
        return String.fromCharCode(ch);
    }).join('');
    var escstr = binstr.replace(/(.)/g, function (m, p) {
        var code = p.charCodeAt(p).toString(16).toUpperCase();
        if (code.length < 2) {
            code = '0' + code;
        }
        return '%' + code;
    });
    return decodeURIComponent(escstr);
}
428306
protected function arrayToLowercase($vars)
    {
        $result = array();

        foreach ($vars as $k => $v) {
            if (is_array($v)) {
                $result[strtolower($k)] = $this->arrayToLowercase($v);
            } else {
                $result[strtolower($k)] = strtolower($v);
            }
        }

        return $result;
    }
1318490
public function normalize()
    {
        $data = $this->get();
        if (is_array($data)) {
            $data = implode($this->separator, $data);
        }
        $data = trim($data, $this->separator);
        if (!$data) {
            $data = null;
        }

        if (get_magic_quotes_gpc()) {
            $this->set(stripslashes($data));
        } else {
            $this->set($data);
        }

        return parent::normalize();
    }
1016508
public static function MakeHashString($variables) {
        $toHash = "";
        $ucfirst = true;
        if (isset($variables["col"]) && isset($variables["op"])) {
            $ucfirst = false;
        }
        foreach ($variables as $k => $v) {
            if ($v === null) continue;
            if ($v === "") continue;
            if ($v === false) $v = "0";
            if ($k === "CRC") continue;
            if ($v === "__AW__VALUE_NOT_CHANGED") continue;
            if ($ucfirst) $k = ucfirst($k);
            if (is_array($v)) {
                if (!count($v)) continue;
                $str = Client::MakeHashString($v);
                if ($str) {
                    $toHash.= $k . "=" . $str . "&";
                }
            } else {
                $toHash.= $k . "=" . $v . "&";
            }
        }
        return $toHash = rtrim($toHash, "&");
    }
1198073
private function ucs4array_utf8($input)
    {
        $output = '';
        foreach ($input as $k => $v) {
            if ($v < 128) { // 7bit are transferred literally
                $output .= chr($v);
            } elseif ($v < (1 << 11)) { // 2 bytes
                $output .= sprintf(
                    '%s%s',
                    chr(192 + ($v >> 6)),
                    chr(128 + ($v & 63))
                );
            } elseif ($v < (1 << 16)) { // 3 bytes
                $output .= sprintf(
                    '%s%s%s',
                    chr(224 + ($v >> 12)),
                    chr(128 + (($v >> 6) & 63)),
                    chr(128 + ($v & 63))
                );
            } elseif ($v < (1 << 21)) { // 4 bytes
                $output .= sprintf(
                    '%s%s%s%s',
                    chr(240 + ($v >> 18)),
                    chr(128 + (($v >> 12) & 63)),
                    chr(128 + (($v >> 6) & 63)),
                    chr(128 + ($v & 63))
                );
            } elseif ($this->safeMode) {
                $output .= $this->safeCodepoint;
            } else {
                throw new InvalidCharacterException(
                    sprintf('Conversion from UCS-4 to UTF-8 failed: malformed input at byte %d', $k),
                    305
                );
            }
        }

        return $output;
    }
607157
public function convertFromJSUnicode($value)
    {
        $matches = array();
        preg_match_all('/\\\u[0-9a-f]{4}/ims', $value, $matches);
        if (!empty($matches[0])) {
            foreach ($matches[0] as $match) {
                $chr = chr(hexdec(substr($match, 2, 4)));
                $value = str_replace($match, $chr, $value);
            }
            $value .= "\n\u0001";
        }
        return $value;
    }
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;
    }
1312490
private function parseArray()
    {
        $length = $this->parseUnsignedInt32();
        $stopAt = strlen($this->buffer) - $length;
        $array = [];

        while (strlen($this->buffer) > $stopAt) {
            $array[] = $this->parseField();
        }

        return $array;
    }
1166874
private static function _numberToString($price, $numbersScript, $sex, $forms, $saveFloat) {
        $result             = array();
        $tmp                = explode('.', str_replace(',','.', $price));

        $integerPart        = number_format($tmp[0], 0, '','-');
        if ($integerPart == 0) {
            $result[] = $numbersScript['0'];
        }

        $fractionalPart     = isset($tmp[1]) ? substr(str_pad($tmp[1], 2, '0', STR_PAD_RIGHT), 0, 2) : '00';
        $segments           = explode('-', $integerPart);
        $offset             = sizeof($segments);

        if ((int)$integerPart == 0) {
            $result[] = $numbersScript['0'];
            $result[] = self::_getMorphed(0, $forms[1][0], $forms[1][1], $forms[1][2]);
        } else {
            foreach ($segments as $segment) {
                $currentSex = (int) $forms[$offset][3];
                $ri         = (int) $segment;
                if ($ri== 0 && $offset>1) {
                    $offset--;
                    continue;
                }

                $ri         = str_pad($ri, 3, '0', STR_PAD_LEFT);

                $r1         = (int)substr($ri, 0, 1);
                $r2         = (int)substr($ri, 1, 1);
                $r3         = (int)substr($ri, 2, 1);
                $r22        = (int)$r2.$r3;

                if ($ri > 99) {
                    $result[] = $numbersScript[100][$r1];
                }
                if ($r22 > 20) {
                    $result[] = $numbersScript[10][$r2];
                    $result[] = $sex[$currentSex][$r3];
                } elseif ($r22 > 9) {
                    $result[] = $numbersScript[11][$r22-9];
                } elseif ($r22 > 0) {
                    $result[] = $sex[$currentSex][$r3];
                }

                $result[]   = self::_getMorphed($ri, $forms[$offset][0], $forms[$offset][1], $forms[$offset][2]);
                $offset--;
            }
        }

        if ($saveFloat) {
            $result[] = $fractionalPart;
            $result[] = self::_getMorphed($fractionalPart, $forms[0][0], $forms[0][1], $forms[0][2]);
        }
        return preg_replace("#\s{2,}#", ' ', implode(' ',$result));
    }
1298966
private function convertHashToArrayOfBoolean()
    {
        preg_match_all('/(\w)(\w)/', $this->hash, $chars);

        foreach ($chars[1] as $i => $char) {
            $index = (int) ($i / 3);
            $data = $this->convertHexaToBoolean($char);

            $items = [
                0 => [0, 4],
                1 => [1, 3],
                2 => [2],
            ];

            foreach ($items[$i % 3] as $item) {
                $this->arrayOfSquare[$index][$item] = $data;
            }

            ksort($this->arrayOfSquare[$index]);
        }

        $this->color = array_map(function ($data) {
            return hexdec($data) * 16;
        }, array_reverse($chars[1]));

        return $this;
    }
1083273
function ucs2encode(array) {
  return _.map(array, function (value) {
    var output = '';

    if (value > 0xFFFF) {
      value -= 0x10000;
      output += String.fromCharCode(value >>> 10 & 0x3FF | 0xD800);
      value = 0xDC00 | value & 0x3FF;
    }
    output += String.fromCharCode(value);
    return output;
  }).join('');
}
346386
public function stringArrayToCsv()
    {
        $value = $this->getParameter('value');
        if (!is_array($value)) {
            $value = explode($this->getParameter('delimiter', ','), $value);
        }

        $value = array_map('trim', $value);
        if (empty($value)) {
            return '';
        }
        $value = array_filter($value, 'strlen');

        if ($this->getParameter('lowercase', false)) {
            $value = array_map('strtolower', $value);
            if ($this->getParameter('unique', true)) {
                $value = array_keys(array_flip($value));
            }
        } else {
            if ($this->getParameter('unique', true)) {
                $value = array_values(array_intersect_key($value, array_unique(array_map('strtolower', $value))));
            }
        }

        return implode(',', $value);
    }
1255207
private function utf8_ucs4array($input)
    {
        $startByte = 0;
        $nextByte = 0;

        $output = [];
        $outputLength = 0;
        $inputLength = $this->byteLength($input);
        $mode = 'next';
        $test = 'none';
        for ($k = 0; $k < $inputLength; ++$k) {
            $v = ord($input{$k}); // Extract byte from input string

            if ($v < 128) { // We found an ASCII char - put into string as is
                $output[$outputLength] = $v;
                ++$outputLength;
                if ('add' === $mode) {
                    if ($this->safeMode) {
                        $output[$outputLength - 2] = $this->safeCodepoint;
                        $mode = 'next';
                    } else {
                        throw new InvalidCharacterException(
                            sprintf(
                                'Conversion from UTF-8 to UCS-4 failed: malformed input at byte %d',
                                $k
                            ),
                            302
                        );
                    }
                }

                continue;
            }

            if ('next' === $mode) { // Try to find the next start byte; determine the width of the Unicode char
                $startByte = $v;
                $mode = 'add';
                $test = 'range';
                if ($v >> 5 === 6) { // &110xxxxx 10xxxxx
                    $nextByte = 0; // How many times subsequent bit masks must rotate 6bits to the left
                    $v = ($v - 192) << 6;
                } elseif ($v >> 4 === 14) { // &1110xxxx 10xxxxxx 10xxxxxx
                    $nextByte = 1;
                    $v = ($v - 224) << 12;
                } elseif ($v >> 3 === 30) { // &11110xxx 10xxxxxx 10xxxxxx 10xxxxxx
                    $nextByte = 2;
                    $v = ($v - 240) << 18;
                } elseif ($this->safeMode) {
                    $mode = 'next';
                    $output[$outputLength] = $this->safeCodepoint;
                    ++$outputLength;

                    continue;
                } else {
                    throw new InvalidCharacterException(
                        sprintf('This might be UTF-8, but I don\'t understand it at byte %d', $k),
                        303
                    );
                }
                if (($inputLength - $k - $nextByte) < 2) {
                    $output[$outputLength] = $this->safeCodepoint;
                    $mode = 'no';

                    continue;
                }

                if ('add' === $mode) {
                    $output[$outputLength] = (int)$v;
                    ++$outputLength;

                    continue;
                }
            }
            if ('add' == $mode) {
                if (!$this->safeMode && $test === 'range') {
                    $test = 'none';
                    if (($v < 0xA0 && $startByte === 0xE0)
                        || ($v < 0x90 && $startByte === 0xF0)
                        || ($v > 0x8F && $startByte === 0xF4)
                    ) {
                        throw new InvalidCharacterException(
                            sprintf('Bogus UTF-8 character (out of legal range) at byte %d', $k),
                            304
                        );
                    }
                }
                if ($v >> 6 === 2) { // Bit mask must be 10xxxxxx
                    $v = ($v - 128) << ($nextByte * 6);
                    $output[($outputLength - 1)] += $v;
                    --$nextByte;
                } else {
                    if ($this->safeMode) {
                        $output[$outputLength - 1] = ord($this->safeCodepoint);
                        $k--;
                        $mode = 'next';

                        continue;
                    } else {
                        throw new InvalidCharacterException(
                            sprintf('Conversion from UTF-8 to UCS-4 failed: malformed input at byte %d', $k),
                            302
                        );
                    }
                }
                if ($nextByte < 0) {
                    $mode = 'next';
                }
            }
        } // for

        return $output;
    }
284872
public static function uchr( $codes ) {

		// Single character code.
		if ( \is_scalar( $codes ) ) {
			$codes = \func_get_args(); // phpcs:ignore PHPCompatibility.FunctionUse.ArgumentFunctionsReportCurrentValue.NeedsInspection
		}

		// Deal with an array of character codes.
		$json = '"';
		foreach ( $codes as $code ) {
			$json .= \sprintf( '\u%04x', $code );
		}
		$json .= '"';

		return \json_decode( $json );
	}
208502
private static function unistr2ords($str) {
    $ords = array();
    $len = iconv_strlen($str);
    for($i = 0; $i < $len; $i++) {
      $char = iconv_substr($str, $i, 1);
      $val = self::utf8ToUnicode($char);
      if ($val !== false && array_key_exists(0, $val)) {
        $ords[] = $val[0];
      }
    }
    return $ords;
  }
1218288
function toString()
    {
        $parts = array();
        if ( ($r = parent::toString()) !== '' )
            ## avoid double slash trail issue
            $parts[] = ($r == $this->getSeparator()) ? '' : $r;
        if ( ($r = $this->getBasename()) !== '')
            $parts[] = $r;

        return implode($this->getSeparator(), $parts);
    }