Page MenuHomeDevCentral

D1607.id4106.diff
No OneTemporary

D1607.id4106.diff

diff --git a/composer.json b/composer.json
--- a/composer.json
+++ b/composer.json
@@ -16,7 +16,8 @@
"global functions"
],
"require": {
- "php": ">=5.4.0"
+ "php": ">=7.1.0",
+ "keruald/omnitools": "dev-master"
},
"require-dev": {
"phpunit/phpunit": "^7"
diff --git a/core.php b/core.php
--- a/core.php
+++ b/core.php
@@ -2,6 +2,8 @@
namespace Keruald;
+use Keruald\OmniTools\Strings\Multibyte\StringUtilities;
+
/**
* Keruald, core libraries for Pluton and Xen engines.
*
@@ -22,40 +24,10 @@
* @param string $encoding the character encoding (optional)
*
* @return string the padded string
- *
+ * @deprecated Use Keruald\OmniTools\Strings\Multibyte\StringUtilities::pad
*/
function mb_str_pad($input, $pad_length, $pad_string = ' ', $pad_type = STR_PAD_RIGHT, $encoding = null) {
- // Inspired by Ronald Ulysses Swanson method
- // http://stackoverflow.com/a/27194169/1930997
- // who followed the str_pad PHP implementation.
-
- if ($encoding === null) {
- $encoding = mb_internal_encoding();
- }
-
- $padBefore = $pad_type === STR_PAD_BOTH || $pad_type === STR_PAD_LEFT;
- $padAfter = $pad_type === STR_PAD_BOTH || $pad_type === STR_PAD_RIGHT;
-
- $pad_length -= mb_strlen($input, $encoding);
- if ($padBefore && $padAfter) {
- $targetLength = $pad_length / 2;
- } else {
- $targetLength = $pad_length;
- }
- $strToRepeatLength = mb_strlen($pad_string, $encoding);
- $repeatTimes = ceil($targetLength / $strToRepeatLength);
- $repeatedString = str_repeat($pad_string, max(0, $repeatTimes)); // safe if used with valid Unicode sequences (any charset)
-
- $paddedString = '';
- if ($padBefore) {
- $paddedString = mb_substr($repeatedString, 0, floor($targetLength), $encoding);
- }
- $paddedString .= $input;
- if ($padAfter) {
- $paddedString .= mb_substr($repeatedString, 0, ceil($targetLength), $encoding);
- }
-
- return $paddedString;
+ return StringUtilities::pad($input, $pad_length, $pad_string, $pad_type, $encoding);
}
/**

File Metadata

Mime Type
text/plain
Expires
Sun, Nov 24, 14:32 (6 h, 1 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2260335
Default Alt Text
D1607.id4106.diff (2 KB)

Event Timeline