You are here

public static function Unicode::isSimple in Express 8

Determines if a string of text is considered "simple".

Parameters

string $string: The string of text to check "simple" criteria on.

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.

array|FALSE $allowed_tags: An array of allowed tag elements. Set explicitly to FALSE to disable this criteria.

bool $html: A variable, passed by reference, that indicates whether or not the string contains HTML.

Return value

bool Returns TRUE if the $string is considered "simple", FALSE otherwise.

2 calls to Unicode::isSimple()
Element::smartDescription in themes/contrib/bootstrap/src/Utility/Element.php
Converts an element description into a tooltip based on certain criteria.
_bootstrap_is_simple_string in themes/contrib/bootstrap/deprecated.php
Determines if a string of text is considered "simple".

File

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

Class

Unicode
Extends \Drupal\Component\Utility\Unicode.

Namespace

Drupal\bootstrap\Utility

Code

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];
}