Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. Xml.php

class Xml

Same name in this branch
  1. 11.1.x vendor/phpunit/phpunit/src/TextUI/Configuration/Xml/CodeCoverage/Report/Xml.php \PHPUnit\TextUI\XmlConfiguration\CodeCoverage\Report\Xml
  2. 11.1.x vendor/squizlabs/php_codesniffer/src/Reports/Xml.php \PHP_CodeSniffer\Reports\Xml

@no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit

@internal This class is not covered by the backward compatibility promise for PHPUnit

Hierarchy

  • class \PHPUnit\Util\Xml

Expanded class hierarchy of Xml

1 file declares its use of Xml
JunitXmlLogger.php in vendor/phpunit/phpunit/src/Logging/JUnit/JunitXmlLogger.php
20 string references to 'Xml'
AbstractObjectNormalizer::validateAndDenormalize in vendor/symfony/serializer/Normalizer/AbstractObjectNormalizer.php
Validates the submitted data and denormalizes it.
AbstractObjectNormalizer::validateAndDenormalizeLegacy in vendor/symfony/serializer/Normalizer/AbstractObjectNormalizer.php
Validates the submitted data and denormalizes it.
bootstrap.php in vendor/symfony/polyfill-iconv/bootstrap.php
bootstrap80.php in vendor/symfony/polyfill-iconv/bootstrap80.php
CodeBlock::defaultConfiguration in core/modules/ckeditor5/src/Plugin/CKEditor5Plugin/CodeBlock.php

... See full list

File

vendor/phpunit/phpunit/src/Util/Xml/Xml.php, line 24

Namespace

PHPUnit\Util
View source
final class Xml {
    
    /**
     * Escapes a string for the use in XML documents.
     *
     * Any Unicode character is allowed, excluding the surrogate blocks, FFFE,
     * and FFFF (not even as character reference).
     *
     * @see https://www.w3.org/TR/xml/#charsets
     */
    public static function prepareString(string $string) : string {
        return preg_replace('/[\\x00-\\x08\\x0b\\x0c\\x0e-\\x1f\\x7f]/', '', htmlspecialchars(self::convertToUtf8($string), ENT_QUOTES));
    }
    private static function convertToUtf8(string $string) : string {
        if (!self::isUtf8($string)) {
            $string = mb_convert_encoding($string, 'UTF-8');
        }
        return $string;
    }
    private static function isUtf8(string $string) : bool {
        $length = strlen($string);
        for ($i = 0; $i < $length; $i++) {
            if (ord($string[$i]) < 0x80) {
                $n = 0;
            }
            elseif ((ord($string[$i]) & 0xe0) === 0xc0) {
                $n = 1;
            }
            elseif ((ord($string[$i]) & 0xf0) === 0xe0) {
                $n = 2;
            }
            elseif ((ord($string[$i]) & 0xf0) === 0xf0) {
                $n = 3;
            }
            else {
                return false;
            }
            for ($j = 0; $j < $n; $j++) {
                if (++$i === $length || (ord($string[$i]) & 0xc0) !== 0x80) {
                    return false;
                }
            }
        }
        return true;
    }

}

Members

Title Sort descending Modifiers Object type Summary
Xml::convertToUtf8 private static function
Xml::isUtf8 private static function
Xml::prepareString public static function Escapes a string for the use in XML documents.

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal