← Back to team overview

anewt-developers team mailing list archive

[Branch ~uws/anewt/anewt.uws] Rev 1746: [xhtml] Add ax_vsprintf() to complement ax_sprintf()

 

------------------------------------------------------------
revno: 1746
committer: Wouter Bolsterlee <uws@xxxxxxxxx>
branch nick: anewt.uws
timestamp: Tue 2010-02-16 00:31:12 +0100
message:
  [xhtml] Add ax_vsprintf() to complement ax_sprintf()
  
  This function works like ax_sprintf(), but the values are
  passed as an array instead of multiple parameters.
  
  Part of bug #503550.
modified:
  xhtml/api.lib.php
  xhtml/xhtml.test.php


--
lp:anewt
https://code.launchpad.net/~uws/anewt/anewt.uws

Your team Anewt developers is subscribed to branch lp:anewt.
To unsubscribe from this branch go to https://code.launchpad.net/~uws/anewt/anewt.uws/+edit-subscription.
=== modified file 'xhtml/api.lib.php'
--- xhtml/api.lib.php	2010-01-05 20:17:50 +0000
+++ xhtml/api.lib.php	2010-02-15 23:31:12 +0000
@@ -81,6 +81,28 @@
 
 	/* First parameter is the format */
 	$format = array_shift($values);
+
+	return ax_vsprintf($format, $values);
+
+}
+
+/**
+ * Format a text node using a format specifier and supplied values.
+ *
+ * This function works like ax_sprintf(), but the values are passed as an array
+ * instead of multiple parameters. See the ax_sprintf() documentation for more
+ * information.
+ * 
+ * \param $format
+ * \param $values
+ * \return
+ *
+ * \see ax_sprintf
+ */
+function ax_vsprintf($format, $values)
+{
+	assert('is_numeric_array($values);');
+
 	if ($format instanceof AnewtXMLDomNode) {
 		$format = to_string($format);
 	} else {

=== modified file 'xhtml/xhtml.test.php'
--- xhtml/xhtml.test.php	2009-07-19 20:16:18 +0000
+++ xhtml/xhtml.test.php	2010-02-15 23:31:12 +0000
@@ -181,6 +181,7 @@
 $r[] = $p;
 
 $r[] = ax_p(ax_sprintf('%s & %s', ax_span_class('Sugar', 'sweet'), 'Spice'));
+$r[] = ax_p(ax_vsprintf('%s & %s', array(ax_span_class('Sugar', 'sweet'), 'Spice')));
 
 $fragment->append_child(ax_fragment($r, ax_p('final paragraph')));