Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
yii2
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
PSDI Army
yii2
Commits
7af92173
Commit
7af92173
authored
Jul 30, 2014
by
Carsten Brandt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
length arg of byteSubstr is now optional
parent
cde71f43
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
33 additions
and
3 deletions
+33
-3
CHANGELOG.md
framework/CHANGELOG.md
+1
-0
BaseStringHelper.php
framework/helpers/BaseStringHelper.php
+4
-3
StringHelperTest.php
tests/unit/framework/helpers/StringHelperTest.php
+28
-0
No files found.
framework/CHANGELOG.md
View file @
7af92173
...
...
@@ -82,6 +82,7 @@ Yii Framework 2 Change Log
-
Bug: URL encoding for the route parameter added to
`\yii\web\UrlManager`
(klimov-paul)
-
Bug: Fixed the bug that requesting protected or private action methods would cause 500 error instead of 404 (qiangxue)
-
Bug: Fixed Object of class Imagick could not be converted to string in CaptchaAction (eXprojects, cebe)
-
Bug: Fixed wrong behavior of
`StringHelper::byteSubstr()`
in some edge cases (cebe)
-
Enh #87: Helper
`yii\helpers\Security`
converted into application component, cryptographic strength improved (klimov-paul)
-
Enh #422: Added Support for BIT(M) data type default values in Schema (cebe)
-
Enh #1160: Added $strict parameter to Inflector::camel2id() to handle consecutive uppercase chars (schmunk)
...
...
framework/helpers/BaseStringHelper.php
View file @
7af92173
...
...
@@ -34,13 +34,14 @@ class BaseStringHelper
* This method ensures the string is treated as a byte array by using `mb_substr()`.
* @param string $string the input string. Must be one character or longer.
* @param integer $start the starting position
* @param integer $length the desired portion length
* @param integer $length the desired portion length. If not specified or `null`, there will be
* no limit on length i.e. the output will be until the end of the string.
* @return string the extracted part of string, or FALSE on failure or an empty string.
* @see http://www.php.net/manual/en/function.substr.php
*/
public
static
function
byteSubstr
(
$string
,
$start
,
$length
)
public
static
function
byteSubstr
(
$string
,
$start
,
$length
=
null
)
{
return
mb_substr
(
$string
,
$start
,
$length
?:
mb_strlen
(
$string
,
'8bit'
)
,
'8bit'
);
return
mb_substr
(
$string
,
$start
,
$length
===
null
?
mb_strlen
(
$string
,
'8bit'
)
:
$length
,
'8bit'
);
}
/**
...
...
tests/unit/framework/helpers/StringHelperTest.php
View file @
7af92173
...
...
@@ -26,6 +26,34 @@ class StringHelperTest extends TestCase
{
$this
->
assertEquals
(
'th'
,
StringHelper
::
byteSubstr
(
'this'
,
0
,
2
));
$this
->
assertEquals
(
'э'
,
StringHelper
::
byteSubstr
(
'это'
,
0
,
2
));
$this
->
assertEquals
(
'abcdef'
,
StringHelper
::
byteSubstr
(
'abcdef'
,
0
));
$this
->
assertEquals
(
'abcdef'
,
StringHelper
::
byteSubstr
(
'abcdef'
,
0
,
null
));
$this
->
assertEquals
(
'de'
,
StringHelper
::
byteSubstr
(
'abcdef'
,
3
,
2
));
$this
->
assertEquals
(
'def'
,
StringHelper
::
byteSubstr
(
'abcdef'
,
3
));
$this
->
assertEquals
(
'def'
,
StringHelper
::
byteSubstr
(
'abcdef'
,
3
,
null
));
$this
->
assertEquals
(
'cd'
,
StringHelper
::
byteSubstr
(
'abcdef'
,
-
4
,
2
));
$this
->
assertEquals
(
'cdef'
,
StringHelper
::
byteSubstr
(
'abcdef'
,
-
4
));
$this
->
assertEquals
(
'cdef'
,
StringHelper
::
byteSubstr
(
'abcdef'
,
-
4
,
null
));
$this
->
assertEquals
(
''
,
StringHelper
::
byteSubstr
(
'abcdef'
,
4
,
0
));
$this
->
assertEquals
(
''
,
StringHelper
::
byteSubstr
(
'abcdef'
,
-
4
,
0
));
$this
->
assertEquals
(
'это'
,
StringHelper
::
byteSubstr
(
'это'
,
0
));
$this
->
assertEquals
(
'это'
,
StringHelper
::
byteSubstr
(
'это'
,
0
,
null
));
$this
->
assertEquals
(
'т'
,
StringHelper
::
byteSubstr
(
'это'
,
2
,
2
));
$this
->
assertEquals
(
'то'
,
StringHelper
::
byteSubstr
(
'это'
,
2
));
$this
->
assertEquals
(
'то'
,
StringHelper
::
byteSubstr
(
'это'
,
2
,
null
));
$this
->
assertEquals
(
'т'
,
StringHelper
::
byteSubstr
(
'это'
,
-
4
,
2
));
$this
->
assertEquals
(
'то'
,
StringHelper
::
byteSubstr
(
'это'
,
-
4
));
$this
->
assertEquals
(
'то'
,
StringHelper
::
byteSubstr
(
'это'
,
-
4
,
null
));
$this
->
assertEquals
(
''
,
StringHelper
::
byteSubstr
(
'это'
,
4
,
0
));
$this
->
assertEquals
(
''
,
StringHelper
::
byteSubstr
(
'это'
,
-
4
,
0
));
}
public
function
testBasename
()
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment