PageRenderTime 50ms CodeModel.GetById 10ms RepoModel.GetById 1ms app.codeStats 0ms

/libraries/simplepie/SimplePie/Misc.php

https://bitbucket.org/timgws/full-text-rss
PHP | 2203 lines | 2145 code | 10 blank | 48 comment | 17 complexity | d7d29ca39aa5561c1b4b473959353073 MD5 | raw file
  1. <?php
  2. /**
  3. * SimplePie
  4. *
  5. * A PHP-Based RSS and Atom Feed Framework.
  6. * Takes the hard work out of managing a complete RSS/Atom solution.
  7. *
  8. * Copyright (c) 2004-2009, Ryan Parman, Geoffrey Sneddon, Ryan McCue, and contributors
  9. * All rights reserved.
  10. *
  11. * Redistribution and use in source and binary forms, with or without modification, are
  12. * permitted provided that the following conditions are met:
  13. *
  14. * * Redistributions of source code must retain the above copyright notice, this list of
  15. * conditions and the following disclaimer.
  16. *
  17. * * Redistributions in binary form must reproduce the above copyright notice, this list
  18. * of conditions and the following disclaimer in the documentation and/or other materials
  19. * provided with the distribution.
  20. *
  21. * * Neither the name of the SimplePie Team nor the names of its contributors may be used
  22. * to endorse or promote products derived from this software without specific prior
  23. * written permission.
  24. *
  25. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
  26. * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
  27. * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS
  28. * AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
  29. * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  30. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  31. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
  32. * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  33. * POSSIBILITY OF SUCH DAMAGE.
  34. *
  35. * @package SimplePie
  36. * @version 1.3-dev
  37. * @copyright 2004-2010 Ryan Parman, Geoffrey Sneddon, Ryan McCue
  38. * @author Ryan Parman
  39. * @author Geoffrey Sneddon
  40. * @author Ryan McCue
  41. * @link http://simplepie.org/ SimplePie
  42. * @license http://www.opensource.org/licenses/bsd-license.php BSD License
  43. * @todo phpDoc comments
  44. */
  45. class SimplePie_Misc
  46. {
  47. public static function time_hms($seconds)
  48. {
  49. $time = '';
  50. $hours = floor($seconds / 3600);
  51. $remainder = $seconds % 3600;
  52. if ($hours > 0)
  53. {
  54. $time .= $hours.':';
  55. }
  56. $minutes = floor($remainder / 60);
  57. $seconds = $remainder % 60;
  58. if ($minutes < 10 && $hours > 0)
  59. {
  60. $minutes = '0' . $minutes;
  61. }
  62. if ($seconds < 10)
  63. {
  64. $seconds = '0' . $seconds;
  65. }
  66. $time .= $minutes.':';
  67. $time .= $seconds;
  68. return $time;
  69. }
  70. public static function absolutize_url($relative, $base)
  71. {
  72. $iri = SimplePie_IRI::absolutize(new SimplePie_IRI($base), $relative);
  73. return $iri->get_iri();
  74. }
  75. public static function remove_dot_segments($input)
  76. {
  77. $output = '';
  78. while (strpos($input, './') !== false || strpos($input, '/.') !== false || $input === '.' || $input === '..')
  79. {
  80. // A: If the input buffer begins with a prefix of "../" or "./", then remove that prefix from the input buffer; otherwise,
  81. if (strpos($input, '../') === 0)
  82. {
  83. $input = substr($input, 3);
  84. }
  85. elseif (strpos($input, './') === 0)
  86. {
  87. $input = substr($input, 2);
  88. }
  89. // B: if the input buffer begins with a prefix of "/./" or "/.", where "." is a complete path segment, then replace that prefix with "/" in the input buffer; otherwise,
  90. elseif (strpos($input, '/./') === 0)
  91. {
  92. $input = substr_replace($input, '/', 0, 3);
  93. }
  94. elseif ($input === '/.')
  95. {
  96. $input = '/';
  97. }
  98. // C: if the input buffer begins with a prefix of "/../" or "/..", where ".." is a complete path segment, then replace that prefix with "/" in the input buffer and remove the last segment and its preceding "/" (if any) from the output buffer; otherwise,
  99. elseif (strpos($input, '/../') === 0)
  100. {
  101. $input = substr_replace($input, '/', 0, 4);
  102. $output = substr_replace($output, '', strrpos($output, '/'));
  103. }
  104. elseif ($input === '/..')
  105. {
  106. $input = '/';
  107. $output = substr_replace($output, '', strrpos($output, '/'));
  108. }
  109. // D: if the input buffer consists only of "." or "..", then remove that from the input buffer; otherwise,
  110. elseif ($input === '.' || $input === '..')
  111. {
  112. $input = '';
  113. }
  114. // E: move the first path segment in the input buffer to the end of the output buffer, including the initial "/" character (if any) and any subsequent characters up to, but not including, the next "/" character or the end of the input buffer
  115. elseif (($pos = strpos($input, '/', 1)) !== false)
  116. {
  117. $output .= substr($input, 0, $pos);
  118. $input = substr_replace($input, '', 0, $pos);
  119. }
  120. else
  121. {
  122. $output .= $input;
  123. $input = '';
  124. }
  125. }
  126. return $output . $input;
  127. }
  128. public static function get_element($realname, $string)
  129. {
  130. $return = array();
  131. $name = preg_quote($realname, '/');
  132. if (preg_match_all("/<($name)" . SIMPLEPIE_PCRE_HTML_ATTRIBUTE . "(>(.*)<\/$name>|(\/)?>)/siU", $string, $matches, PREG_SET_ORDER | PREG_OFFSET_CAPTURE))
  133. {
  134. for ($i = 0, $total_matches = count($matches); $i < $total_matches; $i++)
  135. {
  136. $return[$i]['tag'] = $realname;
  137. $return[$i]['full'] = $matches[$i][0][0];
  138. $return[$i]['offset'] = $matches[$i][0][1];
  139. if (strlen($matches[$i][3][0]) <= 2)
  140. {
  141. $return[$i]['self_closing'] = true;
  142. }
  143. else
  144. {
  145. $return[$i]['self_closing'] = false;
  146. $return[$i]['content'] = $matches[$i][4][0];
  147. }
  148. $return[$i]['attribs'] = array();
  149. if (isset($matches[$i][2][0]) && preg_match_all('/[\x09\x0A\x0B\x0C\x0D\x20]+([^\x09\x0A\x0B\x0C\x0D\x20\x2F\x3E][^\x09\x0A\x0B\x0C\x0D\x20\x2F\x3D\x3E]*)(?:[\x09\x0A\x0B\x0C\x0D\x20]*=[\x09\x0A\x0B\x0C\x0D\x20]*(?:"([^"]*)"|\'([^\']*)\'|([^\x09\x0A\x0B\x0C\x0D\x20\x22\x27\x3E][^\x09\x0A\x0B\x0C\x0D\x20\x3E]*)?))?/', ' ' . $matches[$i][2][0] . ' ', $attribs, PREG_SET_ORDER))
  150. {
  151. for ($j = 0, $total_attribs = count($attribs); $j < $total_attribs; $j++)
  152. {
  153. if (count($attribs[$j]) === 2)
  154. {
  155. $attribs[$j][2] = $attribs[$j][1];
  156. }
  157. $return[$i]['attribs'][strtolower($attribs[$j][1])]['data'] = SimplePie_Misc::entities_decode(end($attribs[$j]), 'UTF-8');
  158. }
  159. }
  160. }
  161. }
  162. return $return;
  163. }
  164. public static function element_implode($element)
  165. {
  166. $full = "<$element[tag]";
  167. foreach ($element['attribs'] as $key => $value)
  168. {
  169. $key = strtolower($key);
  170. $full .= " $key=\"" . htmlspecialchars($value['data']) . '"';
  171. }
  172. if ($element['self_closing'])
  173. {
  174. $full .= ' />';
  175. }
  176. else
  177. {
  178. $full .= ">$element[content]</$element[tag]>";
  179. }
  180. return $full;
  181. }
  182. public static function error($message, $level, $file, $line)
  183. {
  184. if ((ini_get('error_reporting') & $level) > 0)
  185. {
  186. switch ($level)
  187. {
  188. case E_USER_ERROR:
  189. $note = 'PHP Error';
  190. break;
  191. case E_USER_WARNING:
  192. $note = 'PHP Warning';
  193. break;
  194. case E_USER_NOTICE:
  195. $note = 'PHP Notice';
  196. break;
  197. default:
  198. $note = 'Unknown Error';
  199. break;
  200. }
  201. $log_error = true;
  202. if (!function_exists('error_log'))
  203. {
  204. $log_error = false;
  205. }
  206. $log_file = @ini_get('error_log');
  207. if (!empty($log_file) && ('syslog' !== $log_file) && !@is_writable($log_file))
  208. {
  209. $log_error = false;
  210. }
  211. if ($log_error)
  212. {
  213. @error_log("$note: $message in $file on line $line", 0);
  214. }
  215. }
  216. return $message;
  217. }
  218. public static function fix_protocol($url, $http = 1)
  219. {
  220. $url = SimplePie_Misc::normalize_url($url);
  221. $parsed = SimplePie_Misc::parse_url($url);
  222. if ($parsed['scheme'] !== '' && $parsed['scheme'] !== 'http' && $parsed['scheme'] !== 'https')
  223. {
  224. return SimplePie_Misc::fix_protocol(SimplePie_Misc::compress_parse_url('http', $parsed['authority'], $parsed['path'], $parsed['query'], $parsed['fragment']), $http);
  225. }
  226. if ($parsed['scheme'] === '' && $parsed['authority'] === '' && !file_exists($url))
  227. {
  228. return SimplePie_Misc::fix_protocol(SimplePie_Misc::compress_parse_url('http', $parsed['path'], '', $parsed['query'], $parsed['fragment']), $http);
  229. }
  230. if ($http === 2 && $parsed['scheme'] !== '')
  231. {
  232. return "feed:$url";
  233. }
  234. elseif ($http === 3 && strtolower($parsed['scheme']) === 'http')
  235. {
  236. return substr_replace($url, 'podcast', 0, 4);
  237. }
  238. elseif ($http === 4 && strtolower($parsed['scheme']) === 'http')
  239. {
  240. return substr_replace($url, 'itpc', 0, 4);
  241. }
  242. else
  243. {
  244. return $url;
  245. }
  246. }
  247. public static function parse_url($url)
  248. {
  249. $iri = new SimplePie_IRI($url);
  250. return array(
  251. 'scheme' => (string) $iri->get_scheme(),
  252. 'authority' => (string) $iri->get_authority(),
  253. 'path' => (string) $iri->get_path(),
  254. 'query' => (string) $iri->get_query(),
  255. 'fragment' => (string) $iri->get_fragment()
  256. );
  257. }
  258. public static function compress_parse_url($scheme = '', $authority = '', $path = '', $query = '', $fragment = '')
  259. {
  260. $iri = new SimplePie_IRI('');
  261. $iri->set_scheme($scheme);
  262. $iri->set_authority($authority);
  263. $iri->set_path($path);
  264. $iri->set_query($query);
  265. $iri->set_fragment($fragment);
  266. return $iri->get_iri();
  267. }
  268. public static function normalize_url($url)
  269. {
  270. $iri = new SimplePie_IRI($url);
  271. return $iri->get_iri();
  272. }
  273. public static function percent_encoding_normalization($match)
  274. {
  275. $integer = hexdec($match[1]);
  276. if ($integer >= 0x41 && $integer <= 0x5A || $integer >= 0x61 && $integer <= 0x7A || $integer >= 0x30 && $integer <= 0x39 || $integer === 0x2D || $integer === 0x2E || $integer === 0x5F || $integer === 0x7E)
  277. {
  278. return chr($integer);
  279. }
  280. else
  281. {
  282. return strtoupper($match[0]);
  283. }
  284. }
  285. /**
  286. * Converts a Windows-1252 encoded string to a UTF-8 encoded string
  287. *
  288. * @static
  289. * @param string $string Windows-1252 encoded string
  290. * @return string UTF-8 encoded string
  291. */
  292. public static function windows_1252_to_utf8($string)
  293. {
  294. static $convert_table = array("\x80" => "\xE2\x82\xAC", "\x81" => "\xEF\xBF\xBD", "\x82" => "\xE2\x80\x9A", "\x83" => "\xC6\x92", "\x84" => "\xE2\x80\x9E", "\x85" => "\xE2\x80\xA6", "\x86" => "\xE2\x80\xA0", "\x87" => "\xE2\x80\xA1", "\x88" => "\xCB\x86", "\x89" => "\xE2\x80\xB0", "\x8A" => "\xC5\xA0", "\x8B" => "\xE2\x80\xB9", "\x8C" => "\xC5\x92", "\x8D" => "\xEF\xBF\xBD", "\x8E" => "\xC5\xBD", "\x8F" => "\xEF\xBF\xBD", "\x90" => "\xEF\xBF\xBD", "\x91" => "\xE2\x80\x98", "\x92" => "\xE2\x80\x99", "\x93" => "\xE2\x80\x9C", "\x94" => "\xE2\x80\x9D", "\x95" => "\xE2\x80\xA2", "\x96" => "\xE2\x80\x93", "\x97" => "\xE2\x80\x94", "\x98" => "\xCB\x9C", "\x99" => "\xE2\x84\xA2", "\x9A" => "\xC5\xA1", "\x9B" => "\xE2\x80\xBA", "\x9C" => "\xC5\x93", "\x9D" => "\xEF\xBF\xBD", "\x9E" => "\xC5\xBE", "\x9F" => "\xC5\xB8", "\xA0" => "\xC2\xA0", "\xA1" => "\xC2\xA1", "\xA2" => "\xC2\xA2", "\xA3" => "\xC2\xA3", "\xA4" => "\xC2\xA4", "\xA5" => "\xC2\xA5", "\xA6" => "\xC2\xA6", "\xA7" => "\xC2\xA7", "\xA8" => "\xC2\xA8", "\xA9" => "\xC2\xA9", "\xAA" => "\xC2\xAA", "\xAB" => "\xC2\xAB", "\xAC" => "\xC2\xAC", "\xAD" => "\xC2\xAD", "\xAE" => "\xC2\xAE", "\xAF" => "\xC2\xAF", "\xB0" => "\xC2\xB0", "\xB1" => "\xC2\xB1", "\xB2" => "\xC2\xB2", "\xB3" => "\xC2\xB3", "\xB4" => "\xC2\xB4", "\xB5" => "\xC2\xB5", "\xB6" => "\xC2\xB6", "\xB7" => "\xC2\xB7", "\xB8" => "\xC2\xB8", "\xB9" => "\xC2\xB9", "\xBA" => "\xC2\xBA", "\xBB" => "\xC2\xBB", "\xBC" => "\xC2\xBC", "\xBD" => "\xC2\xBD", "\xBE" => "\xC2\xBE", "\xBF" => "\xC2\xBF", "\xC0" => "\xC3\x80", "\xC1" => "\xC3\x81", "\xC2" => "\xC3\x82", "\xC3" => "\xC3\x83", "\xC4" => "\xC3\x84", "\xC5" => "\xC3\x85", "\xC6" => "\xC3\x86", "\xC7" => "\xC3\x87", "\xC8" => "\xC3\x88", "\xC9" => "\xC3\x89", "\xCA" => "\xC3\x8A", "\xCB" => "\xC3\x8B", "\xCC" => "\xC3\x8C", "\xCD" => "\xC3\x8D", "\xCE" => "\xC3\x8E", "\xCF" => "\xC3\x8F", "\xD0" => "\xC3\x90", "\xD1" => "\xC3\x91", "\xD2" => "\xC3\x92", "\xD3" => "\xC3\x93", "\xD4" => "\xC3\x94", "\xD5" => "\xC3\x95", "\xD6" => "\xC3\x96", "\xD7" => "\xC3\x97", "\xD8" => "\xC3\x98", "\xD9" => "\xC3\x99", "\xDA" => "\xC3\x9A", "\xDB" => "\xC3\x9B", "\xDC" => "\xC3\x9C", "\xDD" => "\xC3\x9D", "\xDE" => "\xC3\x9E", "\xDF" => "\xC3\x9F", "\xE0" => "\xC3\xA0", "\xE1" => "\xC3\xA1", "\xE2" => "\xC3\xA2", "\xE3" => "\xC3\xA3", "\xE4" => "\xC3\xA4", "\xE5" => "\xC3\xA5", "\xE6" => "\xC3\xA6", "\xE7" => "\xC3\xA7", "\xE8" => "\xC3\xA8", "\xE9" => "\xC3\xA9", "\xEA" => "\xC3\xAA", "\xEB" => "\xC3\xAB", "\xEC" => "\xC3\xAC", "\xED" => "\xC3\xAD", "\xEE" => "\xC3\xAE", "\xEF" => "\xC3\xAF", "\xF0" => "\xC3\xB0", "\xF1" => "\xC3\xB1", "\xF2" => "\xC3\xB2", "\xF3" => "\xC3\xB3", "\xF4" => "\xC3\xB4", "\xF5" => "\xC3\xB5", "\xF6" => "\xC3\xB6", "\xF7" => "\xC3\xB7", "\xF8" => "\xC3\xB8", "\xF9" => "\xC3\xB9", "\xFA" => "\xC3\xBA", "\xFB" => "\xC3\xBB", "\xFC" => "\xC3\xBC", "\xFD" => "\xC3\xBD", "\xFE" => "\xC3\xBE", "\xFF" => "\xC3\xBF");
  295. return strtr($string, $convert_table);
  296. }
  297. /**
  298. * Change a string from one encoding to another
  299. *
  300. * @param string $data Raw data in $input encoding
  301. * @param string $input Encoding of $data
  302. * @param string $output Encoding you want
  303. * @return string|boolean False if we can't convert it
  304. */
  305. public static function change_encoding($data, $input, $output)
  306. {
  307. $input = SimplePie_Misc::encoding($input);
  308. $output = SimplePie_Misc::encoding($output);
  309. // We fail to fail on non US-ASCII bytes
  310. if ($input === 'US-ASCII')
  311. {
  312. static $non_ascii_octects = '';
  313. if (!$non_ascii_octects)
  314. {
  315. for ($i = 0x80; $i <= 0xFF; $i++)
  316. {
  317. $non_ascii_octects .= chr($i);
  318. }
  319. }
  320. $data = substr($data, 0, strcspn($data, $non_ascii_octects));
  321. }
  322. // This is first, as behaviour of this is completely predictable
  323. if ($input === 'windows-1252' && $output === 'UTF-8')
  324. {
  325. return SimplePie_Misc::windows_1252_to_utf8($data);
  326. }
  327. // This is second, as behaviour of this varies only with PHP version (the middle part of this expression checks the encoding is supported).
  328. elseif (function_exists('mb_convert_encoding') && ($return = SimplePie_Misc::change_encoding_mbstring($data, $input, $output)))
  329. {
  330. return $return;
  331. }
  332. // This is last, as behaviour of this varies with OS userland and PHP version
  333. elseif (function_exists('iconv') && ($return = SimplePie_Misc::change_encoding_iconv($data, $input, $output)))
  334. {
  335. return $return;
  336. }
  337. // If we can't do anything, just fail
  338. else
  339. {
  340. return false;
  341. }
  342. }
  343. protected static function change_encoding_mbstring($data, $input, $output)
  344. {
  345. if ($input === 'windows-949')
  346. {
  347. $input = 'EUC-KR';
  348. }
  349. if ($output === 'windows-949')
  350. {
  351. $output = 'EUC-KR';
  352. }
  353. // Check that the encoding is supported
  354. if (@mb_convert_encoding("\x80", 'UTF-16BE', $input) === "\x00\x80")
  355. {
  356. return false;
  357. }
  358. if (!in_array($input, mb_list_encodings()))
  359. {
  360. return false;
  361. }
  362. // Let's do some conversion
  363. if ($return = @mb_convert_encoding($data, $output, $input))
  364. {
  365. return $return;
  366. }
  367. return false;
  368. }
  369. protected static function change_encoding_iconv($data, $input, $output)
  370. {
  371. return @iconv($input, $output, $data);
  372. }
  373. /**
  374. * Normalize an encoding name
  375. *
  376. * This is automatically generated by create.php
  377. *
  378. * To generate it, run `php create.php` on the command line, and copy the
  379. * output to replace this function.
  380. *
  381. * @param string $charset Character set to standardise
  382. * @return string Standardised name
  383. */
  384. public static function encoding($charset)
  385. {
  386. // Normalization from UTS #22
  387. switch (strtolower(preg_replace('/(?:[^a-zA-Z0-9]+|([^0-9])0+)/', '\1', $charset)))
  388. {
  389. case 'adobestandardencoding':
  390. case 'csadobestandardencoding':
  391. return 'Adobe-Standard-Encoding';
  392. case 'adobesymbolencoding':
  393. case 'cshppsmath':
  394. return 'Adobe-Symbol-Encoding';
  395. case 'ami1251':
  396. case 'amiga1251':
  397. return 'Amiga-1251';
  398. case 'ansix31101983':
  399. case 'csat5001983':
  400. case 'csiso99naplps':
  401. case 'isoir99':
  402. case 'naplps':
  403. return 'ANSI_X3.110-1983';
  404. case 'arabic7':
  405. case 'asmo449':
  406. case 'csiso89asmo449':
  407. case 'iso9036':
  408. case 'isoir89':
  409. return 'ASMO_449';
  410. case 'big5':
  411. case 'csbig5':
  412. return 'Big5';
  413. case 'big5hkscs':
  414. return 'Big5-HKSCS';
  415. case 'bocu1':
  416. case 'csbocu1':
  417. return 'BOCU-1';
  418. case 'brf':
  419. case 'csbrf':
  420. return 'BRF';
  421. case 'bs4730':
  422. case 'csiso4unitedkingdom':
  423. case 'gb':
  424. case 'iso646gb':
  425. case 'isoir4':
  426. case 'uk':
  427. return 'BS_4730';
  428. case 'bsviewdata':
  429. case 'csiso47bsviewdata':
  430. case 'isoir47':
  431. return 'BS_viewdata';
  432. case 'cesu8':
  433. case 'cscesu8':
  434. return 'CESU-8';
  435. case 'ca':
  436. case 'csa71':
  437. case 'csaz243419851':
  438. case 'csiso121canadian1':
  439. case 'iso646ca':
  440. case 'isoir121':
  441. return 'CSA_Z243.4-1985-1';
  442. case 'csa72':
  443. case 'csaz243419852':
  444. case 'csiso122canadian2':
  445. case 'iso646ca2':
  446. case 'isoir122':
  447. return 'CSA_Z243.4-1985-2';
  448. case 'csaz24341985gr':
  449. case 'csiso123csaz24341985gr':
  450. case 'isoir123':
  451. return 'CSA_Z243.4-1985-gr';
  452. case 'csiso139csn369103':
  453. case 'csn369103':
  454. case 'isoir139':
  455. return 'CSN_369103';
  456. case 'csdecmcs':
  457. case 'dec':
  458. case 'decmcs':
  459. return 'DEC-MCS';
  460. case 'csiso21german':
  461. case 'de':
  462. case 'din66003':
  463. case 'iso646de':
  464. case 'isoir21':
  465. return 'DIN_66003';
  466. case 'csdkus':
  467. case 'dkus':
  468. return 'dk-us';
  469. case 'csiso646danish':
  470. case 'dk':
  471. case 'ds2089':
  472. case 'iso646dk':
  473. return 'DS_2089';
  474. case 'csibmebcdicatde':
  475. case 'ebcdicatde':
  476. return 'EBCDIC-AT-DE';
  477. case 'csebcdicatdea':
  478. case 'ebcdicatdea':
  479. return 'EBCDIC-AT-DE-A';
  480. case 'csebcdiccafr':
  481. case 'ebcdiccafr':
  482. return 'EBCDIC-CA-FR';
  483. case 'csebcdicdkno':
  484. case 'ebcdicdkno':
  485. return 'EBCDIC-DK-NO';
  486. case 'csebcdicdknoa':
  487. case 'ebcdicdknoa':
  488. return 'EBCDIC-DK-NO-A';
  489. case 'csebcdices':
  490. case 'ebcdices':
  491. return 'EBCDIC-ES';
  492. case 'csebcdicesa':
  493. case 'ebcdicesa':
  494. return 'EBCDIC-ES-A';
  495. case 'csebcdicess':
  496. case 'ebcdicess':
  497. return 'EBCDIC-ES-S';
  498. case 'csebcdicfise':
  499. case 'ebcdicfise':
  500. return 'EBCDIC-FI-SE';
  501. case 'csebcdicfisea':
  502. case 'ebcdicfisea':
  503. return 'EBCDIC-FI-SE-A';
  504. case 'csebcdicfr':
  505. case 'ebcdicfr':
  506. return 'EBCDIC-FR';
  507. case 'csebcdicit':
  508. case 'ebcdicit':
  509. return 'EBCDIC-IT';
  510. case 'csebcdicpt':
  511. case 'ebcdicpt':
  512. return 'EBCDIC-PT';
  513. case 'csebcdicuk':
  514. case 'ebcdicuk':
  515. return 'EBCDIC-UK';
  516. case 'csebcdicus':
  517. case 'ebcdicus':
  518. return 'EBCDIC-US';
  519. case 'csiso111ecmacyrillic':
  520. case 'ecmacyrillic':
  521. case 'isoir111':
  522. case 'koi8e':
  523. return 'ECMA-cyrillic';
  524. case 'csiso17spanish':
  525. case 'es':
  526. case 'iso646es':
  527. case 'isoir17':
  528. return 'ES';
  529. case 'csiso85spanish2':
  530. case 'es2':
  531. case 'iso646es2':
  532. case 'isoir85':
  533. return 'ES2';
  534. case 'cseucpkdfmtjapanese':
  535. case 'eucjp':
  536. case 'extendedunixcodepackedformatforjapanese':
  537. return 'EUC-JP';
  538. case 'cseucfixwidjapanese':
  539. case 'extendedunixcodefixedwidthforjapanese':
  540. return 'Extended_UNIX_Code_Fixed_Width_for_Japanese';
  541. case 'gb18030':
  542. return 'GB18030';
  543. case 'chinese':
  544. case 'cp936':
  545. case 'csgb2312':
  546. case 'csiso58gb231280':
  547. case 'gb2312':
  548. case 'gb231280':
  549. case 'gbk':
  550. case 'isoir58':
  551. case 'ms936':
  552. case 'windows936':
  553. return 'GBK';
  554. case 'cn':
  555. case 'csiso57gb1988':
  556. case 'gb198880':
  557. case 'iso646cn':
  558. case 'isoir57':
  559. return 'GB_1988-80';
  560. case 'csiso153gost1976874':
  561. case 'gost1976874':
  562. case 'isoir153':
  563. case 'stsev35888':
  564. return 'GOST_19768-74';
  565. case 'csiso150':
  566. case 'csiso150greekccitt':
  567. case 'greekccitt':
  568. case 'isoir150':
  569. return 'greek-ccitt';
  570. case 'csiso88greek7':
  571. case 'greek7':
  572. case 'isoir88':
  573. return 'greek7';
  574. case 'csiso18greek7old':
  575. case 'greek7old':
  576. case 'isoir18':
  577. return 'greek7-old';
  578. case 'cshpdesktop':
  579. case 'hpdesktop':
  580. return 'HP-DeskTop';
  581. case 'cshplegal':
  582. case 'hplegal':
  583. return 'HP-Legal';
  584. case 'cshpmath8':
  585. case 'hpmath8':
  586. return 'HP-Math8';
  587. case 'cshppifont':
  588. case 'hppifont':
  589. return 'HP-Pi-font';
  590. case 'cshproman8':
  591. case 'hproman8':
  592. case 'r8':
  593. case 'roman8':
  594. return 'hp-roman8';
  595. case 'hzgb2312':
  596. return 'HZ-GB-2312';
  597. case 'csibmsymbols':
  598. case 'ibmsymbols':
  599. return 'IBM-Symbols';
  600. case 'csibmthai':
  601. case 'ibmthai':
  602. return 'IBM-Thai';
  603. case 'cp37':
  604. case 'csibm37':
  605. case 'ebcdiccpca':
  606. case 'ebcdiccpnl':
  607. case 'ebcdiccpus':
  608. case 'ebcdiccpwt':
  609. case 'ibm37':
  610. return 'IBM037';
  611. case 'cp38':
  612. case 'csibm38':
  613. case 'ebcdicint':
  614. case 'ibm38':
  615. return 'IBM038';
  616. case 'cp273':
  617. case 'csibm273':
  618. case 'ibm273':
  619. return 'IBM273';
  620. case 'cp274':
  621. case 'csibm274':
  622. case 'ebcdicbe':
  623. case 'ibm274':
  624. return 'IBM274';
  625. case 'cp275':
  626. case 'csibm275':
  627. case 'ebcdicbr':
  628. case 'ibm275':
  629. return 'IBM275';
  630. case 'csibm277':
  631. case 'ebcdiccpdk':
  632. case 'ebcdiccpno':
  633. case 'ibm277':
  634. return 'IBM277';
  635. case 'cp278':
  636. case 'csibm278':
  637. case 'ebcdiccpfi':
  638. case 'ebcdiccpse':
  639. case 'ibm278':
  640. return 'IBM278';
  641. case 'cp280':
  642. case 'csibm280':
  643. case 'ebcdiccpit':
  644. case 'ibm280':
  645. return 'IBM280';
  646. case 'cp281':
  647. case 'csibm281':
  648. case 'ebcdicjpe':
  649. case 'ibm281':
  650. return 'IBM281';
  651. case 'cp284':
  652. case 'csibm284':
  653. case 'ebcdiccpes':
  654. case 'ibm284':
  655. return 'IBM284';
  656. case 'cp285':
  657. case 'csibm285':
  658. case 'ebcdiccpgb':
  659. case 'ibm285':
  660. return 'IBM285';
  661. case 'cp290':
  662. case 'csibm290':
  663. case 'ebcdicjpkana':
  664. case 'ibm290':
  665. return 'IBM290';
  666. case 'cp297':
  667. case 'csibm297':
  668. case 'ebcdiccpfr':
  669. case 'ibm297':
  670. return 'IBM297';
  671. case 'cp420':
  672. case 'csibm420':
  673. case 'ebcdiccpar1':
  674. case 'ibm420':
  675. return 'IBM420';
  676. case 'cp423':
  677. case 'csibm423':
  678. case 'ebcdiccpgr':
  679. case 'ibm423':
  680. return 'IBM423';
  681. case 'cp424':
  682. case 'csibm424':
  683. case 'ebcdiccphe':
  684. case 'ibm424':
  685. return 'IBM424';
  686. case '437':
  687. case 'cp437':
  688. case 'cspc8codepage437':
  689. case 'ibm437':
  690. return 'IBM437';
  691. case 'cp500':
  692. case 'csibm500':
  693. case 'ebcdiccpbe':
  694. case 'ebcdiccpch':
  695. case 'ibm500':
  696. return 'IBM500';
  697. case 'cp775':
  698. case 'cspc775baltic':
  699. case 'ibm775':
  700. return 'IBM775';
  701. case '850':
  702. case 'cp850':
  703. case 'cspc850multilingual':
  704. case 'ibm850':
  705. return 'IBM850';
  706. case '851':
  707. case 'cp851':
  708. case 'csibm851':
  709. case 'ibm851':
  710. return 'IBM851';
  711. case '852':
  712. case 'cp852':
  713. case 'cspcp852':
  714. case 'ibm852':
  715. return 'IBM852';
  716. case '855':
  717. case 'cp855':
  718. case 'csibm855':
  719. case 'ibm855':
  720. return 'IBM855';
  721. case '857':
  722. case 'cp857':
  723. case 'csibm857':
  724. case 'ibm857':
  725. return 'IBM857';
  726. case 'ccsid858':
  727. case 'cp858':
  728. case 'ibm858':
  729. case 'pcmultilingual850euro':
  730. return 'IBM00858';
  731. case '860':
  732. case 'cp860':
  733. case 'csibm860':
  734. case 'ibm860':
  735. return 'IBM860';
  736. case '861':
  737. case 'cp861':
  738. case 'cpis':
  739. case 'csibm861':
  740. case 'ibm861':
  741. return 'IBM861';
  742. case '862':
  743. case 'cp862':
  744. case 'cspc862latinhebrew':
  745. case 'ibm862':
  746. return 'IBM862';
  747. case '863':
  748. case 'cp863':
  749. case 'csibm863':
  750. case 'ibm863':
  751. return 'IBM863';
  752. case 'cp864':
  753. case 'csibm864':
  754. case 'ibm864':
  755. return 'IBM864';
  756. case '865':
  757. case 'cp865':
  758. case 'csibm865':
  759. case 'ibm865':
  760. return 'IBM865';
  761. case '866':
  762. case 'cp866':
  763. case 'csibm866':
  764. case 'ibm866':
  765. return 'IBM866';
  766. case 'cp868':
  767. case 'cpar':
  768. case 'csibm868':
  769. case 'ibm868':
  770. return 'IBM868';
  771. case '869':
  772. case 'cp869':
  773. case 'cpgr':
  774. case 'csibm869':
  775. case 'ibm869':
  776. return 'IBM869';
  777. case 'cp870':
  778. case 'csibm870':
  779. case 'ebcdiccproece':
  780. case 'ebcdiccpyu':
  781. case 'ibm870':
  782. return 'IBM870';
  783. case 'cp871':
  784. case 'csibm871':
  785. case 'ebcdiccpis':
  786. case 'ibm871':
  787. return 'IBM871';
  788. case 'cp880':
  789. case 'csibm880':
  790. case 'ebcdiccyrillic':
  791. case 'ibm880':
  792. return 'IBM880';
  793. case 'cp891':
  794. case 'csibm891':
  795. case 'ibm891':
  796. return 'IBM891';
  797. case 'cp903':
  798. case 'csibm903':
  799. case 'ibm903':
  800. return 'IBM903';
  801. case '904':
  802. case 'cp904':
  803. case 'csibbm904':
  804. case 'ibm904':
  805. return 'IBM904';
  806. case 'cp905':
  807. case 'csibm905':
  808. case 'ebcdiccptr':
  809. case 'ibm905':
  810. return 'IBM905';
  811. case 'cp918':
  812. case 'csibm918':
  813. case 'ebcdiccpar2':
  814. case 'ibm918':
  815. return 'IBM918';
  816. case 'ccsid924':
  817. case 'cp924':
  818. case 'ebcdiclatin9euro':
  819. case 'ibm924':
  820. return 'IBM00924';
  821. case 'cp1026':
  822. case 'csibm1026':
  823. case 'ibm1026':
  824. return 'IBM1026';
  825. case 'ibm1047':
  826. return 'IBM1047';
  827. case 'ccsid1140':
  828. case 'cp1140':
  829. case 'ebcdicus37euro':
  830. case 'ibm1140':
  831. return 'IBM01140';
  832. case 'ccsid1141':
  833. case 'cp1141':
  834. case 'ebcdicde273euro':
  835. case 'ibm1141':
  836. return 'IBM01141';
  837. case 'ccsid1142':
  838. case 'cp1142':
  839. case 'ebcdicdk277euro':
  840. case 'ebcdicno277euro':
  841. case 'ibm1142':
  842. return 'IBM01142';
  843. case 'ccsid1143':
  844. case 'cp1143':
  845. case 'ebcdicfi278euro':
  846. case 'ebcdicse278euro':
  847. case 'ibm1143':
  848. return 'IBM01143';
  849. case 'ccsid1144':
  850. case 'cp1144':
  851. case 'ebcdicit280euro':
  852. case 'ibm1144':
  853. return 'IBM01144';
  854. case 'ccsid1145':
  855. case 'cp1145':
  856. case 'ebcdices284euro':
  857. case 'ibm1145':
  858. return 'IBM01145';
  859. case 'ccsid1146':
  860. case 'cp1146':
  861. case 'ebcdicgb285euro':
  862. case 'ibm1146':
  863. return 'IBM01146';
  864. case 'ccsid1147':
  865. case 'cp1147':
  866. case 'ebcdicfr297euro':
  867. case 'ibm1147':
  868. return 'IBM01147';
  869. case 'ccsid1148':
  870. case 'cp1148':
  871. case 'ebcdicinternational500euro':
  872. case 'ibm1148':
  873. return 'IBM01148';
  874. case 'ccsid1149':
  875. case 'cp1149':
  876. case 'ebcdicis871euro':
  877. case 'ibm1149':
  878. return 'IBM01149';
  879. case 'csiso143iecp271':
  880. case 'iecp271':
  881. case 'isoir143':
  882. return 'IEC_P27-1';
  883. case 'csiso49inis':
  884. case 'inis':
  885. case 'isoir49':
  886. return 'INIS';
  887. case 'csiso50inis8':
  888. case 'inis8':
  889. case 'isoir50':
  890. return 'INIS-8';
  891. case 'csiso51iniscyrillic':
  892. case 'iniscyrillic':
  893. case 'isoir51':
  894. return 'INIS-cyrillic';
  895. case 'csinvariant':
  896. case 'invariant':
  897. return 'INVARIANT';
  898. case 'iso2022cn':
  899. return 'ISO-2022-CN';
  900. case 'iso2022cnext':
  901. return 'ISO-2022-CN-EXT';
  902. case 'csiso2022jp':
  903. case 'iso2022jp':
  904. return 'ISO-2022-JP';
  905. case 'csiso2022jp2':
  906. case 'iso2022jp2':
  907. return 'ISO-2022-JP-2';
  908. case 'csiso2022kr':
  909. case 'iso2022kr':
  910. return 'ISO-2022-KR';
  911. case 'cswindows30latin1':
  912. case 'iso88591windows30latin1':
  913. return 'ISO-8859-1-Windows-3.0-Latin-1';
  914. case 'cswindows31latin1':
  915. case 'iso88591windows31latin1':
  916. return 'ISO-8859-1-Windows-3.1-Latin-1';
  917. case 'csisolatin2':
  918. case 'iso88592':
  919. case 'iso885921987':
  920. case 'isoir101':
  921. case 'l2':
  922. case 'latin2':
  923. return 'ISO-8859-2';
  924. case 'cswindows31latin2':
  925. case 'iso88592windowslatin2':
  926. return 'ISO-8859-2-Windows-Latin-2';
  927. case 'csisolatin3':
  928. case 'iso88593':
  929. case 'iso885931988':
  930. case 'isoir109':
  931. case 'l3':
  932. case 'latin3':
  933. return 'ISO-8859-3';
  934. case 'csisolatin4':
  935. case 'iso88594':
  936. case 'iso885941988':
  937. case 'isoir110':
  938. case 'l4':
  939. case 'latin4':
  940. return 'ISO-8859-4';
  941. case 'csisolatincyrillic':
  942. case 'cyrillic':
  943. case 'iso88595':
  944. case 'iso885951988':
  945. case 'isoir144':
  946. return 'ISO-8859-5';
  947. case 'arabic':
  948. case 'asmo708':
  949. case 'csisolatinarabic':
  950. case 'ecma114':
  951. case 'iso88596':
  952. case 'iso885961987':
  953. case 'isoir127':
  954. return 'ISO-8859-6';
  955. case 'csiso88596e':
  956. case 'iso88596e':
  957. return 'ISO-8859-6-E';
  958. case 'csiso88596i':
  959. case 'iso88596i':
  960. return 'ISO-8859-6-I';
  961. case 'csisolatingreek':
  962. case 'ecma118':
  963. case 'elot928':
  964. case 'greek':
  965. case 'greek8':
  966. case 'iso88597':
  967. case 'iso885971987':
  968. case 'isoir126':
  969. return 'ISO-8859-7';
  970. case 'csisolatinhebrew':
  971. case 'hebrew':
  972. case 'iso88598':
  973. case 'iso885981988':
  974. case 'isoir138':
  975. return 'ISO-8859-8';
  976. case 'csiso88598e':
  977. case 'iso88598e':
  978. return 'ISO-8859-8-E';
  979. case 'csiso88598i':
  980. case 'iso88598i':
  981. return 'ISO-8859-8-I';
  982. case 'cswindows31latin5':
  983. case 'iso88599windowslatin5':
  984. return 'ISO-8859-9-Windows-Latin-5';
  985. case 'csisolatin6':
  986. case 'iso885910':
  987. case 'iso8859101992':
  988. case 'isoir157':
  989. case 'l6':
  990. case 'latin6':
  991. return 'ISO-8859-10';
  992. case 'iso885913':
  993. return 'ISO-8859-13';
  994. case 'iso885914':
  995. case 'iso8859141998':
  996. case 'isoceltic':
  997. case 'isoir199':
  998. case 'l8':
  999. case 'latin8':
  1000. return 'ISO-8859-14';
  1001. case 'iso885915':
  1002. case 'latin9':
  1003. return 'ISO-8859-15';
  1004. case 'iso885916':
  1005. case 'iso8859162001':
  1006. case 'isoir226':
  1007. case 'l10':
  1008. case 'latin10':
  1009. return 'ISO-8859-16';
  1010. case 'iso10646j1':
  1011. return 'ISO-10646-J-1';
  1012. case 'csunicode':
  1013. case 'iso10646ucs2':
  1014. return 'ISO-10646-UCS-2';
  1015. case 'csucs4':
  1016. case 'iso10646ucs4':
  1017. return 'ISO-10646-UCS-4';
  1018. case 'csunicodeascii':
  1019. case 'iso10646ucsbasic':
  1020. return 'ISO-10646-UCS-Basic';
  1021. case 'csunicodelatin1':
  1022. case 'iso10646':
  1023. case 'iso10646unicodelatin1':
  1024. return 'ISO-10646-Unicode-Latin1';
  1025. case 'csiso10646utf1':
  1026. case 'iso10646utf1':
  1027. return 'ISO-10646-UTF-1';
  1028. case 'csiso115481':
  1029. case 'iso115481':
  1030. case 'isotr115481':
  1031. return 'ISO-11548-1';
  1032. case 'csiso90':
  1033. case 'isoir90':
  1034. return 'iso-ir-90';
  1035. case 'csunicodeibm1261':
  1036. case 'isounicodeibm1261':
  1037. return 'ISO-Unicode-IBM-1261';
  1038. case 'csunicodeibm1264':
  1039. case 'isounicodeibm1264':
  1040. return 'ISO-Unicode-IBM-1264';
  1041. case 'csunicodeibm1265':
  1042. case 'isounicodeibm1265':
  1043. return 'ISO-Unicode-IBM-1265';
  1044. case 'csunicodeibm1268':
  1045. case 'isounicodeibm1268':
  1046. return 'ISO-Unicode-IBM-1268';
  1047. case 'csunicodeibm1276':
  1048. case 'isounicodeibm1276':
  1049. return 'ISO-Unicode-IBM-1276';
  1050. case 'csiso646basic1983':
  1051. case 'iso646basic1983':
  1052. case 'ref':
  1053. return 'ISO_646.basic:1983';
  1054. case 'csiso2intlrefversion':
  1055. case 'irv':
  1056. case 'iso646irv1983':
  1057. case 'isoir2':
  1058. return 'ISO_646.irv:1983';
  1059. case 'csiso2033':
  1060. case 'e13b':
  1061. case 'iso20331983':
  1062. case 'isoir98':
  1063. return 'ISO_2033-1983';
  1064. case 'csiso5427cyrillic':
  1065. case 'iso5427':
  1066. case 'isoir37':
  1067. return 'ISO_5427';
  1068. case 'iso5427cyrillic1981':
  1069. case 'iso54271981':
  1070. case 'isoir54':
  1071. return 'ISO_5427:1981';
  1072. case 'csiso5428greek':
  1073. case 'iso54281980':
  1074. case 'isoir55':
  1075. return 'ISO_5428:1980';
  1076. case 'csiso6937add':
  1077. case 'iso6937225':
  1078. case 'isoir152':
  1079. return 'ISO_6937-2-25';
  1080. case 'csisotextcomm':
  1081. case 'iso69372add':
  1082. case 'isoir142':
  1083. return 'ISO_6937-2-add';
  1084. case 'csiso8859supp':
  1085. case 'iso8859supp':
  1086. case 'isoir154':
  1087. case 'latin125':
  1088. return 'ISO_8859-supp';
  1089. case 'csiso10367box':
  1090. case 'iso10367box':
  1091. case 'isoir155':
  1092. return 'ISO_10367-box';
  1093. case 'csiso15italian':
  1094. case 'iso646it':
  1095. case 'isoir15':
  1096. case 'it':
  1097. return 'IT';
  1098. case 'csiso13jisc6220jp':
  1099. case 'isoir13':
  1100. case 'jisc62201969':
  1101. case 'jisc62201969jp':
  1102. case 'katakana':
  1103. case 'x2017':
  1104. return 'JIS_C6220-1969-jp';
  1105. case 'csiso14jisc6220ro':
  1106. case 'iso646jp':
  1107. case 'isoir14':
  1108. case 'jisc62201969ro':
  1109. case 'jp':
  1110. return 'JIS_C6220-1969-ro';
  1111. case 'csiso42jisc62261978':
  1112. case 'isoir42':
  1113. case 'jisc62261978':
  1114. return 'JIS_C6226-1978';
  1115. case 'csiso87jisx208':
  1116. case 'isoir87':
  1117. case 'jisc62261983':
  1118. case 'jisx2081983':
  1119. case 'x208':
  1120. return 'JIS_C6226-1983';
  1121. case 'csiso91jisc62291984a':
  1122. case 'isoir91':
  1123. case 'jisc62291984a':
  1124. case 'jpocra':
  1125. return 'JIS_C6229-1984-a';
  1126. case 'csiso92jisc62991984b':
  1127. case 'iso646jpocrb':
  1128. case 'isoir92':
  1129. case 'jisc62291984b':
  1130. case 'jpocrb':
  1131. return 'JIS_C6229-1984-b';
  1132. case 'csiso93jis62291984badd':
  1133. case 'isoir93':
  1134. case 'jisc62291984badd':
  1135. case 'jpocrbadd':
  1136. return 'JIS_C6229-1984-b-add';
  1137. case 'csiso94jis62291984hand':
  1138. case 'isoir94':
  1139. case 'jisc62291984hand':
  1140. case 'jpocrhand':
  1141. return 'JIS_C6229-1984-hand';
  1142. case 'csiso95jis62291984handadd':
  1143. case 'isoir95':
  1144. case 'jisc62291984handadd':
  1145. case 'jpocrhandadd':
  1146. return 'JIS_C6229-1984-hand-add';
  1147. case 'csiso96jisc62291984kana':
  1148. case 'isoir96':
  1149. case 'jisc62291984kana':
  1150. return 'JIS_C6229-1984-kana';
  1151. case 'csjisencoding':
  1152. case 'jisencoding':
  1153. return 'JIS_Encoding';
  1154. case 'cshalfwidthkatakana':
  1155. case 'jisx201':
  1156. case 'x201':
  1157. return 'JIS_X0201';
  1158. case 'csiso159jisx2121990':
  1159. case 'isoir159':
  1160. case 'jisx2121990':
  1161. case 'x212':
  1162. return 'JIS_X0212-1990';
  1163. case 'csiso141jusib1002':
  1164. case 'iso646yu':
  1165. case 'isoir141':
  1166. case 'js':
  1167. case 'jusib1002':
  1168. case 'yu':
  1169. return 'JUS_I.B1.002';
  1170. case 'csiso147macedonian':
  1171. case 'isoir147':
  1172. case 'jusib1003mac':
  1173. case 'macedonian':
  1174. return 'JUS_I.B1.003-mac';
  1175. case 'csiso146serbian':
  1176. case 'isoir146':
  1177. case 'jusib1003serb':
  1178. case 'serbian':
  1179. return 'JUS_I.B1.003-serb';
  1180. case 'koi7switched':
  1181. return 'KOI7-switched';
  1182. case 'cskoi8r':
  1183. case 'koi8r':
  1184. return 'KOI8-R';
  1185. case 'koi8u':
  1186. return 'KOI8-U';
  1187. case 'csksc5636':
  1188. case 'iso646kr':
  1189. case 'ksc5636':
  1190. return 'KSC5636';
  1191. case 'cskz1048':
  1192. case 'kz1048':
  1193. case 'rk1048':
  1194. case 'strk10482002':
  1195. return 'KZ-1048';
  1196. case 'csiso19latingreek':
  1197. case 'isoir19':
  1198. case 'latingreek':
  1199. return 'latin-greek';
  1200. case 'csiso27latingreek1':
  1201. case 'isoir27':
  1202. case 'latingreek1':
  1203. return 'Latin-greek-1';
  1204. case 'csiso158lap':
  1205. case 'isoir158':
  1206. case 'lap':
  1207. case 'latinlap':
  1208. return 'latin-lap';
  1209. case 'csmacintosh':
  1210. case 'mac':
  1211. case 'macintosh':
  1212. return 'macintosh';
  1213. case 'csmicrosoftpublishing':
  1214. case 'microsoftpublishing':
  1215. return 'Microsoft-Publishing';
  1216. case 'csmnem':
  1217. case 'mnem':
  1218. return 'MNEM';
  1219. case 'csmnemonic':
  1220. case 'mnemonic':
  1221. return 'MNEMONIC';
  1222. case 'csiso86hungarian':
  1223. case 'hu':
  1224. case 'iso646hu':
  1225. case 'isoir86':
  1226. case 'msz77953':
  1227. return 'MSZ_7795.3';
  1228. case 'csnatsdano':
  1229. case 'isoir91':
  1230. case 'natsdano':
  1231. return 'NATS-DANO';
  1232. case 'csnatsdanoadd':
  1233. case 'isoir92':
  1234. case 'natsdanoadd':
  1235. return 'NATS-DANO-ADD';
  1236. case 'csnatssefi':
  1237. case 'isoir81':
  1238. case 'natssefi':
  1239. return 'NATS-SEFI';
  1240. case 'csnatssefiadd':
  1241. case 'isoir82':
  1242. case 'natssefiadd':
  1243. return 'NATS-SEFI-ADD';
  1244. case 'csiso151cuba':
  1245. case 'cuba':
  1246. case 'iso646cu':
  1247. case 'isoir151':
  1248. case 'ncnc1081':
  1249. return 'NC_NC00-10:81';
  1250. case 'csiso69french':
  1251. case 'fr':
  1252. case 'iso646fr':
  1253. case 'isoir69':
  1254. case 'nfz62010':
  1255. return 'NF_Z_62-010';
  1256. case 'csiso25french':
  1257. case 'iso646fr1':
  1258. case 'isoir25':
  1259. case 'nfz620101973':
  1260. return 'NF_Z_62-010_(1973)';
  1261. case 'csiso60danishnorwegian':
  1262. case 'csiso60norwegian1':
  1263. case 'iso646no':
  1264. case 'isoir60':
  1265. case 'no':
  1266. case 'ns45511':
  1267. return 'NS_4551-1';
  1268. case 'csiso61norwegian2':
  1269. case 'iso646no2':
  1270. case 'isoir61':
  1271. case 'no2':
  1272. case 'ns45512':
  1273. return 'NS_4551-2';
  1274. case 'osdebcdicdf3irv':
  1275. return 'OSD_EBCDIC_DF03_IRV';
  1276. case 'osdebcdicdf41':
  1277. return 'OSD_EBCDIC_DF04_1';
  1278. case 'osdebcdicdf415':
  1279. return 'OSD_EBCDIC_DF04_15';
  1280. case 'cspc8danishnorwegian':
  1281. case 'pc8danishnorwegian':
  1282. return 'PC8-Danish-Norwegian';
  1283. case 'cspc8turkish':
  1284. case 'pc8turkish':
  1285. return 'PC8-Turkish';
  1286. case 'csiso16portuguese':
  1287. case 'iso646pt':
  1288. case 'isoir16':
  1289. case 'pt':
  1290. return 'PT';
  1291. case 'csiso84portuguese2':
  1292. case 'iso646pt2':
  1293. case 'isoir84':
  1294. case 'pt2':
  1295. return 'PT2';
  1296. case 'cp154':
  1297. case 'csptcp154':
  1298. case 'cyrillicasian':
  1299. case 'pt154':
  1300. case 'ptcp154':
  1301. return 'PTCP154';
  1302. case 'scsu':
  1303. return 'SCSU';
  1304. case 'csiso10swedish':
  1305. case 'fi':
  1306. case 'iso646fi':
  1307. case 'iso646se':
  1308. case 'isoir10':
  1309. case 'se':
  1310. case 'sen850200b':
  1311. return 'SEN_850200_B';
  1312. case 'csiso11swedishfornames':
  1313. case 'iso646se2':
  1314. case 'isoir11':
  1315. case 'se2':
  1316. case 'sen850200c':
  1317. return 'SEN_850200_C';
  1318. case 'csiso102t617bit':
  1319. case 'isoir102':
  1320. case 't617bit':
  1321. return 'T.61-7bit';
  1322. case 'csiso103t618bit':
  1323. case 'isoir103':
  1324. case 't61':
  1325. case 't618bit':
  1326. return 'T.61-8bit';
  1327. case 'csiso128t101g2':
  1328. case 'isoir128':
  1329. case 't101g2':
  1330. return 'T.101-G2';
  1331. case 'cstscii':
  1332. case 'tscii':
  1333. return 'TSCII';
  1334. case 'csunicode11':
  1335. case 'unicode11':
  1336. return 'UNICODE-1-1';
  1337. case 'csunicode11utf7':
  1338. case 'unicode11utf7':
  1339. return 'UNICODE-1-1-UTF-7';
  1340. case 'csunknown8bit':
  1341. case 'unknown8bit':
  1342. return 'UNKNOWN-8BIT';
  1343. case 'ansix341968':
  1344. case 'ansix341986':
  1345. case 'ascii':
  1346. case 'cp367':
  1347. case 'csascii':
  1348. case 'ibm367':
  1349. case 'iso646irv1991':
  1350. case 'iso646us':
  1351. case 'isoir6':
  1352. case 'us':
  1353. case 'usascii':
  1354. return 'US-ASCII';
  1355. case 'csusdk':
  1356. case 'usdk':
  1357. return 'us-dk';
  1358. case 'utf7':
  1359. return 'UTF-7';
  1360. case 'utf8':
  1361. return 'UTF-8';
  1362. case 'utf16':
  1363. return 'UTF-16';
  1364. case 'utf16be':
  1365. return 'UTF-16BE';
  1366. case 'utf16le':
  1367. return 'UTF-16LE';
  1368. case 'utf32':
  1369. return 'UTF-32';
  1370. case 'utf32be':
  1371. return 'UTF-32BE';
  1372. case 'utf32le':
  1373. return 'UTF-32LE';
  1374. case 'csventurainternational':
  1375. case 'venturainternational':
  1376. return 'Ventura-International';
  1377. case 'csventuramath':
  1378. case 'venturamath':
  1379. return 'Ventura-Math';
  1380. case 'csventuraus':
  1381. case 'venturaus':
  1382. return 'Ventura-US';
  1383. case 'csiso70videotexsupp1':
  1384. case 'isoir70':
  1385. case 'videotexsuppl':
  1386. return 'videotex-suppl';
  1387. case 'csviqr':
  1388. case 'viqr':
  1389. return 'VIQR';
  1390. case 'csviscii':
  1391. case 'viscii':
  1392. return 'VISCII';
  1393. case 'csshiftjis':
  1394. case 'cswindows31j':
  1395. case 'mskanji':
  1396. case 'shiftjis':
  1397. case 'windows31j':
  1398. return 'SJIS';
  1399. //return 'Windows-31J';
  1400. case 'iso885911':
  1401. case 'tis620':
  1402. return 'windows-874';
  1403. case 'cseuckr':
  1404. case 'csksc56011987':
  1405. case 'euckr':
  1406. case 'isoir149':
  1407. case 'korean':
  1408. case 'ksc5601':
  1409. case 'ksc56011987':
  1410. case 'ksc56011989':
  1411. case 'windows949':
  1412. return 'windows-949';
  1413. case 'windows1250':
  1414. return 'windows-1250';
  1415. case 'windows1251':
  1416. return 'windows-1251';
  1417. case 'cp819':
  1418. case 'csisolatin1':
  1419. case 'ibm819':
  1420. case 'iso88591':
  1421. case 'iso885911987':
  1422. case 'isoir100':
  1423. case 'l1':
  1424. case 'latin1':
  1425. case 'windows1252':
  1426. return 'windows-1252';
  1427. case 'windows1253':
  1428. return 'windows-1253';
  1429. case 'csisolatin5':
  1430. case 'iso88599':
  1431. case 'iso885991989':
  1432. case 'isoir148':
  1433. case 'l5':
  1434. case 'latin5':
  1435. case 'windows1254':
  1436. return 'windows-1254';
  1437. case 'windows1255':
  1438. return 'windows-1255';
  1439. case 'windows1256':
  1440. return 'windows-1256';
  1441. case 'windows1257':
  1442. return 'windows-1257';
  1443. case 'windows1258':
  1444. return 'windows-1258';
  1445. default:
  1446. return $charset;
  1447. }
  1448. }
  1449. public static function get_curl_version()
  1450. {
  1451. if (is_array($curl = curl_version()))
  1452. {
  1453. $curl = $curl['version'];
  1454. }
  1455. elseif (substr($curl, 0, 5) === 'curl/')
  1456. {
  1457. $curl = substr($curl, 5, strcspn($curl, "\x09\x0A\x0B\x0C\x0D", 5));
  1458. }
  1459. elseif (substr($curl, 0, 8) === 'libcurl/')
  1460. {
  1461. $curl = substr($curl, 8, strcspn($curl, "\x09\x0A\x0B\x0C\x0D", 8));
  1462. }
  1463. else
  1464. {
  1465. $curl = 0;
  1466. }
  1467. return $curl;
  1468. }
  1469. public static function is_subclass_of($class1, $class2)
  1470. {
  1471. if (func_num_args() !== 2)
  1472. {
  1473. trigger_error('Wrong parameter count for SimplePie_Misc::is_subclass_of()', E_USER_WARNING);
  1474. }
  1475. elseif (version_compare(PHP_VERSION, '5.0.3', '>=') || is_object($class1))
  1476. {
  1477. return is_subclass_of($class1, $class2);
  1478. }
  1479. elseif (is_string($class1) && is_string($class2))
  1480. {
  1481. if (class_exists($class1))
  1482. {
  1483. if (class_exists($class2))
  1484. {
  1485. $class2 = strtolower($class2);
  1486. while ($class1 = strtolower(get_parent_class($class1)))
  1487. {
  1488. if ($class1 === $class2)
  1489. {
  1490. return true;
  1491. }
  1492. }
  1493. }
  1494. }
  1495. else
  1496. {
  1497. trigger_error('Unknown class passed as parameter', E_USER_WARNNG);
  1498. }
  1499. }
  1500. return false;
  1501. }
  1502. /**
  1503. * Strip HTML comments
  1504. *
  1505. * @param string $data Data to strip comments from
  1506. * @return string Comment stripped string
  1507. */
  1508. public static function strip_comments($data)
  1509. {
  1510. $output = '';
  1511. while (($start = strpos($data, '<!--')) !== false)
  1512. {
  1513. $output .= substr($data, 0, $start);
  1514. if (($end = strpos($data, '-->', $start)) !== false)
  1515. {
  1516. $data = substr_replace($data, '', 0, $end + 3);
  1517. }
  1518. else
  1519. {
  1520. $data = '';
  1521. }
  1522. }
  1523. return $output . $data;
  1524. }
  1525. public static function parse_date($dt)
  1526. {
  1527. $parser = SimplePie_Parse_Date::get();
  1528. return $parser->parse($dt);
  1529. }
  1530. /**
  1531. * Decode HTML entities
  1532. *
  1533. * @static
  1534. * @param string $data Input data
  1535. * @return string Output data
  1536. */
  1537. public static function entities_decode($data)
  1538. {
  1539. $decoder = new SimplePie_Decode_HTML_Entities($data);
  1540. return $decoder->parse();
  1541. }
  1542. /**
  1543. * Remove RFC822 comments
  1544. *
  1545. * @param string $data Data to strip comments from
  1546. * @return string Comment stripped string
  1547. */
  1548. public static function uncomment_rfc822($string)
  1549. {
  1550. $string = (string) $string;
  1551. $position = 0;
  1552. $length = strlen($string);
  1553. $depth = 0;
  1554. $output = '';
  1555. while ($position < $length && ($pos = strpos($string, '(', $position)) !== false)
  1556. {
  1557. $output .= substr($string, $position, $pos - $position);
  1558. $position = $pos + 1;
  1559. if ($string[$pos - 1] !== '\\')
  1560. {
  1561. $depth++;
  1562. while ($depth && $position < $length)
  1563. {
  1564. $position += strcspn($string, '()', $position);
  1565. if ($string[$position - 1] === '\\')
  1566. {
  1567. $position++;
  1568. continue;
  1569. }
  1570. elseif (isset($string[$position]))
  1571. {
  1572. switch ($string[$position])
  1573. {
  1574. case '(':
  1575. $depth++;
  1576. break;
  1577. case ')':
  1578. $depth--;
  1579. break;
  1580. }
  1581. $position++;
  1582. }
  1583. else
  1584. {
  1585. break;
  1586. }
  1587. }
  1588. }
  1589. else
  1590. {
  1591. $output .= '(';
  1592. }
  1593. }
  1594. $output .= substr($string, $position);
  1595. return $output;
  1596. }
  1597. public static function parse_mime($mime)
  1598. {
  1599. if (($pos = strpos($mime, ';')) === false)
  1600. {
  1601. return trim($mime);
  1602. }
  1603. else
  1604. {
  1605. return trim(substr($mime, 0, $pos));
  1606. }
  1607. }
  1608. public static function htmlspecialchars_decode($string, $quote_style)
  1609. {
  1610. if (function_exists('htmlspecialchars_decode'))
  1611. {
  1612. return htmlspecialchars_decode($string, $quote_style);
  1613. }
  1614. else
  1615. {
  1616. return strtr($string, array_flip(get_html_translation_table(HTML_SPECIALCHARS, $quote_style)));
  1617. }
  1618. }
  1619. public static function atom_03_construct_type($attribs)
  1620. {
  1621. if (isset($attribs['']['mode']) && strtolower(trim($attribs['']['mode']) === 'base64'))
  1622. {
  1623. $mode = SIMPLEPIE_CONSTRUCT_BASE64;
  1624. }
  1625. else
  1626. {
  1627. $mode = SIMPLEPIE_CONSTRUCT_NONE;
  1628. }
  1629. if (isset($attribs['']['type']))
  1630. {
  1631. switch (strtolower(trim($attribs['']['type'])))
  1632. {
  1633. case 'text':
  1634. case 'text/plain':
  1635. return SIMPLEPIE_CONSTRUCT_TEXT | $mode;
  1636. case 'html':
  1637. case 'text/html':
  1638. return SIMPLEPIE_CONSTRUCT_HTML | $mode;
  1639. case 'xhtml':
  1640. case 'application/xhtml+xml':
  1641. return SIMPLEPIE_CONSTRUCT_XHTML | $mode;
  1642. default:
  1643. return SIMPLEPIE_CONSTRUCT_NONE | $mode;
  1644. }
  1645. }
  1646. else
  1647. {
  1648. return SIMPLEPIE_CONSTRUCT_TEXT | $mode;
  1649. }
  1650. }
  1651. public static function atom_10_construct_type($attribs)
  1652. {
  1653. if (isset($attribs['']['type']))
  1654. {
  1655. switch (strtolower(trim($attribs['']['type'])))
  1656. {
  1657. case 'text':
  1658. return SIMPLEPIE_CONSTRUCT_TEXT;
  1659. case 'html':
  1660. return SIMPLEPIE_CONSTRUCT_HTML;
  1661. case 'xhtml':
  1662. return SIMPLEPIE_CONSTRUCT_XHTML;
  1663. default:
  1664. return SIMPLEPIE_CONSTRUCT_NONE;
  1665. }
  1666. }
  1667. return SIMPLEPIE_CONSTRUCT_TEXT;
  1668. }
  1669. public static function atom_10_content_construct_type($attribs)
  1670. {
  1671. if (isset($attribs['']['type']))
  1672. {
  1673. $type = strtolower(trim($attribs['']['type']));
  1674. switch ($type)
  1675. {
  1676. case 'text':
  1677. return SIMPLEPIE_CONSTRUCT_TEXT;
  1678. case 'html':
  1679. return SIMPLEPIE_CONSTRUCT_HTML;
  1680. case 'xhtml':
  1681. return SIMPLEPIE_CONSTRUCT_XHTML;
  1682. }
  1683. if (in_array(substr($type, -4), array('+xml', '/xml')) || substr($type, 0, 5) === 'text/')
  1684. {
  1685. return SIMPLEPIE_CONSTRUCT_NONE;
  1686. }
  1687. else
  1688. {
  1689. return SIMPLEPIE_CONSTRUCT_BASE64;
  1690. }
  1691. }
  1692. else
  1693. {
  1694. return SIMPLEPIE_CONSTRUCT_TEXT;
  1695. }
  1696. }
  1697. public static function is_isegment_nz_nc($string)
  1698. {
  1699. return (bool) preg_match('/^([A-Za-z0-9\-._~\x{A0}-\x{D7FF}\x{F900}-\x{FDCF}\x{FDF0}-\x{FFEF}\x{10000}-\x{1FFFD}\x{20000}-\x{2FFFD}\x{30000}-\x{3FFFD}\x{40000}-\x{4FFFD}\x{50000}-\x{5FFFD}\x{60000}-\x{6FFFD}\x{70000}-\x{7FFFD}\x{80000}-\x{8FFFD}\x{90000}-\x{9FFFD}\x{A0000}-\x{AFFFD}\x{B0000}-\x{BFFFD}\x{C0000}-\x{CFFFD}\x{D0000}-\x{DFFFD}\x{E1000}-\x{EFFFD}!$&\'()*+,;=@]|(%[0-9ABCDEF]{2}))+$/u', $string);
  1700. }
  1701. public static function space_seperated_tokens($string)
  1702. {
  1703. $space_characters = "\x20\x09\x0A\x0B\x0C\x0D";
  1704. $string_length = strlen($string);
  1705. $position = strspn($string, $space_characters);
  1706. $tokens = array();
  1707. while ($position < $string_length)
  1708. {
  1709. $len = strcspn($string, $space_characters, $position);
  1710. $tokens[] = substr($string, $position, $len);
  1711. $position += $len;
  1712. $position += strspn($string, $space_characters, $position);
  1713. }
  1714. return $tokens;
  1715. }
  1716. public static function array_unique($array)
  1717. {
  1718. if (version_compare(PHP_VERSION, '5.2', '>='))
  1719. {
  1720. return array_unique($array);
  1721. }
  1722. else
  1723. {
  1724. $array = (array) $array;
  1725. $new_array = array();
  1726. $new_array_strings = array();
  1727. foreach ($array as $key => $value)
  1728. {
  1729. if (is_object($value))
  1730. {
  1731. if (method_exists($value, '__toString'))
  1732. {
  1733. $cmp = $value->__toString();
  1734. }
  1735. else
  1736. {
  1737. trigger_error('Object of class ' . get_class($value) . ' could not be converted to string', E_USER_ERROR);
  1738. }
  1739. }
  1740. elseif (is_array($value))
  1741. {
  1742. $cmp = (string) reset($value);
  1743. }
  1744. else
  1745. {
  1746. $cmp = (string) $value;
  1747. }
  1748. if (!in_array($cmp, $new_array_strings))
  1749. {
  1750. $new_array[$key] = $value;
  1751. $new_array_strings[] = $cmp;
  1752. }
  1753. }
  1754. return $new_array;
  1755. }
  1756. }
  1757. /**
  1758. * Converts a unicode codepoint to a UTF-8 character
  1759. *
  1760. * @static
  1761. * @param int $codepoint Unicode codepoint
  1762. * @return string UTF-8 character
  1763. */
  1764. public static function codepoint_to_utf8($codepoint)
  1765. {
  1766. $codepoint = (int) $codepoint;
  1767. if ($codepoint < 0)
  1768. {
  1769. return false;
  1770. }
  1771. else if ($codepoint <= 0x7f)
  1772. {
  1773. return chr($codepoint);
  1774. }
  1775. else if ($codepoint <= 0x7ff)
  1776. {
  1777. return chr(0xc0 | ($codepoint >> 6)) . chr(0x80 | ($codepoint & 0x3f));
  1778. }
  1779. else if ($codepoint <= 0xffff)
  1780. {
  1781. return chr(0xe0 | ($codepoint >> 12)) . chr(0x80 | (($codepoint >> 6) & 0x3f)) . chr(0x80 | ($codepoint & 0x3f));
  1782. }
  1783. else if ($codepoint <= 0x10ffff)
  1784. {
  1785. return chr(0xf0 | ($codepoint >> 18)) . chr(0x80 | (($codepoint >> 12) & 0x3f)) . chr(0x80 | (($codepoint >> 6) & 0x3f)) . chr(0x80 | ($codepoint & 0x3f));
  1786. }
  1787. else
  1788. {
  1789. // U+FFFD REPLACEMENT CHARACTER
  1790. return "\xEF\xBF\xBD";
  1791. }
  1792. }
  1793. /**
  1794. * Similar to parse_str()
  1795. *
  1796. * Returns an associative array of name/value pairs, where the value is an
  1797. * array of values that have used the same name
  1798. *
  1799. * @static
  1800. * @param string $str The input string.
  1801. * @return array
  1802. */
  1803. public static function parse_str($str)
  1804. {
  1805. $return = array();
  1806. $str = explode('&', $str);
  1807. foreach ($str as $section)
  1808. {
  1809. if (strpos($section, '=') !== false)
  1810. {
  1811. list($name, $value) = explode('=', $section, 2);
  1812. $return[urldecode($name)][] = urldecode($value);
  1813. }
  1814. else
  1815. {
  1816. $return[urldecode($section)][] = null;
  1817. }
  1818. }
  1819. return $return;
  1820. }
  1821. /**
  1822. * Detect XML encoding, as per XML 1.0 Appendix F.1
  1823. *
  1824. * @todo Add support for EBCDIC
  1825. * @param string $data XML data
  1826. * @return array Possible encodings
  1827. */
  1828. public static function xml_encoding($data)
  1829. {
  1830. // UTF-32 Big Endian BOM
  1831. if (substr($data, 0, 4) === "\x00\x00\xFE\xFF")
  1832. {
  1833. $encoding[] = 'UTF-32BE';
  1834. }
  1835. // UTF-32 Little Endian BOM
  1836. elseif (substr($data, 0, 4) === "\xFF\xFE\x00\x00")
  1837. {
  1838. $encoding[] = 'UTF-32LE';
  1839. }
  1840. // UTF-16 Big Endian BOM
  1841. elseif (substr($data, 0, 2) === "\xFE\xFF")
  1842. {
  1843. $encoding[] = 'UTF-16BE';
  1844. }
  1845. // UTF-16 Little Endian BOM
  1846. elseif (substr($data, 0, 2) === "\xFF\xFE")
  1847. {
  1848. $encoding[] = 'UTF-16LE';
  1849. }
  1850. // UTF-8 BOM
  1851. elseif (substr($data, 0, 3) === "\xEF\xBB\xBF")
  1852. {
  1853. $encoding[] = 'UTF-8';
  1854. }
  1855. // UTF-32 Big Endian Without BOM
  1856. elseif (substr($data, 0, 20) === "\x00\x00\x00\x3C\x00\x00\x00\x3F\x00\x00\x00\x78\x00\x00\x00\x6D\x00\x00\x00\x6C")
  1857. {
  1858. if ($pos = strpos($data, "\x00\x00\x00\x3F\x00\x00\x00\x3E"))
  1859. {
  1860. $parser = new SimplePie_XML_Declaration_Parser(SimplePie_Misc::change_encoding(substr($data, 20, $pos - 20), 'UTF-32BE', 'UTF-8'));
  1861. if ($parser->parse())
  1862. {
  1863. $encoding[] = $parser->encoding;
  1864. }
  1865. }
  1866. $encoding[] = 'UTF-32BE';
  1867. }
  1868. // UTF-32 Little Endian Without BOM
  1869. elseif (substr($data, 0, 20) === "\x3C\x00\x00\x00\x3F\x00\x00\x00\x78\x00\x00\x00\x6D\x00\x00\x00\x6C\x00\x00\x00")
  1870. {
  1871. if ($pos = strpos($data, "\x3F\x00\x00\x00\x3E\x00\x00\x00"))
  1872. {
  1873. $parser = new SimplePie_XML_Declaration_Parser(SimplePie_Misc::change_encoding(substr($data, 20, $pos - 20), 'UTF-32LE', 'UTF-8'));
  1874. if ($parser->parse())
  1875. {
  1876. $encoding[] = $parser->encoding;
  1877. }
  1878. }
  1879. $encoding[] = 'UTF-32LE';
  1880. }
  1881. // UTF-16 Big Endian Without BOM
  1882. elseif (substr($data, 0, 10) === "\x00\x3C\x00\x3F\x00\x78\x00\x6D\x00\x6C")
  1883. {
  1884. if ($pos = strpos($data, "\x00\x3F\x00\x3E"))
  1885. {
  1886. $parser = new SimplePie_XML_Declaration_Parser(SimplePie_Misc::change_encoding(substr($data, 20, $pos - 10), 'UTF-16BE', 'UTF-8'));
  1887. if ($parser->parse())