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