forked from phpgearbox/string
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRemove.php
More file actions
82 lines (76 loc) · 2.65 KB
/
Copy pathRemove.php
File metadata and controls
82 lines (76 loc) · 2.65 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
<?php namespace Gears\String\Methods;
////////////////////////////////////////////////////////////////////////////////
// __________ __ ________ __________
// \______ \ |__ ______ / _____/ ____ _____ ______\______ \ _______ ___
// | ___/ | \\____ \/ \ ____/ __ \\__ \\_ __ \ | _// _ \ \/ /
// | | | Y \ |_> > \_\ \ ___/ / __ \| | \/ | ( <_> > <
// |____| |___| / __/ \______ /\___ >____ /__| |______ /\____/__/\_ \
// \/|__| \/ \/ \/ \/ \/
// -----------------------------------------------------------------------------
// Designed and Developed by Brad Jones <brad @="bjc.id.au" />
// -----------------------------------------------------------------------------
////////////////////////////////////////////////////////////////////////////////
use voku\helper\UTF8;
trait Remove
{
/**
* Returns a new string with the prefix $substring removed, if present.
*
* @param string $substring The prefix to remove.
*
* @return static String without the prefix $substring.
*/
public function removeLeft($substring)
{
if ($this->startsWith($substring))
{
return $this->newSelf
(
UTF8::substr
(
$this->scalarString,
UTF8::strlen($substring, $this->encoding),
null,
$this->encoding
)
);
}
return $this;
}
/**
* Returns a new string with the suffix $substring removed, if present.
*
* @param string $substring The suffix to remove.
*
* @return static String without the suffix $substring.
*/
public function removeRight($substring)
{
if ($this->endsWith($substring))
{
return $this->newSelf
(
UTF8::substr
(
$this->scalarString,
0,
$this->getLength() - UTF8::strlen($substring, $this->encoding),
$this->encoding
)
);
}
return $this;
}
/**
* Trims and replaces consecutive whitespace characters with a single space.
*
* This includes tabs and newline characters, as well as multibyte
* whitespace such as the thin space and ideographic space.
*
* @return static Trimmed and condensed whitespace.
*/
public function removeWhitespace()
{
return $this->regexReplace('[[:space:]]+', ' ')->trim();
}
}