Page Menu
Home
DevCentral
Search
Configure Global Search
Log In
Files
F14040058
OmniString.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
2 KB
Referenced Files
None
Subscribers
None
OmniString.php
View Options
<?php
declare
(
strict_types
=
1
);
namespace
Keruald\OmniTools\Strings\Multibyte
;
use
Keruald\OmniTools\Collections\Vector
;
class
OmniString
{
use
WithEncoding
;
///
/// Private members
///
/**
* @var string
*/
private
$value
;
///
/// Constructor
///
public
function
__construct
(
string
$value
=
''
,
string
$encoding
=
''
)
{
$this
->
value
=
$value
;
$this
->
setEncoding
(
$encoding
?:
"UTF-8"
);
}
///
/// Magic methods
///
public
function
__toString
()
:
string
{
return
$this
->
value
;
}
///
/// Helper methods
///
public
function
pad
(
int
$padLength
=
0
,
string
$padString
=
' '
,
int
$padType
=
STR_PAD_RIGHT
)
:
string
{
return
(
new
StringPad
)
->
setInput
(
$this
->
value
)
->
setEncoding
(
$this
->
encoding
)
->
setPadLength
(
$padLength
)
->
setPadString
(
$padString
)
->
setPadType
(
$padType
)
->
pad
();
}
public
function
startsWith
(
string
$start
)
:
bool
{
return
str_starts_with
(
$this
->
value
,
$start
);
}
public
function
endsWith
(
string
$end
)
:
bool
{
return
str_ends_with
(
$this
->
value
,
$end
);
}
public
function
len
()
:
int
{
return
mb_strlen
(
$this
->
value
,
$this
->
encoding
);
}
public
function
getChars
()
:
array
{
$chars
=
[];
$len
=
$this
->
len
();
for
(
$i
=
0
;
$i
<
$len
;
$i
++)
{
$chars
[]
=
mb_substr
(
$this
->
value
,
$i
,
1
,
$this
->
encoding
);
}
return
$chars
;
}
public
function
getBigrams
()
:
array
{
$bigrams
=
[];
$len
=
$this
->
len
();
for
(
$i
=
0
;
$i
<
$len
-
1
;
$i
++)
{
$bigrams
[]
=
mb_substr
(
$this
->
value
,
$i
,
2
,
$this
->
encoding
);
}
return
$bigrams
;
}
///
/// Transformation methods
///
public
function
explode
(
string
$delimiter
,
int
$limit
=
PHP_INT_MAX
)
:
Vector
{
if
(
$delimiter
===
""
)
{
if
(
$limit
<
0
)
{
return
new
Vector
;
}
return
new
Vector
([
$this
->
value
]);
}
return
new
Vector
(
explode
(
$delimiter
,
$this
->
value
,
$limit
));
}
///
/// Getters and setters
///
/**
* @return string
*/
public
function
getValue
()
:
string
{
return
$this
->
value
;
}
/**
* @param string $value
*/
public
function
setValue
(
string
$value
)
:
void
{
$this
->
value
=
$value
;
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Fri, Nov 28, 17:38 (1 d, 22 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3146609
Default Alt Text
OmniString.php (2 KB)
Attached To
Mode
rKOT Keruald OmniTools
Attached
Detach File
Event Timeline
Log In to Comment