Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F102055845
tsprintf.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
Sun, Feb 16, 16:02
Size
1 KB
Mime Type
text/x-php
Expires
Tue, Feb 18, 16:02 (1 d, 23 h)
Engine
blob
Format
Raw Data
Handle
24271889
Attached To
rPHU libphutil
tsprintf.php
View Options
<?php
/**
* Format text for terminal output. This function behaves like `sprintf`,
* except that all the normal conversions (like "%s") will be properly escaped,
* and additional conversions are supported:
*
* %B (Block)
* Escapes text, but preserves tabs and newlines.
*
* %R (Raw String)
* Inserts raw, unescaped text. DANGEROUS!
*
* Particularly, this will escape terminal control characters.
*/
function
tsprintf
(
$pattern
/* , ... */
)
{
$args
=
func_get_args
();
$string
=
xsprintf
(
'xsprintf_terminal'
,
null
,
$args
);
return
new
PhutilTerminalString
(
$string
);
}
/**
* Callback for terminal encoding, see @{function:tsprintf} for use.
*/
function
xsprintf_terminal
(
$userdata
,
&
$pattern
,
&
$pos
,
&
$value
,
&
$length
)
{
$type
=
$pattern
[
$pos
];
switch
(
$type
)
{
case
's'
:
$value
=
PhutilTerminalString
::
escapeStringValue
(
$value
,
false
);
$type
=
's'
;
break
;
case
'B'
:
$value
=
PhutilTerminalString
::
escapeStringValue
(
$value
,
true
);
$type
=
's'
;
break
;
case
'R'
:
$type
=
's'
;
break
;
}
$pattern
[
$pos
]
=
$type
;
}
Event Timeline
Log In to Comment