Str.php 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455
  1. <?php
  2. declare(strict_types=1);
  3. namespace Yansongda\Supports;
  4. /**
  5. * Most of the methods in this file come from illuminate/support.
  6. * thanks provide such a useful class.
  7. */
  8. class Str
  9. {
  10. public static function after(string $subject, string $search): string
  11. {
  12. return '' === $search ? $subject : array_reverse(explode($search, $subject, 2))[0];
  13. }
  14. public static function ascii(string $value, string $language = 'en'): string
  15. {
  16. $languageSpecific = static::languageSpecificCharsArray($language);
  17. if (!is_null($languageSpecific)) {
  18. $value = str_replace($languageSpecific[0], $languageSpecific[1], $value);
  19. }
  20. foreach (static::charsArray() as $key => $val) {
  21. $value = str_replace($val, $key, $value);
  22. }
  23. return preg_replace('/[^\x20-\x7E]/u', '', $value);
  24. }
  25. public static function before(string $subject, string $search): string
  26. {
  27. return '' === $search ? $subject : explode($search, $subject)[0];
  28. }
  29. public static function camel(string $value): string
  30. {
  31. return lcfirst(static::studly($value));
  32. }
  33. public static function contains(string $haystack, array|string $needles): bool
  34. {
  35. foreach ((array) $needles as $needle) {
  36. if (str_contains($haystack, $needle)) {
  37. return true;
  38. }
  39. }
  40. return false;
  41. }
  42. public static function endsWith(string $haystack, array|string $needles): bool
  43. {
  44. foreach ((array) $needles as $needle) {
  45. if (str_ends_with($haystack, $needle)) {
  46. return true;
  47. }
  48. }
  49. return false;
  50. }
  51. public static function finish(string $value, string $cap): string
  52. {
  53. $quoted = preg_quote($cap, '/');
  54. return preg_replace('/(?:'.$quoted.')+$/u', '', $value).$cap;
  55. }
  56. public static function is(array|string $pattern, string $value): bool
  57. {
  58. $patterns = Arr::wrap($pattern);
  59. if (empty($patterns)) {
  60. return false;
  61. }
  62. foreach ($patterns as $pattern) {
  63. // If the given value is an exact match we can of course return true right
  64. // from the beginning. Otherwise, we will translate asterisks and do an
  65. // actual pattern match against the two strings to see if they match.
  66. if ($pattern == $value) {
  67. return true;
  68. }
  69. $pattern = preg_quote($pattern, '#');
  70. // Asterisks are translated into zero-or-more regular expression wildcards
  71. // to make it convenient to check if the strings starts with the given
  72. // pattern such as "library/*", making any string check convenient.
  73. $pattern = str_replace('\*', '.*', $pattern);
  74. if (1 === preg_match('#^'.$pattern.'\z#u', $value)) {
  75. return true;
  76. }
  77. }
  78. return false;
  79. }
  80. public static function kebab(string $value): string
  81. {
  82. return static::snake($value, '-');
  83. }
  84. public static function length(string $value, ?string $encoding = null): int
  85. {
  86. if (null !== $encoding) {
  87. return mb_strlen($value, $encoding);
  88. }
  89. return mb_strlen($value);
  90. }
  91. public static function limit(string $value, int $limit = 100, string $end = '...'): string
  92. {
  93. if (mb_strwidth($value, 'UTF-8') <= $limit) {
  94. return $value;
  95. }
  96. return rtrim(mb_strimwidth($value, 0, $limit, '', 'UTF-8')).$end;
  97. }
  98. public static function lower(string $value): string
  99. {
  100. return mb_strtolower($value, 'UTF-8');
  101. }
  102. public static function words(string $value, int $words = 100, string $end = '...'): string
  103. {
  104. preg_match('/^\s*+\S++\s*+{1,'.$words.'}/u', $value, $matches);
  105. if (!isset($matches[0]) || static::length($value) === static::length($matches[0])) {
  106. return $value;
  107. }
  108. return rtrim($matches[0]).$end;
  109. }
  110. public static function parseCallback(string $callback, ?string $default = null): array
  111. {
  112. return static::contains($callback, '@') ? explode('@', $callback, 2) : [$callback, $default];
  113. }
  114. public static function random(int $length = 16): string
  115. {
  116. $string = '';
  117. while (($len = strlen($string)) < $length) {
  118. $size = $length - $len;
  119. $bytes = random_bytes($size);
  120. $string .= substr(str_replace(['/', '+', '='], '', base64_encode($bytes)), 0, $size);
  121. }
  122. return $string;
  123. }
  124. public static function uuidV4(): string
  125. {
  126. return sprintf(
  127. '%04x%04x-%04x-%04x-%04x-%04x%04x%04x',
  128. // 32 bits for "time_low"
  129. mt_rand(0, 0xFFFF),
  130. mt_rand(0, 0xFFFF),
  131. // 16 bits for "time_mid"
  132. mt_rand(0, 0xFFFF),
  133. // 16 bits for "time_hi_and_version",
  134. // four most significant bits holds version number 4
  135. mt_rand(0, 0x0FFF) | 0x4000,
  136. // 16 bits, 8 bits for "clk_seq_hi_res",
  137. // 8 bits for "clk_seq_low",
  138. // two most significant bits holds zero and one for variant DCE1.1
  139. mt_rand(0, 0x3FFF) | 0x8000,
  140. // 48 bits for "node"
  141. mt_rand(0, 0xFFFF),
  142. mt_rand(0, 0xFFFF),
  143. mt_rand(0, 0xFFFF)
  144. );
  145. }
  146. public static function replaceArray(string $search, array $replace, string $subject): string
  147. {
  148. foreach ($replace as $value) {
  149. $subject = static::replaceFirst($search, $value, $subject);
  150. }
  151. return $subject;
  152. }
  153. public static function replaceFirst(string $search, string $replace, string $subject): string
  154. {
  155. if ('' == $search) {
  156. return $subject;
  157. }
  158. $position = strpos($subject, $search);
  159. if (false !== $position) {
  160. return substr_replace($subject, $replace, $position, strlen($search));
  161. }
  162. return $subject;
  163. }
  164. public static function replaceLast(string $search, string $replace, string $subject): string
  165. {
  166. $position = strrpos($subject, $search);
  167. if (false !== $position) {
  168. return substr_replace($subject, $replace, $position, strlen($search));
  169. }
  170. return $subject;
  171. }
  172. public static function start(string $value, string $prefix): string
  173. {
  174. $quoted = preg_quote($prefix, '/');
  175. return $prefix.preg_replace('/^(?:'.$quoted.')+/u', '', $value);
  176. }
  177. public static function upper(string $value): string
  178. {
  179. return mb_strtoupper($value, 'UTF-8');
  180. }
  181. public static function title(string $value): string
  182. {
  183. return mb_convert_case($value, MB_CASE_TITLE, 'UTF-8');
  184. }
  185. public static function slug(string $title, string $separator = '-', string $language = 'en'): string
  186. {
  187. $title = static::ascii($title, $language);
  188. // Convert all dashes/underscores into separator
  189. $flip = '-' == $separator ? '_' : '-';
  190. $title = preg_replace('!['.preg_quote($flip).']+!u', $separator, $title);
  191. // Replace @ with the word 'at'
  192. $title = str_replace('@', $separator.'at'.$separator, $title);
  193. // Remove all characters that are not the separator, letters, numbers, or whitespace.
  194. $title = preg_replace('![^'.preg_quote($separator).'\pL\pN\s]+!u', '', mb_strtolower($title));
  195. // Replace all separator characters and whitespace by a single separator
  196. $title = preg_replace('!['.preg_quote($separator).'\s]+!u', $separator, $title);
  197. return trim($title, $separator);
  198. }
  199. public static function snake(string $value, string $delimiter = '_'): string
  200. {
  201. if (!ctype_lower($value)) {
  202. $value = preg_replace('/\s+/u', '', ucwords($value));
  203. $value = static::lower(preg_replace('/(.)(?=[A-Z])/u', '$1'.$delimiter, $value));
  204. }
  205. return $value;
  206. }
  207. public static function startsWith(int|string $haystack, array|string $needles): bool
  208. {
  209. foreach ((array) $needles as $needle) {
  210. if (str_starts_with(strval($haystack), $needle)) {
  211. return true;
  212. }
  213. }
  214. return false;
  215. }
  216. public static function studly(string $value, string $gap = ''): string
  217. {
  218. $value = ucwords(str_replace(['-', '_'], ' ', $value));
  219. return str_replace(' ', $gap, $value);
  220. }
  221. public static function substr(string $string, int $start, ?int $length = null): string
  222. {
  223. return mb_substr($string, $start, $length, 'UTF-8');
  224. }
  225. public static function ucfirst(string $string): string
  226. {
  227. return static::upper(static::substr($string, 0, 1)).static::substr($string, 1);
  228. }
  229. public static function encoding(string $string, string $to = 'utf-8', string $from = 'gb2312'): string
  230. {
  231. return mb_convert_encoding($string, $to, $from);
  232. }
  233. /**
  234. * @see https://github.com/danielstjules/Stringy/blob/3.1.0/LICENSE.txt
  235. */
  236. protected static function charsArray(): array
  237. {
  238. static $charsArray;
  239. if (isset($charsArray)) {
  240. return $charsArray;
  241. }
  242. return $charsArray = [
  243. '0' => ['°', '₀', '۰', '0'],
  244. '1' => ['¹', '₁', '۱', '1'],
  245. '2' => ['²', '₂', '۲', '2'],
  246. '3' => ['³', '₃', '۳', '3'],
  247. '4' => ['⁴', '₄', '۴', '٤', '4'],
  248. '5' => ['⁵', '₅', '۵', '٥', '5'],
  249. '6' => ['⁶', '₆', '۶', '٦', '6'],
  250. '7' => ['⁷', '₇', '۷', '7'],
  251. '8' => ['⁸', '₈', '۸', '8'],
  252. '9' => ['⁹', '₉', '۹', '9'],
  253. 'a' => ['à', 'á', 'ả', 'ã', 'ạ', 'ă', 'ắ', 'ằ', 'ẳ', 'ẵ', 'ặ', 'â', 'ấ', 'ầ', 'ẩ', 'ẫ', 'ậ', 'ā', 'ą', 'å', 'α', 'ά', 'ἀ', 'ἁ', 'ἂ', 'ἃ', 'ἄ', 'ἅ', 'ἆ', 'ἇ', 'ᾀ', 'ᾁ', 'ᾂ', 'ᾃ', 'ᾄ', 'ᾅ', 'ᾆ', 'ᾇ', 'ὰ', 'ά', 'ᾰ', 'ᾱ', 'ᾲ', 'ᾳ', 'ᾴ', 'ᾶ', 'ᾷ', 'а', 'أ', 'အ', 'ာ', 'ါ', 'ǻ', 'ǎ', 'ª', 'ა', 'अ', 'ا', 'a', 'ä'],
  254. 'b' => ['б', 'β', 'ب', 'ဗ', 'ბ', 'b'],
  255. 'c' => ['ç', 'ć', 'č', 'ĉ', 'ċ', 'c'],
  256. 'd' => ['ď', 'ð', 'đ', 'ƌ', 'ȡ', 'ɖ', 'ɗ', 'ᵭ', 'ᶁ', 'ᶑ', 'д', 'δ', 'د', 'ض', 'ဍ', 'ဒ', 'დ', 'd'],
  257. 'e' => ['é', 'è', 'ẻ', 'ẽ', 'ẹ', 'ê', 'ế', 'ề', 'ể', 'ễ', 'ệ', 'ë', 'ē', 'ę', 'ě', 'ĕ', 'ė', 'ε', 'έ', 'ἐ', 'ἑ', 'ἒ', 'ἓ', 'ἔ', 'ἕ', 'ὲ', 'έ', 'е', 'ё', 'э', 'є', 'ə', 'ဧ', 'ေ', 'ဲ', 'ე', 'ए', 'إ', 'ئ', 'e'],
  258. 'f' => ['ф', 'φ', 'ف', 'ƒ', 'ფ', 'f'],
  259. 'g' => ['ĝ', 'ğ', 'ġ', 'ģ', 'г', 'ґ', 'γ', 'ဂ', 'გ', 'گ', 'g'],
  260. 'h' => ['ĥ', 'ħ', 'η', 'ή', 'ح', 'ه', 'ဟ', 'ှ', 'ჰ', 'h'],
  261. 'i' => ['í', 'ì', 'ỉ', 'ĩ', 'ị', 'î', 'ï', 'ī', 'ĭ', 'į', 'ı', 'ι', 'ί', 'ϊ', 'ΐ', 'ἰ', 'ἱ', 'ἲ', 'ἳ', 'ἴ', 'ἵ', 'ἶ', 'ἷ', 'ὶ', 'ί', 'ῐ', 'ῑ', 'ῒ', 'ΐ', 'ῖ', 'ῗ', 'і', 'ї', 'и', 'ဣ', 'ိ', 'ီ', 'ည်', 'ǐ', 'ი', 'इ', 'ی', 'i'],
  262. 'j' => ['ĵ', 'ј', 'Ј', 'ჯ', 'ج', 'j'],
  263. 'k' => ['ķ', 'ĸ', 'к', 'κ', 'Ķ', 'ق', 'ك', 'က', 'კ', 'ქ', 'ک', 'k'],
  264. 'l' => ['ł', 'ľ', 'ĺ', 'ļ', 'ŀ', 'л', 'λ', 'ل', 'လ', 'ლ', 'l'],
  265. 'm' => ['м', 'μ', 'م', 'မ', 'მ', 'm'],
  266. 'n' => ['ñ', 'ń', 'ň', 'ņ', 'ʼn', 'ŋ', 'ν', 'н', 'ن', 'န', 'ნ', 'n'],
  267. 'o' => ['ó', 'ò', 'ỏ', 'õ', 'ọ', 'ô', 'ố', 'ồ', 'ổ', 'ỗ', 'ộ', 'ơ', 'ớ', 'ờ', 'ở', 'ỡ', 'ợ', 'ø', 'ō', 'ő', 'ŏ', 'ο', 'ὀ', 'ὁ', 'ὂ', 'ὃ', 'ὄ', 'ὅ', 'ὸ', 'ό', 'о', 'و', 'θ', 'ို', 'ǒ', 'ǿ', 'º', 'ო', 'ओ', 'o', 'ö'],
  268. 'p' => ['п', 'π', 'ပ', 'პ', 'پ', 'p'],
  269. 'q' => ['ყ', 'q'],
  270. 'r' => ['ŕ', 'ř', 'ŗ', 'р', 'ρ', 'ر', 'რ', 'r'],
  271. 's' => ['ś', 'š', 'ş', 'с', 'σ', 'ș', 'ς', 'س', 'ص', 'စ', 'ſ', 'ს', 's'],
  272. 't' => ['ť', 'ţ', 'т', 'τ', 'ț', 'ت', 'ط', 'ဋ', 'တ', 'ŧ', 'თ', 'ტ', 't'],
  273. 'u' => ['ú', 'ù', 'ủ', 'ũ', 'ụ', 'ư', 'ứ', 'ừ', 'ử', 'ữ', 'ự', 'û', 'ū', 'ů', 'ű', 'ŭ', 'ų', 'µ', 'у', 'ဉ', 'ု', 'ူ', 'ǔ', 'ǖ', 'ǘ', 'ǚ', 'ǜ', 'უ', 'उ', 'u', 'ў', 'ü'],
  274. 'v' => ['в', 'ვ', 'ϐ', 'v'],
  275. 'w' => ['ŵ', 'ω', 'ώ', 'ဝ', 'ွ', 'w'],
  276. 'x' => ['χ', 'ξ', 'x'],
  277. 'y' => ['ý', 'ỳ', 'ỷ', 'ỹ', 'ỵ', 'ÿ', 'ŷ', 'й', 'ы', 'υ', 'ϋ', 'ύ', 'ΰ', 'ي', 'ယ', 'y'],
  278. 'z' => ['ź', 'ž', 'ż', 'з', 'ζ', 'ز', 'ဇ', 'ზ', 'z'],
  279. 'aa' => ['ع', 'आ', 'آ'],
  280. 'ae' => ['æ', 'ǽ'],
  281. 'ai' => ['ऐ'],
  282. 'ch' => ['ч', 'ჩ', 'ჭ', 'چ'],
  283. 'dj' => ['ђ', 'đ'],
  284. 'dz' => ['џ', 'ძ'],
  285. 'ei' => ['ऍ'],
  286. 'gh' => ['غ', 'ღ'],
  287. 'ii' => ['ई'],
  288. 'ij' => ['ij'],
  289. 'kh' => ['х', 'خ', 'ხ'],
  290. 'lj' => ['љ'],
  291. 'nj' => ['њ'],
  292. 'oe' => ['ö', 'œ', 'ؤ'],
  293. 'oi' => ['ऑ'],
  294. 'oii' => ['ऒ'],
  295. 'ps' => ['ψ'],
  296. 'sh' => ['ш', 'შ', 'ش'],
  297. 'shch' => ['щ'],
  298. 'ss' => ['ß'],
  299. 'sx' => ['ŝ'],
  300. 'th' => ['þ', 'ϑ', 'ث', 'ذ', 'ظ'],
  301. 'ts' => ['ц', 'ც', 'წ'],
  302. 'ue' => ['ü'],
  303. 'uu' => ['ऊ'],
  304. 'ya' => ['я'],
  305. 'yu' => ['ю'],
  306. 'zh' => ['ж', 'ჟ', 'ژ'],
  307. '(c)' => ['©'],
  308. 'A' => ['Á', 'À', 'Ả', 'Ã', 'Ạ', 'Ă', 'Ắ', 'Ằ', 'Ẳ', 'Ẵ', 'Ặ', 'Â', 'Ấ', 'Ầ', 'Ẩ', 'Ẫ', 'Ậ', 'Å', 'Ā', 'Ą', 'Α', 'Ά', 'Ἀ', 'Ἁ', 'Ἂ', 'Ἃ', 'Ἄ', 'Ἅ', 'Ἆ', 'Ἇ', 'ᾈ', 'ᾉ', 'ᾊ', 'ᾋ', 'ᾌ', 'ᾍ', 'ᾎ', 'ᾏ', 'Ᾰ', 'Ᾱ', 'Ὰ', 'Ά', 'ᾼ', 'А', 'Ǻ', 'Ǎ', 'A', 'Ä'],
  309. 'B' => ['Б', 'Β', 'ब', 'B'],
  310. 'C' => ['Ç', 'Ć', 'Č', 'Ĉ', 'Ċ', 'C'],
  311. 'D' => ['Ď', 'Ð', 'Đ', 'Ɖ', 'Ɗ', 'Ƌ', 'ᴅ', 'ᴆ', 'Д', 'Δ', 'D'],
  312. 'E' => ['É', 'È', 'Ẻ', 'Ẽ', 'Ẹ', 'Ê', 'Ế', 'Ề', 'Ể', 'Ễ', 'Ệ', 'Ë', 'Ē', 'Ę', 'Ě', 'Ĕ', 'Ė', 'Ε', 'Έ', 'Ἐ', 'Ἑ', 'Ἒ', 'Ἓ', 'Ἔ', 'Ἕ', 'Έ', 'Ὲ', 'Е', 'Ё', 'Э', 'Є', 'Ə', 'E'],
  313. 'F' => ['Ф', 'Φ', 'F'],
  314. 'G' => ['Ğ', 'Ġ', 'Ģ', 'Г', 'Ґ', 'Γ', 'G'],
  315. 'H' => ['Η', 'Ή', 'Ħ', 'H'],
  316. 'I' => ['Í', 'Ì', 'Ỉ', 'Ĩ', 'Ị', 'Î', 'Ï', 'Ī', 'Ĭ', 'Į', 'İ', 'Ι', 'Ί', 'Ϊ', 'Ἰ', 'Ἱ', 'Ἳ', 'Ἴ', 'Ἵ', 'Ἶ', 'Ἷ', 'Ῐ', 'Ῑ', 'Ὶ', 'Ί', 'И', 'І', 'Ї', 'Ǐ', 'ϒ', 'I'],
  317. 'J' => ['J'],
  318. 'K' => ['К', 'Κ', 'K'],
  319. 'L' => ['Ĺ', 'Ł', 'Л', 'Λ', 'Ļ', 'Ľ', 'Ŀ', 'ल', 'L'],
  320. 'M' => ['М', 'Μ', 'M'],
  321. 'N' => ['Ń', 'Ñ', 'Ň', 'Ņ', 'Ŋ', 'Н', 'Ν', 'N'],
  322. 'O' => ['Ó', 'Ò', 'Ỏ', 'Õ', 'Ọ', 'Ô', 'Ố', 'Ồ', 'Ổ', 'Ỗ', 'Ộ', 'Ơ', 'Ớ', 'Ờ', 'Ở', 'Ỡ', 'Ợ', 'Ø', 'Ō', 'Ő', 'Ŏ', 'Ο', 'Ό', 'Ὀ', 'Ὁ', 'Ὂ', 'Ὃ', 'Ὄ', 'Ὅ', 'Ὸ', 'Ό', 'О', 'Θ', 'Ө', 'Ǒ', 'Ǿ', 'O', 'Ö'],
  323. 'P' => ['П', 'Π', 'P'],
  324. 'Q' => ['Q'],
  325. 'R' => ['Ř', 'Ŕ', 'Р', 'Ρ', 'Ŗ', 'R'],
  326. 'S' => ['Ş', 'Ŝ', 'Ș', 'Š', 'Ś', 'С', 'Σ', 'S'],
  327. 'T' => ['Ť', 'Ţ', 'Ŧ', 'Ț', 'Т', 'Τ', 'T'],
  328. 'U' => ['Ú', 'Ù', 'Ủ', 'Ũ', 'Ụ', 'Ư', 'Ứ', 'Ừ', 'Ử', 'Ữ', 'Ự', 'Û', 'Ū', 'Ů', 'Ű', 'Ŭ', 'Ų', 'У', 'Ǔ', 'Ǖ', 'Ǘ', 'Ǚ', 'Ǜ', 'U', 'Ў', 'Ü'],
  329. 'V' => ['В', 'V'],
  330. 'W' => ['Ω', 'Ώ', 'Ŵ', 'W'],
  331. 'X' => ['Χ', 'Ξ', 'X'],
  332. 'Y' => ['Ý', 'Ỳ', 'Ỷ', 'Ỹ', 'Ỵ', 'Ÿ', 'Ῠ', 'Ῡ', 'Ὺ', 'Ύ', 'Ы', 'Й', 'Υ', 'Ϋ', 'Ŷ', 'Y'],
  333. 'Z' => ['Ź', 'Ž', 'Ż', 'З', 'Ζ', 'Z'],
  334. 'AE' => ['Æ', 'Ǽ'],
  335. 'Ch' => ['Ч'],
  336. 'Dj' => ['Ђ'],
  337. 'Dz' => ['Џ'],
  338. 'Gx' => ['Ĝ'],
  339. 'Hx' => ['Ĥ'],
  340. 'Ij' => ['IJ'],
  341. 'Jx' => ['Ĵ'],
  342. 'Kh' => ['Х'],
  343. 'Lj' => ['Љ'],
  344. 'Nj' => ['Њ'],
  345. 'Oe' => ['Œ'],
  346. 'Ps' => ['Ψ'],
  347. 'Sh' => ['Ш'],
  348. 'Shch' => ['Щ'],
  349. 'Ss' => ['ẞ'],
  350. 'Th' => ['Þ'],
  351. 'Ts' => ['Ц'],
  352. 'Ya' => ['Я'],
  353. 'Yu' => ['Ю'],
  354. 'Zh' => ['Ж'],
  355. ' ' => ["\xC2\xA0", "\xE2\x80\x80", "\xE2\x80\x81", "\xE2\x80\x82", "\xE2\x80\x83", "\xE2\x80\x84", "\xE2\x80\x85", "\xE2\x80\x86", "\xE2\x80\x87", "\xE2\x80\x88", "\xE2\x80\x89", "\xE2\x80\x8A", "\xE2\x80\xAF", "\xE2\x81\x9F", "\xE3\x80\x80", "\xEF\xBE\xA0"],
  356. ];
  357. }
  358. /**
  359. * @see https://github.com/danielstjules/Stringy/blob/3.1.0/LICENSE.txt
  360. */
  361. protected static function languageSpecificCharsArray(string $language): ?array
  362. {
  363. static $languageSpecific;
  364. if (!isset($languageSpecific)) {
  365. $languageSpecific = [
  366. 'bg' => [
  367. ['х', 'Х', 'щ', 'Щ', 'ъ', 'Ъ', 'ь', 'Ь'],
  368. ['h', 'H', 'sht', 'SHT', 'a', 'А', 'y', 'Y'],
  369. ],
  370. 'de' => [
  371. ['ä', 'ö', 'ü', 'Ä', 'Ö', 'Ü'],
  372. ['ae', 'oe', 'ue', 'AE', 'OE', 'UE'],
  373. ],
  374. ];
  375. }
  376. return $languageSpecific[$language] ?? null;
  377. }
  378. }