Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F101065744
PhutilTerminalString.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Wed, Feb 5, 09:33
Size
1 KB
Mime Type
text/x-php
Expires
Fri, Feb 7, 09:33 (2 d)
Engine
blob
Format
Raw Data
Handle
24087448
Attached To
rPHU libphutil
PhutilTerminalString.php
View Options
<?php
/**
* String escaped for terminal output. See @{function:tsprintf}.
*/
final
class
PhutilTerminalString
extends
Phobject
{
private
$string
;
public
function
__construct
(
$string
)
{
$this
->
string
=
$string
;
}
public
function
__toString
()
{
return
$this
->
string
;
}
public
static
function
escapeStringValue
(
$value
,
$allow_whitespace
)
{
if
(
$value
instanceof
PhutilTerminalString
)
{
return
(
string
)
$value
;
}
$value
=
(
string
)
$value
;
static
$escape_map
;
if
(
$escape_map
===
null
)
{
$escape_map
=
array
(
chr
(
0x00
)
=>
'<NUL>'
,
chr
(
0x07
)
=>
'<BEL>'
,
chr
(
0x08
)
=>
'<BS>'
,
chr
(
0x09
)
=>
'<TAB>'
,
chr
(
0x0A
)
=>
'<LF>'
,
chr
(
0x0D
)
=>
'<CR>'
,
chr
(
0x1B
)
=>
'<ESC>'
,
chr
(
0x7F
)
=>
'<DEL>'
,
);
for
(
$ii
=
0
;
$ii
<
32
;
$ii
++)
{
$c
=
chr
(
$ii
);
if
(
empty
(
$escape_map
[
$c
]))
{
$escape_map
[
$c
]
=
sprintf
(
'<0x%02X>'
,
$ii
);
}
}
}
$map
=
$escape_map
;
if
(
$allow_whitespace
)
{
unset
(
$map
[
"
\r
"
]);
unset
(
$map
[
"
\n
"
]);
unset
(
$map
[
"
\t
"
]);
}
$value
=
str_replace
(
array_keys
(
$map
),
array_values
(
$map
),
$value
);
// In this mode, we additionally escape any <CR> which is not immediately
// followed by <LF>.
if
(
$allow_whitespace
)
{
$value
=
preg_replace
(
'/
\r
(?!
\n
)/'
,
'<CR>'
,
$value
);
}
return
$value
;
}
}
Event Timeline
Log In to Comment