File: _polyfills.php

package info (click to toggle)
haxe 1%3A4.1.5-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 40,556 kB
  • sloc: ml: 125,171; ansic: 2,408; makefile: 436; java: 362; cs: 323; cpp: 318; python: 316; sh: 75; objc: 64; php: 39; xml: 30; javascript: 11
file content (53 lines) | stat: -rw-r--r-- 1,749 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<?php
/**
 * Polyfills for some functions, which are required by Haxe-generated code, but not available in PHP 7.0.
 * No Haxe-generated code is available at this point.
 * No code should be executed from this file.
 * Symbols declarations are the only code allowed here.
 */
namespace { //Namespace declaration is required because this file is included under non-root namespace.

	/**
	 * @see http://php.net/manual/en/function.mb-chr.php
	 */
	if(!function_exists('mb_chr')) {
		function mb_chr($code, $encoding = null) {
			if($encoding && $encoding !== 'UTF-8') {
				throw new Exception("$encoding is not supported in mb_chr() polyfill.");
			}
			if (0x80 > $code %= 0x200000) {
				$s = chr($code);
			} elseif (0x800 > $code) {
				$s = chr(0xC0 | $code >> 6) . chr(0x80 | $code & 0x3F);
			} elseif (0x10000 > $code) {
				$s = chr(0xE0 | $code >> 12) . chr(0x80 | $code >> 6 & 0x3F) . chr(0x80 | $code & 0x3F);
			} else {
				$s = chr(0xF0 | $code >> 18) . chr(0x80 | $code >> 12 & 0x3F) . chr(0x80 | $code >> 6 & 0x3F) . chr(0x80 | $code & 0x3F);
			}
			return $s;
		}
	}

	/**
	 * @see http://php.net/manual/en/function.mb-ord.php
	 */
	if(!function_exists('mb_ord')) {
		function mb_ord($s, $encoding = null) {
			if($encoding && $encoding !== 'UTF-8') {
				throw new Exception("$encoding is not supported in mb_ord() polyfill.");
			}
			$code = ($s = unpack('C*', substr($s, 0, 4))) ? $s[1] : 0;
			if (0xF0 <= $code) {
				return (($code - 0xF0) << 18) + (($s[2] - 0x80) << 12) + (($s[3] - 0x80) << 6) + $s[4] - 0x80;
			}
			if (0xE0 <= $code) {
				return (($code - 0xE0) << 12) + (($s[2] - 0x80) << 6) + $s[3] - 0x80;
			}
			if (0xC0 <= $code) {
				return (($code - 0xC0) << 6) + $s[2] - 0x80;
			}
			return $code;
		}
	}

}