annotate vendor/masterminds/html5/src/HTML5/Parser/CharacterReference.php @ 5:12f9dff5fda9 tip

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