/vendor/PowerTools/HTML5/Parser/CharacterReference.php
https://github.com/PHPPowertools/DOM-Query · PHP · 142 lines · 20 code · 8 blank · 114 comment · 0 complexity · 4334194123dff8ea8457733b6c49b2a6 MD5 · raw file
- <?php
- /* !
- * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- *
- * PACKAGE : PHP POWERTOOLS
- *
- * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- *
- * COMPONENT : HTML5
- *
- * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- *
- * DESCRIPTION :
- *
- * A library for easy HTML5 parsing
- *
- * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- *
- * REQUIREMENTS :
- *
- * PHP version 5.4+
- * PSR-0 compatibility
- *
- * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- *
- * CREDITS :
- *
- * This library started out as a fork of Masterminds/html5-php
- *
- * Contributors of that Masterminds/html5-php :
- * ---------------------------------------------
- * Matt Butcher [technosophos]
- * Matt Farina [mattfarina]
- * Asmir Mustafic [goetas]
- * Edward Z. Yang [ezyang]
- * Geoffrey Sneddon [gsnedders]
- * Kukhar Vasily [ngreduce]
- * Rune Christensen [MrElectronic]
- * Mišo Belica [miso-belica]
- * Asmir Mustafic [goetas]
- * KITAITI Makoto [KitaitiMakoto]
- * Jacob Floyd [cognifloyd]
- *
- * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- *
- * LICENSE :
- *
- * LICENSE: Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
- * THE SOFTWARE.
- *
- * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- *
- * @category HTML5 parsing
- * @package HTML5
- * @author John Slegers
- * @copyright MMXIV John Slegers
- * @license http://www.opensource.org/licenses/mit-license.html MIT License
- * @link https://github.com/jslegers
- *
- * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
- */
- namespace PowerTools;
- /**
- * Manage entity references.
- *
- * This is a simple resolver for HTML5 character reference entitites.
- * See HTML5_Entities for the list of supported entities.
- */
- class HTML5_Parser_CharacterReference {
- protected static $numeric_mask = array(
- 0x0,
- 0x2FFFF,
- 0,
- 0xFFFF
- );
- /**
- * Given a name (e.g.
- * 'amp'), lookup the UTF-8 character ('&')
- *
- * @param string $name
- * The name to look up.
- * @return string The character sequence. In UTF-8 this may be more than one byte.
- */
- public static function lookupName($name) {
- // Do we really want to return NULL here? or FFFD
- return isset(HTML5_Entities::$byName[$name]) ? HTML5_Entities::$byName[$name] : null;
- }
- /**
- * Given a Unicode codepoint, return the UTF-8 character.
- *
- * (NOT USED ANYWHERE)
- */
- /*
- * public static function lookupCode($codePoint) { return 'POINT'; }
- */
- /**
- * Given a decimal number, return the UTF-8 character.
- */
- public static function lookupDecimal($int) {
- $entity = '&#' . $int . ';';
- // UNTESTED: This may fail on some planes. Couldn't find full documentation
- // on the value of the mask array.
- return mb_decode_numericentity($entity, static::$numeric_mask, 'utf-8');
- }
- /**
- * Given a hexidecimal number, return the UTF-8 character.
- */
- public static function lookupHex($hexdec) {
- return static::lookupDecimal(hexdec($hexdec));
- }
- }