-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_Whitespace_.php
More file actions
61 lines (55 loc) · 1.33 KB
/
_Whitespace_.php
File metadata and controls
61 lines (55 loc) · 1.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<?php
/**
* _Chain_ ©2015 Julien <youlweb@hotmail.com>
* Refer to the LICENSE file for the full copyright and license information.
* @package chain/string
*/
namespace _Chain_\_String_;
use _Chain_\_AbsLink_;
use _Chain_\I_O;
use _Chain_\Type;
/**
* Remove extra whitespaces from a string.
*
* @author Julien <youlweb@hotmail.com>
*/
class _Whitespace_ extends _AbsLink_
{
/**
* @var bool
*/
private $_trim;
/**
* @param bool $trim Remove leading/trailing whitespaces.
*/
public function __construct($trim = true)
{
$this->_trim = $trim;
}
/**
* Remove extra whitespaces from a string.
*
* Reduce substrings containing more than one whitespace to a single
* whitespace. By default, leading and trailing whitespaces are also
* removed. Whitespaces include tab, newline, and linebreak characters.
*
* I/O contract
* ------------
* <pre>
* I string String to process.
* O string Processed string.
* X no
* </pre>
*
* @param I_O $IO
* @return I_O
*/
public function EXE(I_O $IO)
{
$filtered = preg_replace("/[\\x00-\\x20]+/", ' ', $IO->I_(Type::STRING));
if ($this->_trim) {
$filtered = trim($filtered);
}
return $IO->_O($filtered);
}
}