1 | <?php declare(strict_types=1); |
||
11 | class Str |
||
12 | { |
||
13 | /** |
||
14 | * CamelCases words or a dash name (eg. "hey-you" or "hey you" becomes "heyYou"). |
||
15 | * |
||
16 | * NB! This method is only for property formatted separated none |
||
17 | * multibyte (UTF-8) ASCII strings. It does not handle malformed strings with |
||
18 | * a lot of other weird characters. |
||
19 | * |
||
20 | * @param string $separatorString |
||
21 | * @param string $separator |
||
22 | * @param bool $upperCamelCase If first character should be capitalized (eg. "HeyYou" instead of "heyYou") |
||
23 | * @return string |
||
24 | */ |
||
25 | 2 | public static function separatorToCamel( |
|
37 | |||
38 | /** |
||
39 | * Converts CamelCase text to lowercase separator separated text (eg. "heyYou" becomes "hey-you"). |
||
40 | * |
||
41 | * NB! This method is only for none multibyte (UTF-8) ASCII strings. |
||
42 | * |
||
43 | * @param string $camelCaseString |
||
44 | * @param string $separator |
||
45 | * @return string |
||
46 | */ |
||
47 | 1 | public static function camelToSeparator(string $camelCaseString, string $separator = '_'): string |
|
54 | |||
55 | /** |
||
56 | * Get a random string generated from provided values. |
||
57 | * |
||
58 | * @param int $charCount |
||
59 | * @param string $characters |
||
60 | * @return string |
||
61 | */ |
||
62 | 1 | public static function random(int $charCount, string $characters = 'abcdefghijklmnopqrstuvqxyz0123456789'): string |
|
72 | |||
73 | /** |
||
74 | * Get shortened string. |
||
75 | * |
||
76 | * @param string $string |
||
77 | * @param int $maxLength |
||
78 | * @param string $indicator |
||
79 | * @return string |
||
80 | */ |
||
81 | 1 | public static function truncate(string $string, int $maxLength, string $indicator = '...'): string |
|
89 | |||
90 | /** |
||
91 | * Check if a string start with another substring. |
||
92 | * |
||
93 | * @param string $string |
||
94 | * @param string $search |
||
95 | * @return bool |
||
96 | */ |
||
97 | 3 | public static function startsWith(string $string, string $search): bool |
|
101 | |||
102 | /** |
||
103 | * Check if a string ends with another substring. |
||
104 | * |
||
105 | * @param string $string |
||
106 | * @param string $search |
||
107 | * @return bool |
||
108 | */ |
||
109 | 4 | public static function endsWith(string $string, string $search): bool |
|
113 | |||
114 | /** |
||
115 | * Remove left part of string and return the new string. |
||
116 | * |
||
117 | * @param string $string |
||
118 | * @param string $strip |
||
119 | * @return string |
||
120 | */ |
||
121 | 1 | public static function stripLeft(string $string, string $strip): string |
|
129 | |||
130 | /** |
||
131 | * Remove right part of string and return the new string. |
||
132 | * |
||
133 | * @param string $string |
||
134 | * @param string $strip |
||
135 | * @return string |
||
136 | */ |
||
137 | 2 | public static function stripRight(string $string, string $strip): string |
|
145 | |||
146 | /** |
||
147 | * Increment a string/separated string. |
||
148 | * |
||
149 | * Example: "a-name" becomes "a-name-2", "a-name-3" and so on. |
||
150 | * |
||
151 | * @param string $string |
||
152 | * @param string $separator |
||
153 | * @return string |
||
154 | */ |
||
155 | 1 | public static function incrementSeparated(string $string, string $separator = '-'): string |
|
168 | |||
169 | /** |
||
170 | * @param string $string |
||
171 | * @return string |
||
172 | */ |
||
173 | 1 | public static function uppercaseFirst(string $string): string |
|
181 | |||
182 | /** |
||
183 | * Filter out all non numeric characters and return a clean numeric string. |
||
184 | * |
||
185 | * @param string $string |
||
186 | * @param bool $allowDecimal |
||
187 | * @param bool $allowNegative |
||
188 | * @return string |
||
189 | */ |
||
190 | 3 | public static function toNumber(string $string, bool $allowDecimal = false, bool $allowNegative = false): string |
|
224 | |||
225 | /** |
||
226 | * @param string $search |
||
227 | * @param string $replace |
||
228 | * @param string $subject |
||
229 | * @return string |
||
230 | */ |
||
231 | 2 | public static function replaceFirst(string $search,string $replace,string $subject): string |
|
239 | } |
||
240 |