@@ 62-73 (lines=12) @@ | ||
59 | * |
|
60 | * @return string |
|
61 | */ |
|
62 | public static function ensureTrailing($needle, $haystack) |
|
63 | { |
|
64 | $needleLength = strlen($needle); |
|
65 | $needlePart = substr($haystack, -1 * $needleLength); |
|
66 | ||
67 | if ($needlePart !== $needle) { |
|
68 | // append missing trailing character. |
|
69 | $haystack .= $needle; |
|
70 | } |
|
71 | ||
72 | return $haystack; |
|
73 | } |
|
74 | ||
75 | /** |
|
76 | * Ensure that a string is starts with a special string. |
|
@@ 88-99 (lines=12) @@ | ||
85 | * |
|
86 | * @return string |
|
87 | */ |
|
88 | public static function ensureLeading($needle, $haystack) |
|
89 | { |
|
90 | $needleLength = strlen($needle); |
|
91 | $needlePart = substr($haystack, 0, $needleLength); |
|
92 | ||
93 | if ($needlePart !== $needle) { |
|
94 | // append missing trailing string |
|
95 | $haystack = $needle . $haystack; |
|
96 | } |
|
97 | ||
98 | return $haystack; |
|
99 | } |
|
100 | ||
101 | /** |
|
102 | * Delete trailing characters. |