class NameUnicodeExtras in Name Field 8
Provides custom Unicode-related extension methods.
Hierarchy
- class \Drupal\Component\Utility\Unicode
- class \Drupal\name\NameUnicodeExtras
Expanded class hierarchy of NameUnicodeExtras
1 file declares its use of NameUnicodeExtras
- NameUnicodeExtrasTest.php in tests/
src/ Unit/ NameUnicodeExtrasTest.php
File
- src/
NameUnicodeExtras.php, line 12
Namespace
Drupal\nameView source
class NameUnicodeExtras extends Unicode {
/**
* Split each word in a UTF-8 string.
*
* @param string $text
* The text that will be converted.
*
* @return array
* The input $text as an array of words.
*/
public static function explode($text) {
$regex = '/(^|[' . static::PREG_CLASS_WORD_BOUNDARY . '])/u';
$words = preg_split($regex, $text, NULL, PREG_SPLIT_NO_EMPTY);
return $words;
}
/**
* Generate the initials of all first characters in a string.
*
* Note that this is case-insensitive, camel case words are treated as a
* single word.
*
* @param string $text
* The text that will be converted.
* @param string $delimitor
* An optional string to separate each character.
*
* @return string
* The input $text with first letters of each word capitalized.
*/
public static function initials($text, $delimitor = '') {
$text = mb_strtolower($text);
$results = [];
foreach (array_filter(self::explode($text)) as $word) {
$results[] = mb_substr($word, 0, 1);
}
$text = implode($delimitor, $results);
$text = mb_strtoupper($text);
return $text ? $text . $delimitor : '';
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
NameUnicodeExtras:: |
public static | function | Split each word in a UTF-8 string. | |
NameUnicodeExtras:: |
public static | function | Generate the initials of all first characters in a string. | |
Unicode:: |
public static | function | Flip U+C0-U+DE to U+E0-U+FD and back. Can be used as preg_replace callback. | |
Unicode:: |
public static | function | Checks for Unicode support in PHP and sets the proper settings if possible. | |
Unicode:: |
public static | function | Converts data to UTF-8. | |
Unicode:: |
public static | function | Decodes UTF byte-order mark (BOM) into the encoding's name. | |
Unicode:: |
public static | function | Gets the current status of unicode/multibyte support on this environment. | |
Unicode:: |
public static | function | Converts the first character of a UTF-8 string to lowercase. | |
Unicode:: |
public static | function | Decodes MIME/HTTP encoded header values. | |
Unicode:: |
public static | function | Encodes MIME/HTTP headers that contain incorrectly encoded characters. | |
Unicode:: |
constant | Matches Unicode characters that are word boundaries. | ||
Unicode:: |
public static | function | Sets the value for multibyte support status for the current environment. | |
Unicode:: |
constant | Indicates an error during check for PHP unicode support. | ||
Unicode:: |
constant | Indicates that full unicode support with the PHP mbstring extension is being used. | ||
Unicode:: |
constant | Indicates that standard PHP (emulated) unicode support is being used. | ||
Unicode:: |
public static | function | Compares UTF-8-encoded strings in a binary safe case-insensitive manner. | |
Unicode:: |
public static | function | Counts the number of characters in a UTF-8 string. | |
Unicode:: |
public static | function | Finds the position of the first occurrence of a string in another string. | |
Unicode:: |
public static | function | Converts a UTF-8 string to lowercase. | |
Unicode:: |
public static | function | Converts a UTF-8 string to uppercase. | |
Unicode:: |
public static | function | Cuts off a piece of a string based on character indices and counts. | |
Unicode:: |
public static | function | Truncates a UTF-8-encoded string safely to a number of characters. | |
Unicode:: |
public static | function | Truncates a UTF-8-encoded string safely to a number of bytes. | |
Unicode:: |
public static | function | Capitalizes the first character of a UTF-8 string. | |
Unicode:: |
public static | function | Capitalizes the first character of each word in a UTF-8 string. | |
Unicode:: |
public static | function | Checks whether a string is valid UTF-8. |