Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F99052465
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
Sat, Jan 18, 18:08
Size
1 KB
Mime Type
text/x-php
Expires
Mon, Jan 20, 18:08 (2 d)
Engine
blob
Format
Raw Data
Handle
23697946
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
();
$args
[
0
]
=
PhutilConsoleFormatter
::
interpretFormat
(
$args
[
0
]);
$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