Page MenuHomePhabricator

D11677.diff
No OneTemporary

D11677.diff

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

Mime Type
text/plain
Expires
Tue, Jun 25, 10:54 AM (4 d, 6 h ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
6290414
Default Alt Text
D11677.diff (3 KB)

Event Timeline