Page Menu
Home
DevCentral
Search
Configure Global Search
Log In
Files
F3769341
D1607.id.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
2 KB
Referenced Files
None
Subscribers
None
D1607.id.diff
View Options
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
Details
Attached
Mime Type
text/plain
Expires
Sun, Nov 24, 14:13 (4 h, 24 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2260335
Default Alt Text
D1607.id.diff (2 KB)
Attached To
Mode
D1607: Switch mb_str_pad to Keruald\OmniTools\Strings\Multibyte implementation
Attached
Detach File
Event Timeline
Log In to Comment