TYPO3CMS  8
 All Classes Namespaces Files Functions Variables Pages
CharsetConverter.php
Go to the documentation of this file.
1 <?php
2 namespace TYPO3\CMS\Core\Charset;
3 
4 /*
5  * This file is part of the TYPO3 CMS project.
6  *
7  * It is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU General Public License, either version 2
9  * of the License, or any later version.
10  *
11  * For the full copyright and license information, please read the
12  * LICENSE.txt file that was distributed with this source code.
13  *
14  * The TYPO3 project - inspiring people to share!
15  */
16 
21 
55 {
61  public $noCharByteVal = 63;
62 
68  public $parsedCharsets = [];
69 
75  public $caseFolding = [];
76 
82  public $toASCII = [];
83 
89  public $twoByteSets = [
90  'ucs-2' => 1
91  ];
92 
99  public $fourByteSets = [
100  'ucs-4' => 1, // 4-byte Unicode
101  'utf-32' => 1
102  ];
103 
109  public $eucBasedSets = [
110  'gb2312' => 1, // Chinese, simplified.
111  'big5' => 1, // Chinese, traditional.
112  'euc-kr' => 1, // Korean
113  'shift_jis' => 1
114  ];
115 
122  public $synonyms = [
123  'us' => 'ascii',
124  'us-ascii' => 'ascii',
125  'cp819' => 'iso-8859-1',
126  'ibm819' => 'iso-8859-1',
127  'iso-ir-100' => 'iso-8859-1',
128  'iso-ir-101' => 'iso-8859-2',
129  'iso-ir-109' => 'iso-8859-3',
130  'iso-ir-110' => 'iso-8859-4',
131  'iso-ir-144' => 'iso-8859-5',
132  'iso-ir-127' => 'iso-8859-6',
133  'iso-ir-126' => 'iso-8859-7',
134  'iso-ir-138' => 'iso-8859-8',
135  'iso-ir-148' => 'iso-8859-9',
136  'iso-ir-157' => 'iso-8859-10',
137  'iso-ir-179' => 'iso-8859-13',
138  'iso-ir-199' => 'iso-8859-14',
139  'iso-ir-203' => 'iso-8859-15',
140  'csisolatin1' => 'iso-8859-1',
141  'csisolatin2' => 'iso-8859-2',
142  'csisolatin3' => 'iso-8859-3',
143  'csisolatin5' => 'iso-8859-9',
144  'csisolatin8' => 'iso-8859-14',
145  'csisolatin9' => 'iso-8859-15',
146  'csisolatingreek' => 'iso-8859-7',
147  'iso-celtic' => 'iso-8859-14',
148  'latin1' => 'iso-8859-1',
149  'latin2' => 'iso-8859-2',
150  'latin3' => 'iso-8859-3',
151  'latin5' => 'iso-8859-9',
152  'latin6' => 'iso-8859-10',
153  'latin8' => 'iso-8859-14',
154  'latin9' => 'iso-8859-15',
155  'l1' => 'iso-8859-1',
156  'l2' => 'iso-8859-2',
157  'l3' => 'iso-8859-3',
158  'l5' => 'iso-8859-9',
159  'l6' => 'iso-8859-10',
160  'l8' => 'iso-8859-14',
161  'l9' => 'iso-8859-15',
162  'cyrillic' => 'iso-8859-5',
163  'arabic' => 'iso-8859-6',
164  'tis-620' => 'iso-8859-11',
165  'win874' => 'windows-874',
166  'win1250' => 'windows-1250',
167  'win1251' => 'windows-1251',
168  'win1252' => 'windows-1252',
169  'win1253' => 'windows-1253',
170  'win1254' => 'windows-1254',
171  'win1255' => 'windows-1255',
172  'win1256' => 'windows-1256',
173  'win1257' => 'windows-1257',
174  'win1258' => 'windows-1258',
175  'cp1250' => 'windows-1250',
176  'cp1251' => 'windows-1251',
177  'cp1252' => 'windows-1252',
178  'ms-ee' => 'windows-1250',
179  'ms-ansi' => 'windows-1252',
180  'ms-greek' => 'windows-1253',
181  'ms-turk' => 'windows-1254',
182  'winbaltrim' => 'windows-1257',
183  'koi-8ru' => 'koi-8r',
184  'koi8r' => 'koi-8r',
185  'cp878' => 'koi-8r',
186  'mac' => 'macroman',
187  'macintosh' => 'macroman',
188  'euc-cn' => 'gb2312',
189  'x-euc-cn' => 'gb2312',
190  'euccn' => 'gb2312',
191  'cp936' => 'gb2312',
192  'big-5' => 'big5',
193  'cp950' => 'big5',
194  'eucjp' => 'euc-jp',
195  'sjis' => 'shift_jis',
196  'shift-jis' => 'shift_jis',
197  'cp932' => 'shift_jis',
198  'cp949' => 'euc-kr',
199  'utf7' => 'utf-7',
200  'utf8' => 'utf-8',
201  'utf16' => 'utf-16',
202  'utf32' => 'utf-32',
203  'ucs2' => 'ucs-2',
204  'ucs4' => 'ucs-4'
205  ];
206 
214  public $charSetArray = [
215  'af' => '',
216  'ar' => 'iso-8859-6',
217  'ba' => 'iso-8859-2',
218  'bg' => 'windows-1251',
219  'br' => '',
220  'ca' => 'iso-8859-15',
221  'ch' => 'gb2312',
222  'cs' => 'windows-1250',
223  'cz' => 'windows-1250',
224  'da' => '',
225  'de' => '',
226  'dk' => '',
227  'el' => 'iso-8859-7',
228  'eo' => 'utf-8',
229  'es' => '',
230  'et' => 'iso-8859-4',
231  'eu' => '',
232  'fa' => 'utf-8',
233  'fi' => '',
234  'fo' => 'utf-8',
235  'fr' => '',
236  'fr_CA' => '',
237  'ga' => '',
238  'ge' => 'utf-8',
239  'gl' => '',
240  'gr' => 'iso-8859-7',
241  'he' => 'utf-8',
242  'hi' => 'utf-8',
243  'hk' => 'big5',
244  'hr' => 'windows-1250',
245  'hu' => 'iso-8859-2',
246  'is' => 'utf-8',
247  'it' => '',
248  'ja' => 'shift_jis',
249  'jp' => 'shift_jis',
250  'ka' => 'utf-8',
251  'kl' => 'utf-8',
252  'km' => 'utf-8',
253  'ko' => 'euc-kr',
254  'kr' => 'euc-kr',
255  'lt' => 'windows-1257',
256  'lv' => 'utf-8',
257  'ms' => '',
258  'my' => '',
259  'nl' => '',
260  'no' => '',
261  'pl' => 'iso-8859-2',
262  'pt' => '',
263  'pt_BR' => '',
264  'qc' => '',
265  'ro' => 'iso-8859-2',
266  'ru' => 'windows-1251',
267  'se' => '',
268  'si' => 'windows-1250',
269  'sk' => 'windows-1250',
270  'sl' => 'windows-1250',
271  'sq' => 'utf-8',
272  'sr' => 'utf-8',
273  'sv' => '',
274  'th' => 'iso-8859-11',
275  'tr' => 'iso-8859-9',
276  'ua' => 'windows-1251',
277  'uk' => 'windows-1251',
278  'vi' => 'utf-8',
279  'vn' => 'utf-8',
280  'zh' => 'big5'
281  ];
282 
289  public function parse_charset($charset)
290  {
291  $charset = trim(strtolower($charset));
292  if (isset($this->synonyms[$charset])) {
293  $charset = $this->synonyms[$charset];
294  }
295  return $charset;
296  }
297 
298  /********************************************
299  *
300  * Charset Conversion functions
301  *
302  ********************************************/
313  public function conv($inputString, $fromCharset, $toCharset, $useEntityForNoChar = false)
314  {
315  if ($fromCharset === $toCharset) {
316  return $inputString;
317  }
318  // PHP-libs don't support fallback to SGML entities, but UTF-8 handles everything
319  if ($toCharset === 'utf-8' || !$useEntityForNoChar) {
320  $convertedString = mb_convert_encoding($inputString, $toCharset, $fromCharset);
321  if (false !== $convertedString) {
322  return $convertedString;
323  }
324  // Returns FALSE for unsupported charsets
325  }
326  if ($fromCharset !== 'utf-8') {
327  $inputString = $this->utf8_encode($inputString, $fromCharset);
328  }
329  if ($toCharset !== 'utf-8') {
330  $inputString = $this->utf8_decode($inputString, $toCharset, $useEntityForNoChar);
331  }
332  return $inputString;
333  }
334 
346  public function convArray(&$array, $fromCharset, $toCharset, $useEntityForNoChar = false)
347  {
348  foreach ($array as $key => $value) {
349  if (is_array($array[$key])) {
350  $this->convArray($array[$key], $fromCharset, $toCharset, $useEntityForNoChar);
351  } elseif (is_string($array[$key])) {
352  $array[$key] = $this->conv($array[$key], $fromCharset, $toCharset, $useEntityForNoChar);
353  }
354  }
355  }
356 
364  public function utf8_encode($str, $charset)
365  {
366  if ($charset === 'utf-8') {
367  return $str;
368  }
369  // Charset is case-insensitive
370  // Parse conv. table if not already
371  if ($this->initCharset($charset)) {
372  $strLen = strlen($str);
373  $outStr = '';
374  // Traverse each char in string
375  for ($a = 0; $a < $strLen; $a++) {
376  $chr = substr($str, $a, 1);
377  $ord = ord($chr);
378  // If the charset has two bytes per char
379  if (isset($this->twoByteSets[$charset])) {
380  $ord2 = ord($str[$a + 1]);
381  // Assume big endian
382  $ord = $ord << 8 | $ord2;
383  // If the local char-number was found in parsed conv. table then we use that, otherwise 127 (no char?)
384  if (isset($this->parsedCharsets[$charset]['local'][$ord])) {
385  $outStr .= $this->parsedCharsets[$charset]['local'][$ord];
386  } else {
387  $outStr .= chr($this->noCharByteVal);
388  }
389  // No char exists
390  $a++;
391  } elseif ($ord > 127) {
392  // If char has value over 127 it's a multibyte char in UTF-8
393  // EUC uses two-bytes above 127; we get both and advance pointer and make $ord a 16bit int.
394  if (isset($this->eucBasedSets[$charset])) {
395  // Shift-JIS: chars between 160 and 223 are single byte
396  if ($charset !== 'shift_jis' || ($ord < 160 || $ord > 223)) {
397  $a++;
398  $ord2 = ord(substr($str, $a, 1));
399  $ord = $ord * 256 + $ord2;
400  }
401  }
402  if (isset($this->parsedCharsets[$charset]['local'][$ord])) {
403  // If the local char-number was found in parsed conv. table then we use that, otherwise 127 (no char?)
404  $outStr .= $this->parsedCharsets[$charset]['local'][$ord];
405  } else {
406  $outStr .= chr($this->noCharByteVal);
407  }
408  } else {
409  $outStr .= $chr;
410  }
411  }
412  return $outStr;
413  }
414  return '';
415  }
416 
425  public function utf8_decode($str, $charset, $useEntityForNoChar = false)
426  {
427  if ($charset === 'utf-8') {
428  return $str;
429  }
430  // Charset is case-insensitive.
431  // Parse conv. table if not already
432  if ($this->initCharset($charset)) {
433  $strLen = strlen($str);
434  $outStr = '';
435  // Traverse each char in UTF-8 string
436  for ($a = 0, $i = 0; $a < $strLen; $a++, $i++) {
437  $chr = substr($str, $a, 1);
438  $ord = ord($chr);
439  // This means multibyte! (first byte!)
440  if ($ord > 127) {
441  // Since the first byte must have the 7th bit set we check that. Otherwise we might be in the middle of a byte sequence.
442  if ($ord & 64) {
443  // Add first byte
444  $buf = $chr;
445  // For each byte in multibyte string
446  for ($b = 0; $b < 8; $b++) {
447  // Shift it left and
448  $ord = $ord << 1;
449  // ... and with 8th bit - if that is set, then there are still bytes in sequence.
450  if ($ord & 128) {
451  $a++;
452  // ... and add the next char.
453  $buf .= substr($str, $a, 1);
454  } else {
455  break;
456  }
457  }
458  // If the UTF-8 char-sequence is found then...
459  if (isset($this->parsedCharsets[$charset]['utf8'][$buf])) {
460  // The local number
461  $mByte = $this->parsedCharsets[$charset]['utf8'][$buf];
462  // If the local number is greater than 255 we will need to split the byte (16bit word assumed) in two chars.
463  if ($mByte > 255) {
464  $outStr .= chr(($mByte >> 8 & 255)) . chr(($mByte & 255));
465  } else {
466  $outStr .= chr($mByte);
467  }
468  } elseif ($useEntityForNoChar) {
469  // Create num entity:
470  $outStr .= '&#' . $this->utf8CharToUnumber($buf, 1) . ';';
471  } else {
472  $outStr .= chr($this->noCharByteVal);
473  }
474  } else {
475  $outStr .= chr($this->noCharByteVal);
476  }
477  } else {
478  $outStr .= $chr;
479  }
480  }
481  return $outStr;
482  }
483  return '';
484  }
485 
492  public function utf8_to_entities($str)
493  {
494  $strLen = strlen($str);
495  $outStr = '';
496  // Traverse each char in UTF-8 string.
497  for ($a = 0; $a < $strLen; $a++) {
498  $chr = substr($str, $a, 1);
499  $ord = ord($chr);
500  // This means multibyte! (first byte!)
501  if ($ord > 127) {
502  // Since the first byte must have the 7th bit set we check that. Otherwise we might be in the middle of a byte sequence.
503  if ($ord & 64) {
504  // Add first byte
505  $buf = $chr;
506  // For each byte in multibyte string...
507  for ($b = 0; $b < 8; $b++) {
508  // Shift it left and ...
509  $ord = $ord << 1;
510  // ... and with 8th bit - if that is set, then there are still bytes in sequence.
511  if ($ord & 128) {
512  $a++;
513  // ... and add the next char.
514  $buf .= substr($str, $a, 1);
515  } else {
516  break;
517  }
518  }
519  $outStr .= '&#' . $this->utf8CharToUnumber($buf, 1) . ';';
520  } else {
521  $outStr .= chr($this->noCharByteVal);
522  }
523  } else {
524  $outStr .= $chr;
525  }
526  }
527  return $outStr;
528  }
529 
536  public function entities_to_utf8($str)
537  {
538  $trans_tbl = array_flip(get_html_translation_table(HTML_ENTITIES, ENT_COMPAT));
539  $token = md5(microtime());
540  $parts = explode($token, preg_replace('/(&([#[:alnum:]]*);)/', $token . '${2}' . $token, $str));
541  foreach ($parts as $k => $v) {
542  // Only take every second element
543  if ($k % 2 === 0) {
544  continue;
545  }
546  $position = 0;
547  // Dec or hex entities
548  if (substr($v, $position, 1) === '#') {
549  $position++;
550  if (substr($v, $position, 1) === 'x') {
551  $v = hexdec(substr($v, ++$position));
552  } else {
553  $v = substr($v, $position);
554  }
555  $parts[$k] = $this->UnumberToChar($v);
556  } elseif (isset($trans_tbl['&' . $v . ';'])) {
557  // Other entities:
558  $v = $trans_tbl['&' . $v . ';'];
559  $parts[$k] = $v;
560  } else {
561  // No conversion:
562  $parts[$k] = '&' . $v . ';';
563  }
564  }
565  return implode('', $parts);
566  }
567 
576  public function utf8_to_numberarray($str)
577  {
578  // Entities must be registered as well
579  $str = $this->entities_to_utf8($str);
580 
581  // Do conversion:
582  $strLen = strlen($str);
583  $outArr = [];
584  // Traverse each char in UTF-8 string.
585  for ($a = 0; $a < $strLen; $a++) {
586  $chr = substr($str, $a, 1);
587  $ord = ord($chr);
588  // This means multibyte! (first byte!)
589  if ($ord > 127) {
590  // Since the first byte must have the 7th bit set we check that. Otherwise we might be in the middle of a byte sequence.
591  if ($ord & 64) {
592  // Add first byte
593  $buf = $chr;
594  // For each byte in multibyte string...
595  for ($b = 0; $b < 8; $b++) {
596  // Shift it left and ...
597  $ord = $ord << 1;
598  // ... and with 8th bit - if that is set, then there are still bytes in sequence.
599  if ($ord & 128) {
600  $a++;
601  // ... and add the next char.
602  $buf .= substr($str, $a, 1);
603  } else {
604  break;
605  }
606  }
607  $outArr[] = $buf;
608  } else {
609  $outArr[] = chr($this->noCharByteVal);
610  }
611  } else {
612  $outArr[] = chr($ord);
613  }
614  }
615  return $outArr;
616  }
617 
638  public function UnumberToChar($unicodeInteger)
639  {
640  $str = '';
641  if ($unicodeInteger < 128) {
642  $str .= chr($unicodeInteger);
643  } elseif ($unicodeInteger < 2048) {
644  $str .= chr(192 | $unicodeInteger >> 6);
645  $str .= chr(128 | $unicodeInteger & 63);
646  } elseif ($unicodeInteger < 65536) {
647  $str .= chr(224 | $unicodeInteger >> 12);
648  $str .= chr(128 | $unicodeInteger >> 6 & 63);
649  $str .= chr(128 | $unicodeInteger & 63);
650  } elseif ($unicodeInteger < 2097152) {
651  $str .= chr(240 | $unicodeInteger >> 18);
652  $str .= chr(128 | $unicodeInteger >> 12 & 63);
653  $str .= chr(128 | $unicodeInteger >> 6 & 63);
654  $str .= chr(128 | $unicodeInteger & 63);
655  } elseif ($unicodeInteger < 67108864) {
656  $str .= chr(248 | $unicodeInteger >> 24);
657  $str .= chr(128 | $unicodeInteger >> 18 & 63);
658  $str .= chr(128 | $unicodeInteger >> 12 & 63);
659  $str .= chr(128 | $unicodeInteger >> 6 & 63);
660  $str .= chr(128 | $unicodeInteger & 63);
661  } elseif ($unicodeInteger < 2147483648) {
662  $str .= chr(252 | $unicodeInteger >> 30);
663  $str .= chr(128 | $unicodeInteger >> 24 & 63);
664  $str .= chr(128 | $unicodeInteger >> 18 & 63);
665  $str .= chr(128 | $unicodeInteger >> 12 & 63);
666  $str .= chr(128 | $unicodeInteger >> 6 & 63);
667  $str .= chr(128 | $unicodeInteger & 63);
668  } else {
669  // Cannot express a 32-bit character in UTF-8
670  $str .= chr($this->noCharByteVal);
671  }
672  return $str;
673  }
674 
684  public function utf8CharToUnumber($str, $hex = false)
685  {
686  // First char
687  $ord = ord($str[0]);
688  // This verifies that it IS a multi byte string
689  if (($ord & 192) === 192) {
690  $binBuf = '';
691  // For each byte in multibyte string...
692  for ($b = 0; $b < 8; $b++) {
693  // Shift it left and ...
694  $ord = $ord << 1;
695  // ... and with 8th bit - if that is set, then there are still bytes in sequence.
696  if ($ord & 128) {
697  $binBuf .= substr('00000000' . decbin(ord(substr($str, ($b + 1), 1))), -6);
698  } else {
699  break;
700  }
701  }
702  $binBuf = substr(('00000000' . decbin(ord($str[0]))), -(6 - $b)) . $binBuf;
703  $int = bindec($binBuf);
704  } else {
705  $int = $ord;
706  }
707  return $hex ? 'x' . dechex($int) : $int;
708  }
709 
710  /********************************************
711  *
712  * Init functions
713  *
714  ********************************************/
725  public function initCharset($charset)
726  {
727  // Only process if the charset is not yet loaded:
728  if (!is_array($this->parsedCharsets[$charset])) {
729  // Conversion table filename:
730  $charsetConvTableFile = ExtensionManagementUtility::extPath('core') . 'Resources/Private/Charsets/csconvtbl/' . $charset . '.tbl';
731  // If the conversion table is found:
732  if ($charset && GeneralUtility::validPathStr($charsetConvTableFile) && @is_file($charsetConvTableFile)) {
733  // Cache file for charsets:
734  // Caching brought parsing time for gb2312 down from 2400 ms to 150 ms. For other charsets we are talking 11 ms down to zero.
735  $cacheFile = GeneralUtility::getFileAbsFileName('typo3temp/var/charset/charset_' . $charset . '.tbl');
736  if ($cacheFile && @is_file($cacheFile)) {
737  $this->parsedCharsets[$charset] = unserialize(file_get_contents($cacheFile));
738  } else {
739  // Parse conversion table into lines:
740  $lines = GeneralUtility::trimExplode(LF, file_get_contents($charsetConvTableFile), true);
741  // Initialize the internal variable holding the conv. table:
742  $this->parsedCharsets[$charset] = ['local' => [], 'utf8' => []];
743  // traverse the lines:
744  $detectedType = '';
745  foreach ($lines as $value) {
746  // Comment line or blanks are ignored.
747  if (trim($value) && $value[0] !== '#') {
748  // Detect type if not done yet: (Done on first real line)
749  // The "whitespaced" type is on the syntax "0x0A 0x000A #LINE FEED" while "ms-token" is like "B9 = U+00B9 : SUPERSCRIPT ONE"
750  if (!$detectedType) {
751  $detectedType = preg_match('/[[:space:]]*0x([[:alnum:]]*)[[:space:]]+0x([[:alnum:]]*)[[:space:]]+/', $value) ? 'whitespaced' : 'ms-token';
752  }
753  $hexbyte = '';
754  $utf8 = '';
755  if ($detectedType === 'ms-token') {
756  list($hexbyte, $utf8) = preg_split('/[=:]/', $value, 3);
757  } elseif ($detectedType === 'whitespaced') {
758  $regA = [];
759  preg_match('/[[:space:]]*0x([[:alnum:]]*)[[:space:]]+0x([[:alnum:]]*)[[:space:]]+/', $value, $regA);
760  $hexbyte = $regA[1];
761  $utf8 = 'U+' . $regA[2];
762  }
763  $decval = hexdec(trim($hexbyte));
764  if ($decval > 127) {
765  $utf8decval = hexdec(substr(trim($utf8), 2));
766  $this->parsedCharsets[$charset]['local'][$decval] = $this->UnumberToChar($utf8decval);
767  $this->parsedCharsets[$charset]['utf8'][$this->parsedCharsets[$charset]['local'][$decval]] = $decval;
768  }
769  }
770  }
771  if ($cacheFile) {
772  GeneralUtility::writeFileToTypo3tempDir($cacheFile, serialize($this->parsedCharsets[$charset]));
773  }
774  }
775  return 2;
776  } else {
777  return false;
778  }
779  } else {
780  return 1;
781  }
782  }
783 
793  public function initUnicodeData($mode = null)
794  {
795  // Cache files
796  $cacheFileCase = GeneralUtility::getFileAbsFileName('typo3temp/var/charset/cscase_utf-8.tbl');
797  $cacheFileASCII = GeneralUtility::getFileAbsFileName('typo3temp/var/charset/csascii_utf-8.tbl');
798  // Only process if the tables are not yet loaded
799  switch ($mode) {
800  case 'case':
801  if (is_array($this->caseFolding['utf-8'])) {
802  return 1;
803  }
804  // Use cached version if possible
805  if ($cacheFileCase && @is_file($cacheFileCase)) {
806  $this->caseFolding['utf-8'] = unserialize(file_get_contents($cacheFileCase));
807  return 2;
808  }
809  break;
810  case 'ascii':
811  if (is_array($this->toASCII['utf-8'])) {
812  return 1;
813  }
814  // Use cached version if possible
815  if ($cacheFileASCII && @is_file($cacheFileASCII)) {
816  $this->toASCII['utf-8'] = unserialize(file_get_contents($cacheFileASCII));
817  return 2;
818  }
819  break;
820  }
821  // Process main Unicode data file
822  $unicodeDataFile = ExtensionManagementUtility::extPath('core') . 'Resources/Private/Charsets/unidata/UnicodeData.txt';
823  if (!(GeneralUtility::validPathStr($unicodeDataFile) && @is_file($unicodeDataFile))) {
824  return false;
825  }
826  $fh = fopen($unicodeDataFile, 'rb');
827  if (!$fh) {
828  return false;
829  }
830  // key = utf8 char (single codepoint), value = utf8 string (codepoint sequence)
831  // Note: we use the UTF-8 characters here and not the Unicode numbers to avoid conversion roundtrip in utf8_strtolower/-upper)
832  $this->caseFolding['utf-8'] = [];
833  $utf8CaseFolding = &$this->caseFolding['utf-8'];
834  // a shorthand
835  $utf8CaseFolding['toUpper'] = [];
836  $utf8CaseFolding['toLower'] = [];
837  $utf8CaseFolding['toTitle'] = [];
838  // Array of temp. decompositions
839  $decomposition = [];
840  // Array of chars that are marks (eg. composing accents)
841  $mark = [];
842  // Array of chars that are numbers (eg. digits)
843  $number = [];
844  // Array of chars to be omitted (eg. Russian hard sign)
845  $omit = [];
846  while (!feof($fh)) {
847  $line = fgets($fh, 4096);
848  // Has a lot of info
849  list($char, $name, $cat, , , $decomp, , , $num, , , , $upper, $lower, $title, ) = explode(';', rtrim($line));
850  $ord = hexdec($char);
851  if ($ord > 65535) {
852  // Only process the BMP
853  break;
854  }
855  $utf8_char = $this->UnumberToChar($ord);
856  if ($upper) {
857  $utf8CaseFolding['toUpper'][$utf8_char] = $this->UnumberToChar(hexdec($upper));
858  }
859  if ($lower) {
860  $utf8CaseFolding['toLower'][$utf8_char] = $this->UnumberToChar(hexdec($lower));
861  }
862  // Store "title" only when different from "upper" (only a few)
863  if ($title && $title !== $upper) {
864  $utf8CaseFolding['toTitle'][$utf8_char] = $this->UnumberToChar(hexdec($title));
865  }
866  switch ($cat[0]) {
867  case 'M':
868  // mark (accent, umlaut, ...)
869  $mark['U+' . $char] = 1;
870  break;
871  case 'N':
872  // numeric value
873  if ($ord > 128 && $num !== '') {
874  $number['U+' . $char] = $num;
875  }
876  }
877  // Accented Latin letters without "official" decomposition
878  $match = [];
879  if (preg_match('/^LATIN (SMALL|CAPITAL) LETTER ([A-Z]) WITH/', $name, $match) && !$decomp) {
880  $c = ord($match[2]);
881  if ($match[1] === 'SMALL') {
882  $c += 32;
883  }
884  $decomposition['U+' . $char] = [dechex($c)];
885  continue;
886  }
887  $match = [];
888  if (preg_match('/(<.*>)? *(.+)/', $decomp, $match)) {
889  switch ($match[1]) {
890  case '<circle>':
891  // add parenthesis as circle replacement, eg (1)
892  $match[2] = '0028 ' . $match[2] . ' 0029';
893  break;
894  case '<square>':
895  // add square brackets as square replacement, eg [1]
896  $match[2] = '005B ' . $match[2] . ' 005D';
897  break;
898  case '<compat>':
899  // ignore multi char decompositions that start with a space
900  if (preg_match('/^0020 /', $match[2])) {
901  continue 2;
902  }
903  break;
904  case '<initial>':
905  case '<medial>':
906  case '<final>':
907  case '<isolated>':
908  case '<vertical>':
909  continue 2;
910  }
911  $decomposition['U+' . $char] = explode(' ', $match[2]);
912  }
913  }
914  fclose($fh);
915  // Process additional Unicode data for casing (allow folded characters to expand into a sequence)
916  $specialCasingFile = ExtensionManagementUtility::extPath('core') . 'Resources/Private/Charsets/unidata/SpecialCasing.txt';
917  if (GeneralUtility::validPathStr($specialCasingFile) && @is_file($specialCasingFile)) {
918  $fh = fopen($specialCasingFile, 'rb');
919  if ($fh) {
920  while (!feof($fh)) {
921  $line = fgets($fh, 4096);
922  if ($line[0] !== '#' && trim($line) !== '') {
923  list($char, $lower, $title, $upper, $cond) = GeneralUtility::trimExplode(';', $line);
924  if ($cond === '' || $cond[0] === '#') {
925  $utf8_char = $this->UnumberToChar(hexdec($char));
926  if ($char !== $lower) {
927  $arr = explode(' ', $lower);
928  for ($i = 0; isset($arr[$i]); $i++) {
929  $arr[$i] = $this->UnumberToChar(hexdec($arr[$i]));
930  }
931  $utf8CaseFolding['toLower'][$utf8_char] = implode('', $arr);
932  }
933  if ($char !== $title && $title !== $upper) {
934  $arr = explode(' ', $title);
935  for ($i = 0; isset($arr[$i]); $i++) {
936  $arr[$i] = $this->UnumberToChar(hexdec($arr[$i]));
937  }
938  $utf8CaseFolding['toTitle'][$utf8_char] = implode('', $arr);
939  }
940  if ($char !== $upper) {
941  $arr = explode(' ', $upper);
942  for ($i = 0; isset($arr[$i]); $i++) {
943  $arr[$i] = $this->UnumberToChar(hexdec($arr[$i]));
944  }
945  $utf8CaseFolding['toUpper'][$utf8_char] = implode('', $arr);
946  }
947  }
948  }
949  }
950  fclose($fh);
951  }
952  }
953  // Process custom decompositions
954  $customTranslitFile = ExtensionManagementUtility::extPath('core') . 'Resources/Private/Charsets/unidata/Translit.txt';
955  if (GeneralUtility::validPathStr($customTranslitFile) && @is_file($customTranslitFile)) {
956  $fh = fopen($customTranslitFile, 'rb');
957  if ($fh) {
958  while (!feof($fh)) {
959  $line = fgets($fh, 4096);
960  if ($line[0] !== '#' && trim($line) !== '') {
961  list($char, $translit) = GeneralUtility::trimExplode(';', $line);
962  if (!$translit) {
963  $omit['U+' . $char] = 1;
964  }
965  $decomposition['U+' . $char] = explode(' ', $translit);
966  }
967  }
968  fclose($fh);
969  }
970  }
971  // Decompose and remove marks; inspired by unac (Loic Dachary <loic@senga.org>)
972  foreach ($decomposition as $from => $to) {
973  $code_decomp = [];
974  while ($code_value = array_shift($to)) {
975  // Do recursive decomposition
976  if (isset($decomposition['U+' . $code_value])) {
977  foreach (array_reverse($decomposition['U+' . $code_value]) as $cv) {
978  array_unshift($to, $cv);
979  }
980  } elseif (!isset($mark['U+' . $code_value])) {
981  // remove mark
982  array_push($code_decomp, $code_value);
983  }
984  }
985  if (!empty($code_decomp) || isset($omit[$from])) {
986  $decomposition[$from] = $code_decomp;
987  } else {
988  unset($decomposition[$from]);
989  }
990  }
991  // Create ascii only mapping
992  $this->toASCII['utf-8'] = [];
993  $ascii = &$this->toASCII['utf-8'];
994  foreach ($decomposition as $from => $to) {
995  $code_decomp = [];
996  while ($code_value = array_shift($to)) {
997  $ord = hexdec($code_value);
998  if ($ord > 127) {
999  continue 2;
1000  } else {
1001  // Skip decompositions containing non-ASCII chars
1002  array_push($code_decomp, chr($ord));
1003  }
1004  }
1005  $ascii[$this->UnumberToChar(hexdec($from))] = implode('', $code_decomp);
1006  }
1007  // Add numeric decompositions
1008  foreach ($number as $from => $to) {
1009  $utf8_char = $this->UnumberToChar(hexdec($from));
1010  if (!isset($ascii[$utf8_char])) {
1011  $ascii[$utf8_char] = $to;
1012  }
1013  }
1014  if ($cacheFileCase) {
1015  GeneralUtility::writeFileToTypo3tempDir($cacheFileCase, serialize($utf8CaseFolding));
1016  }
1017  if ($cacheFileASCII) {
1018  GeneralUtility::writeFileToTypo3tempDir($cacheFileASCII, serialize($ascii));
1019  }
1020  return 3;
1021  }
1022 
1031  public function initCaseFolding($charset)
1032  {
1033  // Only process if the case table is not yet loaded:
1034  if (is_array($this->caseFolding[$charset])) {
1035  return 1;
1036  }
1037  // Use cached version if possible
1038  $cacheFile = GeneralUtility::getFileAbsFileName('typo3temp/var/charset/cscase_' . $charset . '.tbl');
1039  if ($cacheFile && @is_file($cacheFile)) {
1040  $this->caseFolding[$charset] = unserialize(file_get_contents($cacheFile));
1041  return 2;
1042  }
1043  // init UTF-8 conversion for this charset
1044  if (!$this->initCharset($charset)) {
1045  return false;
1046  }
1047  // UTF-8 case folding is used as the base conversion table
1048  if (!$this->initUnicodeData('case')) {
1049  return false;
1050  }
1051  $nochar = chr($this->noCharByteVal);
1052  foreach ($this->parsedCharsets[$charset]['local'] as $ci => $utf8) {
1053  // Reconvert to charset (don't use chr() of numeric value, might be muli-byte)
1054  $c = $this->utf8_decode($utf8, $charset);
1055  $cc = $this->utf8_decode($this->caseFolding['utf-8']['toUpper'][$utf8], $charset);
1056  if ($cc !== '' && $cc !== $nochar) {
1057  $this->caseFolding[$charset]['toUpper'][$c] = $cc;
1058  }
1059  $cc = $this->utf8_decode($this->caseFolding['utf-8']['toLower'][$utf8], $charset);
1060  if ($cc !== '' && $cc !== $nochar) {
1061  $this->caseFolding[$charset]['toLower'][$c] = $cc;
1062  }
1063  $cc = $this->utf8_decode($this->caseFolding['utf-8']['toTitle'][$utf8], $charset);
1064  if ($cc !== '' && $cc !== $nochar) {
1065  $this->caseFolding[$charset]['toTitle'][$c] = $cc;
1066  }
1067  }
1068  // Add the ASCII case table
1069  $start = ord('a');
1070  $end = ord('z');
1071  for ($i = $start; $i <= $end; $i++) {
1072  $this->caseFolding[$charset]['toUpper'][chr($i)] = chr($i - 32);
1073  }
1074  $start = ord('A');
1075  $end = ord('Z');
1076  for ($i = $start; $i <= $end; $i++) {
1077  $this->caseFolding[$charset]['toLower'][chr($i)] = chr($i + 32);
1078  }
1079  if ($cacheFile) {
1080  GeneralUtility::writeFileToTypo3tempDir($cacheFile, serialize($this->caseFolding[$charset]));
1081  }
1082  return 3;
1083  }
1084 
1093  public function initToASCII($charset)
1094  {
1095  // Only process if the case table is not yet loaded:
1096  if (is_array($this->toASCII[$charset])) {
1097  return 1;
1098  }
1099  // Use cached version if possible
1100  $cacheFile = GeneralUtility::getFileAbsFileName('typo3temp/var/charset/csascii_' . $charset . '.tbl');
1101  if ($cacheFile && @is_file($cacheFile)) {
1102  $this->toASCII[$charset] = unserialize(file_get_contents($cacheFile));
1103  return 2;
1104  }
1105  // Init UTF-8 conversion for this charset
1106  if (!$this->initCharset($charset)) {
1107  return false;
1108  }
1109  // UTF-8/ASCII transliteration is used as the base conversion table
1110  if (!$this->initUnicodeData('ascii')) {
1111  return false;
1112  }
1113  foreach ($this->parsedCharsets[$charset]['local'] as $ci => $utf8) {
1114  // Reconvert to charset (don't use chr() of numeric value, might be muli-byte)
1115  $c = $this->utf8_decode($utf8, $charset);
1116  if (isset($this->toASCII['utf-8'][$utf8])) {
1117  $this->toASCII[$charset][$c] = $this->toASCII['utf-8'][$utf8];
1118  }
1119  }
1120  if ($cacheFile) {
1121  GeneralUtility::writeFileToTypo3tempDir($cacheFile, serialize($this->toASCII[$charset]));
1122  }
1123  return 3;
1124  }
1125 
1126  /********************************************
1127  *
1128  * String operation functions
1129  *
1130  ********************************************/
1143  public function substr($charset, $string, $start, $len = null)
1144  {
1146  return mb_substr($string, $start, $len, $charset);
1147  }
1148 
1159  public function strlen($charset, $string)
1160  {
1162  return mb_strlen($string, $charset);
1163  }
1164 
1176  public function crop($charset, $string, $len, $crop = '')
1177  {
1178  if ((int)$len === 0 || mb_strlen($string, $charset) <= abs($len)) {
1179  return $string;
1180  }
1181  if ($len > 0) {
1182  $string = mb_substr($string, 0, $len, $charset) . $crop;
1183  } else {
1184  $string = $crop . mb_substr($string, $len, mb_strlen($string, $charset), $charset);
1185  }
1186  return $string;
1187  }
1188 
1198  public function strtrunc($charset, $string, $len)
1199  {
1200  if ($len <= 0) {
1201  return '';
1202  }
1203  return mb_strcut($string, 0, $len, $charset);
1204  }
1205 
1221  public function conv_case($charset, $string, $case)
1222  {
1224  return $case === 'toLower'
1225  ? mb_strtolower($string, $charset)
1226  : mb_strtoupper($string, $charset);
1227  }
1228 
1237  public function convCaseFirst($charset, $string, $case)
1238  {
1239  $firstChar = mb_substr($string, 0, 1, $charset);
1240  $firstChar = $case === 'toLower'
1241  ? mb_strtolower($firstChar, $charset)
1242  : mb_strtoupper($firstChar, $charset);
1243  $remainder = mb_substr($string, 1, null, $charset);
1244  return $firstChar . $remainder;
1245  }
1246 
1255  public function convCapitalize($charset, $string)
1256  {
1258  return mb_convert_case($string, MB_CASE_TITLE, $charset);
1259  }
1260 
1268  public function specCharsToASCII($charset, $string)
1269  {
1270  if ($charset === 'utf-8') {
1271  $string = $this->utf8_char_mapping($string, 'ascii');
1272  } elseif (isset($this->eucBasedSets[$charset])) {
1273  $string = $this->euc_char_mapping($string, $charset, 'ascii');
1274  } else {
1275  // Treat everything else as single-byte encoding
1276  $string = $this->sb_char_mapping($string, $charset, 'ascii');
1277  }
1278  return $string;
1279  }
1280 
1289  public function getPreferredClientLanguage($languageCodesList)
1290  {
1293  $locales = GeneralUtility::makeInstance(Locales::class);
1294  return $locales->getPreferredClientLanguage($languageCodesList);
1295  }
1296 
1297  /********************************************
1298  *
1299  * Internal string operation functions
1300  *
1301  ********************************************/
1311  public function sb_char_mapping($str, $charset, $mode, $opt = '')
1312  {
1313  switch ($mode) {
1314  case 'case':
1315  if (!$this->initCaseFolding($charset)) {
1316  return $str;
1317  }
1318  // Do nothing
1319  $map = &$this->caseFolding[$charset][$opt];
1320  break;
1321  case 'ascii':
1322  if (!$this->initToASCII($charset)) {
1323  return $str;
1324  }
1325  // Do nothing
1326  $map = &$this->toASCII[$charset];
1327  break;
1328  default:
1329  return $str;
1330  }
1331  $out = '';
1332  for ($i = 0; isset($str[$i]); $i++) {
1333  $c = $str[$i];
1334  if (isset($map[$c])) {
1335  $out .= $map[$c];
1336  } else {
1337  $out .= $c;
1338  }
1339  }
1340  return $out;
1341  }
1342 
1343  /********************************************
1344  *
1345  * Internal UTF-8 string operation functions
1346  *
1347  ********************************************/
1359  public function utf8_substr($str, $start, $len = null)
1360  {
1362  if ((string)$len === '0') {
1363  return '';
1364  }
1365  $byte_start = $this->utf8_char2byte_pos($str, $start);
1366  if ($byte_start === false) {
1367  if ($start > 0) {
1368  // $start outside string length
1369  return false;
1370  }
1371  }
1372  $str = substr($str, $byte_start);
1373  if ($len != null) {
1374  $byte_end = $this->utf8_char2byte_pos($str, $len);
1375  // $len outside actual string length
1376  if ($byte_end === false) {
1377  return $len < 0 ? '' : $str;
1378  } else {
1379  // When length is less than zero and exceeds, then we return blank string.
1380  return substr($str, 0, $byte_end);
1381  }
1382  } else {
1383  return $str;
1384  }
1385  }
1386 
1396  public function utf8_strlen($str)
1397  {
1399  $n = 0;
1400  for ($i = 0; isset($str[$i]); $i++) {
1401  $c = ord($str[$i]);
1402  // Single-byte (0xxxxxx)
1403  if (!($c & 128)) {
1404  $n++;
1405  } elseif (($c & 192) === 192) {
1406  // Multi-byte starting byte (11xxxxxx)
1407  $n++;
1408  }
1409  }
1410  return $n;
1411  }
1412 
1422  public function utf8_strtrunc($str, $len)
1423  {
1425  $i = $len - 1;
1426  // Part of a multibyte sequence
1427  if (ord($str[$i]) & 128) {
1428  for (; $i > 0 && !(ord($str[$i]) & 64); $i--) {
1429  }
1430  if ($i <= 0) {
1431  return '';
1432  }
1433  // Sanity check
1434  for ($bc = 0, $mbs = ord($str[$i]); $mbs & 128; $mbs = $mbs << 1) {
1435  // Calculate number of bytes
1436  $bc++;
1437  }
1438  if ($bc + $i > $len) {
1439  return substr($str, 0, $i);
1440  }
1441  }
1442  return substr($str, 0, $len);
1443  }
1444 
1455  public function utf8_strpos($haystack, $needle, $offset = 0)
1456  {
1458  return mb_strpos($haystack, $needle, $offset, 'utf-8');
1459  }
1460 
1470  public function utf8_strrpos($haystack, $needle)
1471  {
1473  return mb_strrpos($haystack, $needle, 'utf-8');
1474  }
1475 
1484  public function utf8_char2byte_pos($str, $pos)
1485  {
1486  // Number of characters found
1487  $n = 0;
1488  // Number of characters wanted
1489  $p = abs($pos);
1490  if ($pos >= 0) {
1491  $i = 0;
1492  $d = 1;
1493  } else {
1494  $i = strlen($str) - 1;
1495  $d = -1;
1496  }
1497  for (; isset($str[$i]) && $n < $p; $i += $d) {
1498  $c = (int)ord($str[$i]);
1499  // single-byte (0xxxxxx)
1500  if (!($c & 128)) {
1501  $n++;
1502  } elseif (($c & 192) === 192) {
1503  // Multi-byte starting byte (11xxxxxx)
1504  $n++;
1505  }
1506  }
1507  if (!isset($str[$i])) {
1508  // Offset beyond string length
1509  return false;
1510  }
1511  if ($pos >= 0) {
1512  // Skip trailing multi-byte data bytes
1513  while (ord($str[$i]) & 128 && !(ord($str[$i]) & 64)) {
1514  $i++;
1515  }
1516  } else {
1517  // Correct offset
1518  $i++;
1519  }
1520  return $i;
1521  }
1522 
1532  public function utf8_byte2char_pos($str, $pos)
1533  {
1535  // Number of characters
1536  $n = 0;
1537  for ($i = $pos; $i > 0; $i--) {
1538  $c = (int)ord($str[$i]);
1539  // single-byte (0xxxxxx)
1540  if (!($c & 128)) {
1541  $n++;
1542  } elseif (($c & 192) === 192) {
1543  // Multi-byte starting byte (11xxxxxx)
1544  $n++;
1545  }
1546  }
1547  if (!isset($str[$i])) {
1548  // Offset beyond string length
1549  return false;
1550  }
1551  return $n;
1552  }
1553 
1562  public function utf8_char_mapping($str, $mode, $opt = '')
1563  {
1564  if (!$this->initUnicodeData($mode)) {
1565  // Do nothing
1566  return $str;
1567  }
1568  $out = '';
1569  switch ($mode) {
1570  case 'case':
1571  $map = &$this->caseFolding['utf-8'][$opt];
1572  break;
1573  case 'ascii':
1574  $map = &$this->toASCII['utf-8'];
1575  break;
1576  default:
1577  return $str;
1578  }
1579  for ($i = 0; isset($str[$i]); $i++) {
1580  $c = ord($str[$i]);
1581  $mbc = '';
1582  // single-byte (0xxxxxx)
1583  if (!($c & 128)) {
1584  $mbc = $str[$i];
1585  } elseif (($c & 192) === 192) {
1586  // multi-byte starting byte (11xxxxxx)
1587  for ($bc = 0; $c & 128; $c = $c << 1) {
1588  $bc++;
1589  }
1590  // calculate number of bytes
1591  $mbc = substr($str, $i, $bc);
1592  $i += $bc - 1;
1593  }
1594  if (isset($map[$mbc])) {
1595  $out .= $map[$mbc];
1596  } else {
1597  $out .= $mbc;
1598  }
1599  }
1600  return $out;
1601  }
1602 
1603  /********************************************
1604  *
1605  * Internal EUC string operation functions
1606  *
1607  * Extended Unix Code:
1608  * ASCII compatible 7bit single bytes chars
1609  * 8bit two byte chars
1610  *
1611  * Shift-JIS is treated as a special case.
1612  *
1613  ********************************************/
1624  public function euc_strtrunc($str, $len, $charset)
1625  {
1627  $shiftJis = $charset === 'shift_jis';
1628  for ($i = 0; isset($str[$i]) && $i < $len; $i++) {
1629  $c = ord($str[$i]);
1630  if ($shiftJis) {
1631  if ($c >= 128 && $c < 160 || $c >= 224) {
1632  $i++;
1633  }
1634  } else {
1635  if ($c >= 128) {
1636  $i++;
1637  }
1638  }
1639  }
1640  if (!isset($str[$i])) {
1641  return $str;
1642  }
1643  // string shorter than supplied length
1644  if ($i > $len) {
1645  // We ended on a first byte
1646  return substr($str, 0, $len - 1);
1647  } else {
1648  return substr($str, 0, $len);
1649  }
1650  }
1651 
1662  public function euc_substr($str, $start, $charset, $len = null)
1663  {
1665  $byte_start = $this->euc_char2byte_pos($str, $start, $charset);
1666  if ($byte_start === false) {
1667  // $start outside string length
1668  return false;
1669  }
1670  $str = substr($str, $byte_start);
1671  if ($len != null) {
1672  $byte_end = $this->euc_char2byte_pos($str, $len, $charset);
1673  // $len outside actual string length
1674  if ($byte_end === false) {
1675  return $str;
1676  } else {
1677  return substr($str, 0, $byte_end);
1678  }
1679  } else {
1680  return $str;
1681  }
1682  }
1683 
1693  public function euc_strlen($str, $charset)
1694  {
1696  $sjis = $charset === 'shift_jis';
1697  $n = 0;
1698  for ($i = 0; isset($str[$i]); $i++) {
1699  $c = ord($str[$i]);
1700  if ($sjis) {
1701  if ($c >= 128 && $c < 160 || $c >= 224) {
1702  $i++;
1703  }
1704  } else {
1705  if ($c >= 128) {
1706  $i++;
1707  }
1708  }
1709  $n++;
1710  }
1711  return $n;
1712  }
1713 
1723  public function euc_char2byte_pos($str, $pos, $charset)
1724  {
1726  $sjis = $charset === 'shift_jis';
1727  // Number of characters seen
1728  $n = 0;
1729  // Number of characters wanted
1730  $p = abs($pos);
1731  if ($pos >= 0) {
1732  $i = 0;
1733  $d = 1;
1734  } else {
1735  $i = strlen($str) - 1;
1736  $d = -1;
1737  }
1738  for (; isset($str[$i]) && $n < $p; $i += $d) {
1739  $c = ord($str[$i]);
1740  if ($sjis) {
1741  if ($c >= 128 && $c < 160 || $c >= 224) {
1742  $i += $d;
1743  }
1744  } else {
1745  if ($c >= 128) {
1746  $i += $d;
1747  }
1748  }
1749  $n++;
1750  }
1751  if (!isset($str[$i])) {
1752  return false;
1753  }
1754  // offset beyond string length
1755  if ($pos < 0) {
1756  $i++;
1757  }
1758  // correct offset
1759  return $i;
1760  }
1761 
1771  public function euc_char_mapping($str, $charset, $mode, $opt = '')
1772  {
1773  switch ($mode) {
1774  case 'case':
1775  if (!$this->initCaseFolding($charset)) {
1776  return $str;
1777  }
1778  // do nothing
1779  $map = &$this->caseFolding[$charset][$opt];
1780  break;
1781  case 'ascii':
1782  if (!$this->initToASCII($charset)) {
1783  return $str;
1784  }
1785  // do nothing
1786  $map = &$this->toASCII[$charset];
1787  break;
1788  default:
1789  return $str;
1790  }
1791  $sjis = $charset === 'shift_jis';
1792  $out = '';
1793  for ($i = 0; isset($str[$i]); $i++) {
1794  $mbc = $str[$i];
1795  $c = ord($mbc);
1796  if ($sjis) {
1797  // A double-byte char
1798  if ($c >= 128 && $c < 160 || $c >= 224) {
1799  $mbc = substr($str, $i, 2);
1800  $i++;
1801  }
1802  } else {
1803  // A double-byte char
1804  if ($c >= 128) {
1805  $mbc = substr($str, $i, 2);
1806  $i++;
1807  }
1808  }
1809  if (isset($map[$mbc])) {
1810  $out .= $map[$mbc];
1811  } else {
1812  $out .= $mbc;
1813  }
1814  }
1815  return $out;
1816  }
1817 }
convArray(&$array, $fromCharset, $toCharset, $useEntityForNoChar=false)
static trimExplode($delim, $string, $removeEmptyValues=false, $limit=0)
euc_char_mapping($str, $charset, $mode, $opt= '')
euc_substr($str, $start, $charset, $len=null)
utf8_strpos($haystack, $needle, $offset=0)
static writeFileToTypo3tempDir($filepath, $content)
sb_char_mapping($str, $charset, $mode, $opt= '')
static makeInstance($className,...$constructorArguments)
conv($inputString, $fromCharset, $toCharset, $useEntityForNoChar=false)
utf8_decode($str, $charset, $useEntityForNoChar=false)
static getFileAbsFileName($filename, $_=null, $_2=null)
substr($charset, $string, $start, $len=null)
crop($charset, $string, $len, $crop= '')