Page MenuHomeDevCentral

D1605.id4102.diff
No OneTemporary

D1605.id4102.diff

diff --git a/src/Strings/Multibyte/OmniString.php b/src/Strings/Multibyte/OmniString.php
--- a/src/Strings/Multibyte/OmniString.php
+++ b/src/Strings/Multibyte/OmniString.php
@@ -20,9 +20,9 @@
/// Constructor
///
- public function __construct (string $value = '', ?string $encoding = null) {
+ public function __construct (string $value = '', string $encoding = '') {
$this->value = $value;
- $this->setEncoding($encoding ?? "UTF-8");
+ $this->setEncoding($encoding ?: "UTF-8");
}
///
diff --git a/src/Strings/Multibyte/StringPad.php b/src/Strings/Multibyte/StringPad.php
--- a/src/Strings/Multibyte/StringPad.php
+++ b/src/Strings/Multibyte/StringPad.php
@@ -56,14 +56,14 @@
int $padLength = 0,
string $padString = ' ',
int $padType = STR_PAD_RIGHT,
- ?string $encoding = null
+ string $encoding = ''
) {
$this->input = $input;
$this->padLength = $padLength;
$this->padString = $padString;
$this->setPadType($padType);
- $this->setEncoding($encoding ?? mb_internal_encoding());
+ $this->setEncoding($encoding ?: mb_internal_encoding());
}
///
diff --git a/src/Strings/Multibyte/StringUtilities.php b/src/Strings/Multibyte/StringUtilities.php
--- a/src/Strings/Multibyte/StringUtilities.php
+++ b/src/Strings/Multibyte/StringUtilities.php
@@ -29,7 +29,7 @@
->setPadLength($padLength)
->setPadString($padString)
->setPadType($padType)
- ->setEncoding($encoding)
+ ->setEncoding($encoding ?: mb_internal_encoding())
->pad();
}
diff --git a/tests/Strings/Multibyte/StringUtilitiesTest.php b/tests/Strings/Multibyte/StringUtilitiesTest.php
--- a/tests/Strings/Multibyte/StringUtilitiesTest.php
+++ b/tests/Strings/Multibyte/StringUtilitiesTest.php
@@ -26,6 +26,12 @@
$this->assertEquals($expected, $paddedString);
}
+ public function testPadWithDefaultArguments () : void {
+ $this->assertEquals("foo ", StringUtilities::pad("foo", 4));
+ $this->assertEquals("foo_", StringUtilities::pad("foo", 4, '_'));
+ $this->assertEquals("_foo", StringUtilities::pad("foo", 4, '_', STR_PAD_LEFT));
+ }
+
public function testSupportedEncoding () : void {
$this->assertTrue(StringUtilities::isSupportedEncoding("UTF-8"));
$this->assertFalse(StringUtilities::isSupportedEncoding("notexisting"));

File Metadata

Mime Type
text/plain
Expires
Sun, Nov 17, 18:10 (15 h, 34 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2249699
Default Alt Text
D1605.id4102.diff (2 KB)

Event Timeline