comparison vendor/masterminds/html5/src/HTML5/Parser/CharacterReference.php @ 17:129ea1e6d783

Update, including to Drupal core 8.6.10
author Chris Cannam
date Thu, 28 Feb 2019 13:21:36 +0000
parents 4c8ae668cc8c
children
comparison
equal deleted inserted replaced
16:c2387f117808 17:129ea1e6d783
1 <?php 1 <?php
2
2 namespace Masterminds\HTML5\Parser; 3 namespace Masterminds\HTML5\Parser;
3 4
4 use Masterminds\HTML5\Entities; 5 use Masterminds\HTML5\Entities;
5 6
6 /** 7 /**
7 * Manage entity references. 8 * Manage entity references.
8 * 9 *
9 * This is a simple resolver for HTML5 character reference entitites. 10 * This is a simple resolver for HTML5 character reference entitites. See Entities for the list of supported entities.
10 * See \Masterminds\HTML5\Entities for the list of supported entities.
11 */ 11 */
12 class CharacterReference 12 class CharacterReference
13 { 13 {
14
15 protected static $numeric_mask = array( 14 protected static $numeric_mask = array(
16 0x0, 15 0x0,
17 0x2FFFF, 16 0x2FFFF,
18 0, 17 0,
19 0xFFFF 18 0xFFFF,
20 ); 19 );
21 20
22 /** 21 /**
23 * Given a name (e.g. 22 * Given a name (e.g. 'amp'), lookup the UTF-8 character ('&').
24 * 'amp'), lookup the UTF-8 character ('&')
25 * 23 *
26 * @param string $name 24 * @param string $name The name to look up.
27 * The name to look up. 25 *
28 * @return string The character sequence. In UTF-8 this may be more than one byte. 26 * @return string The character sequence. In UTF-8 this may be more than one byte.
29 */ 27 */
30 public static function lookupName($name) 28 public static function lookupName($name)
31 { 29 {
32 // Do we really want to return NULL here? or FFFD 30 // Do we really want to return NULL here? or FFFD
33 return isset(Entities::$byName[$name]) ? Entities::$byName[$name] : null; 31 return isset(Entities::$byName[$name]) ? Entities::$byName[$name] : null;
34 } 32 }
35 33
36 /** 34 /**
37 * Given a Unicode codepoint, return the UTF-8 character. 35 * Given a decimal number, return the UTF-8 character.
38 * 36 *
39 * (NOT USED ANYWHERE) 37 * @param $int
40 */ 38 *
41 /* 39 * @return false|string|string[]|null
42 * public static function lookupCode($codePoint) { return 'POINT'; }
43 */
44
45 /**
46 * Given a decimal number, return the UTF-8 character.
47 */ 40 */
48 public static function lookupDecimal($int) 41 public static function lookupDecimal($int)
49 { 42 {
50 $entity = '&#' . $int . ';'; 43 $entity = '&#' . $int . ';';
44
51 // UNTESTED: This may fail on some planes. Couldn't find full documentation 45 // UNTESTED: This may fail on some planes. Couldn't find full documentation
52 // on the value of the mask array. 46 // on the value of the mask array.
53 return mb_decode_numericentity($entity, static::$numeric_mask, 'utf-8'); 47 return mb_decode_numericentity($entity, static::$numeric_mask, 'utf-8');
54 } 48 }
55 49
56 /** 50 /**
57 * Given a hexidecimal number, return the UTF-8 character. 51 * Given a hexidecimal number, return the UTF-8 character.
52 *
53 * @param $hexdec
54 *
55 * @return false|string|string[]|null
58 */ 56 */
59 public static function lookupHex($hexdec) 57 public static function lookupHex($hexdec)
60 { 58 {
61 return static::lookupDecimal(hexdec($hexdec)); 59 return static::lookupDecimal(hexdec($hexdec));
62 } 60 }