Page Menu
Home
WickedGov Phorge
Search
Configure Global Search
Log In
Files
F1431223
IsEqualIgnoringWhiteSpace.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
1 KB
Referenced Files
None
Subscribers
None
IsEqualIgnoringWhiteSpace.php
View Options
<?php
namespace
Hamcrest\Text
;
/*
Copyright (c) 2009 hamcrest.org
*/
use
Hamcrest\Description
;
use
Hamcrest\TypeSafeMatcher
;
/**
* Tests if a string is equal to another string, ignoring any changes in
* whitespace.
*/
class
IsEqualIgnoringWhiteSpace
extends
TypeSafeMatcher
{
private
$_string
;
public
function
__construct
(
$string
)
{
parent
::
__construct
(
self
::
TYPE_STRING
);
$this
->
_string
=
$string
;
}
protected
function
matchesSafely
(
$item
)
{
return
(
strtolower
(
$this
->
_stripSpace
(
$item
))
===
strtolower
(
$this
->
_stripSpace
(
$this
->
_string
)));
}
protected
function
describeMismatchSafely
(
$item
,
Description
$mismatchDescription
)
{
$mismatchDescription
->
appendText
(
'was '
)->
appendText
(
$item
);
}
public
function
describeTo
(
Description
$description
)
{
$description
->
appendText
(
'equalToIgnoringWhiteSpace('
)
->
appendValue
(
$this
->
_string
)
->
appendText
(
')'
)
;
}
/**
* Matches if value is a string equal to $string, regardless of whitespace.
*
* @factory
*/
public
static
function
equalToIgnoringWhiteSpace
(
$string
)
{
return
new
self
(
$string
);
}
// -- Private Methods
private
function
_stripSpace
(
$string
)
{
$parts
=
preg_split
(
"/[
\r\n\t
]+/"
,
$string
);
foreach
(
$parts
as
$i
=>
$part
)
{
$parts
[
$i
]
=
trim
(
$part
,
"
\r\n\t
"
);
}
return
trim
(
implode
(
' '
,
$parts
),
"
\r\n\t
"
);
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Sat, May 16, 20:12 (1 d, 1 h)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
e3/1c/ef42773508c40bfeefdf0d93732d
Default Alt Text
IsEqualIgnoringWhiteSpace.php (1 KB)
Attached To
Mode
rMWPROD MediaWiki Production
Attached
Detach File
Event Timeline
Log In to Comment