Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F95855050
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
Fri, Dec 20, 00:04
Size
1 KB
Mime Type
text/x-php
Expires
Sun, Dec 22, 00:04 (1 d, 23 h)
Engine
blob
Format
Raw Data
Handle
23067694
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
function
applyWrap
()
{
$string
=
(
string
)
$this
;
$string
=
phutil_console_wrap
(
$string
);
return
new
self
(
$string
);
}
public
function
applyIndent
(
$depth
,
$with_prefix
=
true
)
{
$string
=
(
string
)
$this
;
$string
=
phutil_console_wrap
(
$string
,
$depth
,
$with_prefix
);
return
new
self
(
$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