Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F15422642
D11677.id28097.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
3 KB
Referenced Files
None
Subscribers
None
D11677.id28097.diff
View Options
diff --git a/src/xsprintf/xsprintf.php b/src/xsprintf/xsprintf.php
--- a/src/xsprintf/xsprintf.php
+++ b/src/xsprintf/xsprintf.php
@@ -1,24 +1,24 @@
<?php
/**
- * Parse a sprintf()-style format string in an extensible way.
+ * Parse a `sprintf()`-style format string in an extensible way.
*
- * This method allows you to build a function with sprintf() semantics but
+ * This method allows you to build a function with `sprintf()` semantics but
* custom conversions for different datatypes. Three examples are
- * @{function:jsprintf} (which builds Javascript strings),
+ * @{function:jsprintf} (which builds JavaScript strings),
* @{function:qsprintf} (which builds MySQL strings), and
* @{function:csprintf} (which builds command line strings).
*
- * To build a new xsprintf-family function, provide a callback which conforms
+ * To build a new `xsprintf`-family function, provide a callback which conforms
* to the specification described in @{function:xsprintf_callback_example}. The
* callback will be invoked each time a conversion (like "%Z") is encountered
- * in the string. For instance, if you call xsprintf() like this...
+ * in the string. For instance, if you call `xsprintf()` like this...
*
* $result = xsprintf(
* 'xsprintf_callback_example',
* $userdata = null,
* array(
- * "The %M is made of %C.",
+ * 'The %M is made of %C.',
* 'moon',
* 'cheese',
* ));
@@ -29,17 +29,18 @@
* @param string The name of a callback to pass conversions to.
* @param wild Optional userdata to pass to the callback. For
* @{function:qsprintf}, this is the database connection.
- * @param list List of arguments, with the sprintf() pattern in position 0.
+ * @param list List of arguments, with the `sprintf()` pattern in
+ * position 0.
* @return string Formatted string.
*/
function xsprintf($callback, $userdata, array $argv) {
$argc = count($argv);
- $arg = 0;
- $pos = 0;
+ $arg = 0;
+ $pos = 0;
$pattern = $argv[0];
- $len = strlen($pattern);
+ $len = strlen($pattern);
- $conv = false; // Are we inside a conversion?
+ $conv = false; // Are we inside a conversion?
for ($pos = 0; $pos < $len; $pos++) {
$c = $pattern[$pos];
@@ -48,7 +49,10 @@
// but they really have no place in semantic string formatting.
if (strpos("'-0123456789.\$+", $c) !== false) {
throw new InvalidArgumentException(
- "xsprintf() does not support the `%{$c}' modifier.");
+ pht(
+ '%s does not support the "%s" modifier.',
+ 'xsprintf()',
+ "%{$c}"));
}
if ($c !== '%') {
@@ -57,7 +61,9 @@
$arg++;
if ($arg >= $argc) {
throw new BadFunctionCallException(
- 'Too few arguments to xsprintf().');
+ pht(
+ 'Too few arguments to %s.',
+ 'xsprintf()'));
}
$callback($userdata, $pattern, $pos, $argv[$arg], $len);
@@ -72,7 +78,10 @@
}
if ($arg !== ($argc - 1)) {
- throw new BadFunctionCallException('Too many arguments to xsprintf().');
+ throw new BadFunctionCallException(
+ pht(
+ 'Too many arguments to %s.',
+ 'xsprintf()'));
}
$argv[0] = $pattern;
@@ -109,6 +118,8 @@
&$value,
&$length) {
throw new RuntimeException(
- 'This function exists only to document the call signature for xsprintf() '.
- 'callbacks.');
+ pht(
+ 'This function exists only to document the call signature '.
+ 'for %s callbacks.',
+ 'xsprintf()'));
}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Sun, Mar 23, 9:58 AM (3 w, 4 d ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
7651341
Default Alt Text
D11677.id28097.diff (3 KB)
Attached To
Mode
D11677: `pht`ize some strings
Attached
Detach File
Event Timeline
Log In to Comment