Str.php 18 KB

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