Mercurial > hg > isophonics-drupal-site
annotate vendor/masterminds/html5/src/HTML5/Parser/CharacterReference.php @ 19:fa3358dc1485 tip
Add ndrum files
author | Chris Cannam |
---|---|
date | Wed, 28 Aug 2019 13:14:47 +0100 |
parents | 129ea1e6d783 |
children |
rev | line source |
---|---|
Chris@0 | 1 <?php |
Chris@17 | 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@17 | 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@17 | 18 0xFFFF, |
Chris@0 | 19 ); |
Chris@0 | 20 |
Chris@0 | 21 /** |
Chris@17 | 22 * Given a name (e.g. 'amp'), lookup the UTF-8 character ('&'). |
Chris@0 | 23 * |
Chris@17 | 24 * @param string $name The name to look up. |
Chris@17 | 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@17 | 35 * Given a decimal number, return the UTF-8 character. |
Chris@0 | 36 * |
Chris@17 | 37 * @param $int |
Chris@17 | 38 * |
Chris@17 | 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@17 | 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@17 | 52 * |
Chris@17 | 53 * @param $hexdec |
Chris@17 | 54 * |
Chris@17 | 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 } |