You are here

class Unicode in Express 8

Extends \Drupal\Component\Utility\Unicode.

Hierarchy

  • class \Drupal\Component\Utility\Unicode
    • class \Drupal\bootstrap\Utility\Unicode

Expanded class hierarchy of Unicode

4 files declare their use of Unicode
Bootstrap.php in themes/contrib/bootstrap/src/Bootstrap.php
Contains \Drupal\bootstrap\Bootstrap.
BootstrapDropdown.php in themes/contrib/bootstrap/src/Plugin/Preprocess/BootstrapDropdown.php
Contains \Drupal\bootstrap\Plugin\Preprocess\BootstrapDropdown.
deprecated.php in themes/contrib/bootstrap/deprecated.php
This contains deprecated functions that will be removed in a future release.
ThemeSuggestions.php in themes/contrib/bootstrap/src/Plugin/Alter/ThemeSuggestions.php
Contains \Drupal\bootstrap\Plugin\Alter\ThemeSuggestions.

File

themes/contrib/bootstrap/src/Utility/Unicode.php, line 17
Contains \Drupal\bootstrap\Utility\Unicode.

Namespace

Drupal\bootstrap\Utility
View source
class Unicode extends \Drupal\Component\Utility\Unicode {

  /**
   * Extracts the hook name from a function name.
   *
   * @param string $string
   *   The function name to extract the hook name from.
   * @param string $suffix
   *   A suffix hook ending (like "alter") to also remove.
   * @param string $prefix
   *   A prefix hook beginning (like "form") to also remove.
   *
   * @return string
   *   The extracted hook name.
   */
  public static function extractHook($string, $suffix = NULL, $prefix = NULL) {
    $regex = '^(' . implode('|', array_keys(Bootstrap::getTheme()
      ->getAncestry())) . ')';
    $regex .= $prefix ? '_' . $prefix : '';
    $regex .= $suffix ? '_|_' . $suffix . '$' : '';
    return preg_replace("/{$regex}/", '', $string);
  }

  /**
   * Converts a callback to a string representation.
   *
   * @param array|string $callback
   *   The callback to convert.
   * @param bool $array
   *   Flag determining whether or not to convert the callback to an array.
   *
   * @return string
   *   The converted callback as a string or an array if $array is specified.
   *
   * @see \Drupal\bootstrap\Bootstrap::addCallback()
   */
  public static function convertCallback($callback, $array = FALSE) {
    if (is_array($callback)) {
      if (is_object($callback[0])) {
        $callback[0] = get_class($callback[0]);
      }
      $callback = implode('::', $callback);
    }
    if ($callback[0] === '\\') {
      $callback = self::substr($callback, 1);
    }
    if ($array && self::strpos($callback, '::') !== FALSE) {
      $callback = explode('::', $callback);
    }
    return $callback;
  }

  /**
   * Determines if a string of text is considered "simple".
   *
   * @param string $string
   *   The string of text to check "simple" criteria on.
   * @param int|FALSE $length
   *   The length of characters used to determine whether or not $string is
   *   considered "simple". Set explicitly to FALSE to disable this criteria.
   * @param array|FALSE $allowed_tags
   *   An array of allowed tag elements. Set explicitly to FALSE to disable this
   *   criteria.
   * @param bool $html
   *   A variable, passed by reference, that indicates whether or not the
   *   string contains HTML.
   *
   * @return bool
   *   Returns TRUE if the $string is considered "simple", FALSE otherwise.
   */
  public static function isSimple($string, $length = 250, $allowed_tags = NULL, &$html = FALSE) {

    // Typecast to a string (if an object).
    $string_clone = (string) $string;

    // Use the advanced drupal_static() pattern.
    static $drupal_static_fast;
    if (!isset($drupal_static_fast)) {
      $drupal_static_fast['strings'] =& drupal_static(__METHOD__);
    }
    $strings =& $drupal_static_fast['strings'];
    if (!isset($strings[$string_clone])) {
      $plain_string = strip_tags($string_clone);
      $simple = TRUE;
      if ($allowed_tags !== FALSE) {
        $filtered_string = Xss::filter($string_clone, $allowed_tags);
        $html = $filtered_string !== $plain_string;
        $simple = $simple && $string_clone === $filtered_string;
      }
      if ($length !== FALSE) {
        $simple = $simple && strlen($plain_string) <= intval($length);
      }
      $strings[$string_clone] = $simple;
    }
    return $strings[$string_clone];
  }

}

Members

Namesort descending Modifiers Type Description Overrides
Unicode::caseFlip Deprecated public static function Flip U+C0-U+DE to U+E0-U+FD and back. Can be used as preg_replace callback.
Unicode::check public static function Checks for Unicode support in PHP and sets the proper settings if possible.
Unicode::convertCallback public static function Converts a callback to a string representation.
Unicode::convertToUtf8 public static function Converts data to UTF-8.
Unicode::encodingFromBOM public static function Decodes UTF byte-order mark (BOM) into the encoding's name.
Unicode::extractHook public static function Extracts the hook name from a function name.
Unicode::getStatus public static function Gets the current status of unicode/multibyte support on this environment.
Unicode::isSimple public static function Determines if a string of text is considered "simple".
Unicode::lcfirst public static function Converts the first character of a UTF-8 string to lowercase.
Unicode::mimeHeaderDecode public static function Decodes MIME/HTTP encoded header values.
Unicode::mimeHeaderEncode public static function Encodes MIME/HTTP headers that contain incorrectly encoded characters.
Unicode::PREG_CLASS_WORD_BOUNDARY constant Matches Unicode characters that are word boundaries.
Unicode::setStatus Deprecated public static function Sets the value for multibyte support status for the current environment.
Unicode::STATUS_ERROR constant Indicates an error during check for PHP unicode support.
Unicode::STATUS_MULTIBYTE constant Indicates that full unicode support with the PHP mbstring extension is being used.
Unicode::STATUS_SINGLEBYTE constant Indicates that standard PHP (emulated) unicode support is being used.
Unicode::strcasecmp public static function Compares UTF-8-encoded strings in a binary safe case-insensitive manner.
Unicode::strlen Deprecated public static function Counts the number of characters in a UTF-8 string.
Unicode::strpos Deprecated public static function Finds the position of the first occurrence of a string in another string.
Unicode::strtolower Deprecated public static function Converts a UTF-8 string to lowercase.
Unicode::strtoupper Deprecated public static function Converts a UTF-8 string to uppercase.
Unicode::substr Deprecated public static function Cuts off a piece of a string based on character indices and counts.
Unicode::truncate public static function Truncates a UTF-8-encoded string safely to a number of characters.
Unicode::truncateBytes public static function Truncates a UTF-8-encoded string safely to a number of bytes.
Unicode::ucfirst public static function Capitalizes the first character of a UTF-8 string.
Unicode::ucwords public static function Capitalizes the first character of each word in a UTF-8 string.
Unicode::validateUtf8 public static function Checks whether a string is valid UTF-8.