Page Menu
Home
DevCentral
Search
Configure Global Search
Log In
Files
F3914220
D1605.id4102.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
D1605.id4102.diff
View Options
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
Details
Attached
Mime Type
text/plain
Expires
Fri, Dec 20, 13:48 (20 h, 59 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2307969
Default Alt Text
D1605.id4102.diff (2 KB)
Attached To
Mode
D1605: Use an empty string as default encoding argument for encoding
Attached
Detach File
Event Timeline
Log In to Comment