diff --git a/core/lib/Drupal/Core/Mail/MailFormatHelper.php b/core/lib/Drupal/Core/Mail/MailFormatHelper.php index 2d8fe99a8a3beef3e070c7b31150ef24bfaaa31a..c17da77f7bfcc981515a560dee5cbc9a206f6748 100644 --- a/core/lib/Drupal/Core/Mail/MailFormatHelper.php +++ b/core/lib/Drupal/Core/Mail/MailFormatHelper.php @@ -9,6 +9,7 @@ use Drupal\Component\Utility\Html; use Drupal\Component\Utility\String; +use Drupal\Component\Utility\Unicode; use Drupal\Component\Utility\Xss; use Drupal\Core\Site\Settings; @@ -264,7 +265,7 @@ public static function htmlToText($string, $allowed_tags = NULL) { // Convert inline HTML text to plain text; not removing line-breaks or // white-space, since that breaks newlines when sanitizing plain-text. $value = trim(String::decodeEntities($value)); - if (drupal_strlen($value)) { + if (Unicode::strlen($value)) { $chunk = $value; } } diff --git a/core/lib/Drupal/Core/TypedData/Plugin/DataType/ItemList.php b/core/lib/Drupal/Core/TypedData/Plugin/DataType/ItemList.php index 54f36484504edeb21325d5bb182702c53cbf5728..cdb724686b387a6dec0394d95ca17e7eeed6e4eb 100644 --- a/core/lib/Drupal/Core/TypedData/Plugin/DataType/ItemList.php +++ b/core/lib/Drupal/Core/TypedData/Plugin/DataType/ItemList.php @@ -99,7 +99,7 @@ public function getString() { $strings[] = $item->getString(); } // Remove any empty strings resulting from empty items. - return implode(', ', array_filter($strings, 'drupal_strlen')); + return implode(', ', array_filter($strings, '\Drupal\Component\Utility\Unicode::strlen')); } } diff --git a/core/lib/Drupal/Core/TypedData/Plugin/DataType/Map.php b/core/lib/Drupal/Core/TypedData/Plugin/DataType/Map.php index bc699ccb75f9e604e71cda1ef5e8232350f7bd21..abb1c9c39b89d1a441502106af1eef2dd931c682 100644 --- a/core/lib/Drupal/Core/TypedData/Plugin/DataType/Map.php +++ b/core/lib/Drupal/Core/TypedData/Plugin/DataType/Map.php @@ -115,7 +115,7 @@ public function getString() { $strings[] = $property->getString(); } // Remove any empty strings resulting from empty items. - return implode(', ', array_filter($strings, 'drupal_strlen')); + return implode(', ', array_filter($strings, '\Drupal\Component\Utility\Unicode::strlen')); } /** diff --git a/core/modules/filter/filter.module b/core/modules/filter/filter.module index 7af67322e9e4d25451eb81f11a8a83e65716e55c..a14d730ac80ad48e5f9437b923248af56661bb19 100644 --- a/core/modules/filter/filter.module +++ b/core/modules/filter/filter.module @@ -784,7 +784,7 @@ function _filter_html_escape($text) { function _filter_html_image_secure_process($text) { // Find the path (e.g. '/') to Drupal root. $base_path = base_path(); - $base_path_length = drupal_strlen($base_path); + $base_path_length = Unicode::strlen($base_path); // Find the directory on the server where index.php resides. $local_dir = DRUPAL_ROOT . '/'; diff --git a/core/modules/image/image.field.inc b/core/modules/image/image.field.inc index 4668e2600e39539c08280afefede12ca264a4f9c..3f44993c46fa3e82f7e8a59276c2d5ba58d7bb58 100644 --- a/core/modules/image/image.field.inc +++ b/core/modules/image/image.field.inc @@ -6,6 +6,7 @@ */ use Drupal\Component\Utility\NestedArray; +use Drupal\Component\Utility\Unicode; use Drupal\Core\Render\Element; /** @@ -64,7 +65,7 @@ function template_preprocess_image_formatter(&$variables) { $item = $variables['item']; // Do not output an empty 'title' attribute. - if (drupal_strlen($item->title) != 0) { + if (Unicode::strlen($item->title) != 0) { $variables['image']['#title'] = $item->title; } diff --git a/core/modules/menu_ui/src/Tests/MenuTest.php b/core/modules/menu_ui/src/Tests/MenuTest.php index c35d0d1caddba01931e74fc9a17fd7967dc58f91..1b09615e08c719057caaaf43ebb99984a1ccbac7 100644 --- a/core/modules/menu_ui/src/Tests/MenuTest.php +++ b/core/modules/menu_ui/src/Tests/MenuTest.php @@ -8,6 +8,7 @@ namespace Drupal\menu_ui\Tests; use Drupal\Component\Serialization\Json; +use Drupal\Component\Utility\Unicode; use Drupal\Core\Menu\MenuLinkInterface; use Drupal\menu_link_content\Entity\MenuLinkContent; use Drupal\system\Entity\Menu; @@ -175,7 +176,7 @@ function addCustomMenu() { $this->assertRaw(t('!name cannot be longer than %max characters but is currently %length characters long.', array( '!name' => t('Menu name'), '%max' => MENU_MAX_MENU_NAME_LENGTH_UI, - '%length' => drupal_strlen($menu_name), + '%length' => Unicode::strlen($menu_name), ))); // Change the menu_name so it no longer exceeds the maximum length. @@ -187,7 +188,7 @@ function addCustomMenu() { $this->assertNoRaw(t('!name cannot be longer than %max characters but is currently %length characters long.', array( '!name' => t('Menu name'), '%max' => MENU_MAX_MENU_NAME_LENGTH_UI, - '%length' => drupal_strlen($menu_name), + '%length' => Unicode::strlen($menu_name), ))); // Verify that the confirmation message is displayed. $this->assertRaw(t('Menu %label has been added.', array('%label' => $label))); diff --git a/core/modules/options/src/Plugin/Field/FieldType/ListStringItem.php b/core/modules/options/src/Plugin/Field/FieldType/ListStringItem.php index 37053c3434b9317934d6225e401e5b2d3b5c2a6b..d74049a54ea28c2054ccc8b35e366cbcd20ad1f0 100644 --- a/core/modules/options/src/Plugin/Field/FieldType/ListStringItem.php +++ b/core/modules/options/src/Plugin/Field/FieldType/ListStringItem.php @@ -7,6 +7,7 @@ namespace Drupal\options\Plugin\Field\FieldType; +use Drupal\Component\Utility\Unicode; use Drupal\Core\Field\FieldStorageDefinitionInterface; use Drupal\Core\TypedData\DataDefinition; @@ -68,7 +69,7 @@ protected function allowedValuesDescription() { * {@inheritdoc} */ protected static function validateAllowedValue($option) { - if (drupal_strlen($option) > 255) { + if (Unicode::strlen($option) > 255) { return t('Allowed values list: each key must be a string at most 255 characters long.'); } } diff --git a/core/modules/responsive_image/responsive_image.module b/core/modules/responsive_image/responsive_image.module index 79928157af1ef42c507ec85820fa7f2a1b171b02..bdb2a8320716994d3d4321846ac6dd30444006a3 100644 --- a/core/modules/responsive_image/responsive_image.module +++ b/core/modules/responsive_image/responsive_image.module @@ -6,6 +6,7 @@ */ use Drupal\Component\Utility\SafeMarkup; +use Drupal\Component\Utility\Unicode; use Drupal\Core\Routing\RouteMatchInterface; use \Drupal\Core\Template\Attribute; use Drupal\Core\Url; @@ -144,7 +145,7 @@ function theme_responsive_image_formatter($variables) { $responsive_image['#entity'] = $entity; } $responsive_image['#alt'] = $item->alt; - if (drupal_strlen($item->title) != 0) { + if (Unicode::strlen($item->title) != 0) { $responsive_image['#title'] = $item->title; } // @todo Add support for route names. diff --git a/core/modules/search/search.module b/core/modules/search/search.module index e780087b0618422f60093fcd347ed1b81c69ec10..1ebe99d153ff7c55635f8212a9ba7819c2a1398e 100644 --- a/core/modules/search/search.module +++ b/core/modules/search/search.module @@ -306,7 +306,7 @@ function search_simplify($text, $langcode = NULL) { function search_expand_cjk($matches) { $min = \Drupal::config('search.settings')->get('index.minimum_word_size'); $str = $matches[0]; - $length = drupal_strlen($str); + $length = Unicode::strlen($str); // If the text is shorter than the minimum word size, don't tokenize it. if ($length <= $min) { return ' ' . $str . ' '; @@ -453,7 +453,7 @@ function search_index($sid, $type, $text, $langcode) { // Add word to accumulator $accum .= $word . ' '; // Check wordlength - if (is_numeric($word) || drupal_strlen($word) >= $minimum_word_size) { + if (is_numeric($word) || Unicode::strlen($word) >= $minimum_word_size) { if (!isset($scored_words[$word])) { $scored_words[$word] = 0; } diff --git a/core/modules/search/src/SearchQuery.php b/core/modules/search/src/SearchQuery.php index b3e2cac5eab07b597b6324f7d597039ace91549d..21c271bfc50c488b64b553dbd6641926b5e61242 100644 --- a/core/modules/search/src/SearchQuery.php +++ b/core/modules/search/src/SearchQuery.php @@ -9,6 +9,7 @@ namespace Drupal\search; +use Drupal\Component\Utility\Unicode; use Drupal\Core\Database\Query\SelectExtender; use Drupal\Core\Database\StatementEmpty; @@ -367,7 +368,7 @@ protected function parseWord($word) { $split = explode(' ', $word); foreach ($split as $s) { $num = is_numeric($s); - if ($num || drupal_strlen($s) >= \Drupal::config('search.settings')->get('index.minimum_word_size')) { + if ($num || Unicode::strlen($s) >= \Drupal::config('search.settings')->get('index.minimum_word_size')) { if (!isset($this->words[$s])) { $this->words[$s] = $s; $num_new_scores++; diff --git a/core/modules/search/src/Tests/SearchSimplifyTest.php b/core/modules/search/src/Tests/SearchSimplifyTest.php index 848f7b7e84853bd7ba8adf6adc0d2b014e450c1d..d1c2774233dfa7878662a2fdb7db5dbcf188ac47 100644 --- a/core/modules/search/src/Tests/SearchSimplifyTest.php +++ b/core/modules/search/src/Tests/SearchSimplifyTest.php @@ -39,7 +39,7 @@ function testSearchSimplifyUnicode() { // Split this into 30-character chunks, so we don't run into limits // of truncation in search_simplify(). $start = 0; - while ($start < drupal_strlen($string)) { + while ($start < Unicode::strlen($string)) { $newstr = Unicode::substr($string, $start, 30); // Special case: leading zeros are removed from numeric strings, // and there's one string in this file that is numbers starting with @@ -54,7 +54,7 @@ function testSearchSimplifyUnicode() { } foreach ($strings as $key => $string) { $simplified = search_simplify($string); - $this->assertTrue(drupal_strlen($simplified) >= drupal_strlen($string), "Nothing is removed from string $key."); + $this->assertTrue(Unicode::strlen($simplified) >= Unicode::strlen($string), "Nothing is removed from string $key."); } // Test the low-numbered ASCII control characters separately. They are not diff --git a/core/modules/system/src/Tests/Mail/HtmlToTextTest.php b/core/modules/system/src/Tests/Mail/HtmlToTextTest.php index f26b49810d4a9ae516bf357f103574c7a7baaab6..57de914383ca0e7f0c071f9c30a0ffbcc9dbb3f1 100644 --- a/core/modules/system/src/Tests/Mail/HtmlToTextTest.php +++ b/core/modules/system/src/Tests/Mail/HtmlToTextTest.php @@ -352,7 +352,7 @@ public function testVeryLongLineWrap() { $maximum_line_length = 0; foreach (explode($eol, $output) as $line) { - // We must use strlen() rather than drupal_strlen() in order to count + // We must use strlen() rather than Unicode::strlen() in order to count // octets rather than characters. $maximum_line_length = max($maximum_line_length, strlen($line . $eol)); } diff --git a/core/modules/text/text.module b/core/modules/text/text.module index 0ea98e0e43499bd19e67b040b10288d888af9ea9..02140fe0a01a9ae693653e6d7fa90fbab0a19a37 100644 --- a/core/modules/text/text.module +++ b/core/modules/text/text.module @@ -91,7 +91,7 @@ function text_summary($text, $format = NULL, $size = NULL) { } // If we have a short body, the entire body is the summary. - if (drupal_strlen($text) <= $size) { + if (Unicode::strlen($text) <= $size) { return $text; } diff --git a/core/modules/user/src/AccountForm.php b/core/modules/user/src/AccountForm.php index a8f39aa5b34f884c5163b525848b771df37f874a..602f0e715d7497934bb0d3e47ea09478173611c7 100644 --- a/core/modules/user/src/AccountForm.php +++ b/core/modules/user/src/AccountForm.php @@ -7,6 +7,7 @@ namespace Drupal\user; +use Drupal\Component\Utility\Unicode; use Drupal\Core\Entity\ContentEntityForm; use Drupal\Core\Entity\EntityManagerInterface; use Drupal\Core\Entity\Query\QueryFactory; @@ -379,7 +380,7 @@ public function validate(array $form, FormStateInterface $form_state) { // automatic typed data validation in https://drupal.org/node/2227381. $field_definitions = $this->entityManager->getFieldDefinitions('user', $this->getEntity()->bundle()); $max_length = $field_definitions['signature']->getSetting('max_length'); - if (drupal_strlen($form_state->getValue('signature')) > $max_length) { + if (Unicode::strlen($form_state->getValue('signature')) > $max_length) { $form_state->setErrorByName('signature', $this->t('The signature is too long: it must be %max characters or less.', array('%max' => $max_length))); } } diff --git a/core/modules/user/src/Plugin/Validation/Constraint/UserNameConstraintValidator.php b/core/modules/user/src/Plugin/Validation/Constraint/UserNameConstraintValidator.php index 5b788ca7a2d4cf25c3164a6ab08b499717a67198..12d4fa3cc43a17077c3f3376f0f53610343ee837 100644 --- a/core/modules/user/src/Plugin/Validation/Constraint/UserNameConstraintValidator.php +++ b/core/modules/user/src/Plugin/Validation/Constraint/UserNameConstraintValidator.php @@ -7,6 +7,7 @@ namespace Drupal\user\Plugin\Validation\Constraint; +use Drupal\Component\Utility\Unicode; use Symfony\Component\Validator\Constraint; use Symfony\Component\Validator\ConstraintValidator; @@ -48,7 +49,7 @@ public function validate($items, Constraint $constraint) { ) { $this->context->addViolation($constraint->illegalMessage); } - if (drupal_strlen($name) > USERNAME_MAX_LENGTH) { + if (Unicode::strlen($name) > USERNAME_MAX_LENGTH) { $this->context->addViolation($constraint->tooLongMessage, array('%name' => $name, '%max' => USERNAME_MAX_LENGTH)); } } diff --git a/core/modules/user/user.module b/core/modules/user/user.module index 9c49486f6c87ce379b56efcd2e05a6ff16882531..6d3c6f30dbc47f95c38251eb7a8d6745878f6753 100644 --- a/core/modules/user/user.module +++ b/core/modules/user/user.module @@ -556,7 +556,7 @@ function template_preprocess_username(&$variables) { // their own shortening logic or add markup. If they do so, they must ensure // that $variables['name'] is safe for printing. $name = $variables['name_raw'] = $account->getUsername(); - if (drupal_strlen($name) > 20) { + if (Unicode::strlen($name) > 20) { $name = Unicode::truncate($name, 15, FALSE, TRUE); $variables['truncated'] = TRUE; } diff --git a/core/modules/views/src/Plugin/views/field/FieldPluginBase.php b/core/modules/views/src/Plugin/views/field/FieldPluginBase.php index eb4372673a9072613d00bb107f9b1b302898ffbf..f13b8dbfc5ea1b7282a4d444082334de8a9e1e51 100644 --- a/core/modules/views/src/Plugin/views/field/FieldPluginBase.php +++ b/core/modules/views/src/Plugin/views/field/FieldPluginBase.php @@ -1289,7 +1289,7 @@ public function renderText($alter) { $base_path = base_path(); // Checks whether the path starts with the base_path. if (strpos($more_link_path, $base_path) === 0) { - $more_link_path = Unicode::substr($more_link_path, drupal_strlen($base_path)); + $more_link_path = Unicode::substr($more_link_path, Unicode::strlen($base_path)); } $more_link = _l($more_link_text, $more_link_path, array('attributes' => array('class' => array('views-more-link')))); @@ -1705,7 +1705,7 @@ public function adminLabel($short = FALSE) { * The trimmed string. */ public static function trimText($alter, $value) { - if (drupal_strlen($value) > $alter['max_length']) { + if (Unicode::strlen($value) > $alter['max_length']) { $value = Unicode::substr($value, 0, $alter['max_length']); if (!empty($alter['word_boundary'])) { $regex = "(.*)\b.+"; diff --git a/core/modules/views/src/Plugin/views/filter/InOperator.php b/core/modules/views/src/Plugin/views/filter/InOperator.php index 07bdf669d4399e21380aaa9716d0f8c961210ab0..51468afa38c41dcf42498fc9a3ee6a81b8868726 100644 --- a/core/modules/views/src/Plugin/views/filter/InOperator.php +++ b/core/modules/views/src/Plugin/views/filter/InOperator.php @@ -367,7 +367,7 @@ public function adminSummary() { if ($values !== '') { $values .= ', '; } - if (drupal_strlen($values) > 8) { + if (Unicode::strlen($values) > 8) { $values = Unicode::truncate($values, 8, FALSE, TRUE); break; } diff --git a/core/modules/views_ui/views_ui.module b/core/modules/views_ui/views_ui.module index a6a51e34af88098efdad95d9bfb790ae5530c659..7bf6e7127c5b3683d6f18cd94117b4ebfd3b96e6 100644 --- a/core/modules/views_ui/views_ui.module +++ b/core/modules/views_ui/views_ui.module @@ -327,7 +327,7 @@ function views_ui_views_analyze(ViewExecutable $view) { * This is often used in the UI to ensure long strings fit. */ function views_ui_truncate($string, $length) { - if (drupal_strlen($string) > $length) { + if (Unicode::strlen($string) > $length) { $string = Unicode::substr($string, 0, $length); $string .= '...'; }