Extension talk:StringFunctionsEscaped/Archive

White-space trimming --Dmb 14:10, 4 June 2010 (UTC)
Hi,

How would I use this extension to make a general purpose 'white-space trimming' template? I often find that my layout of code in templates, which is optimized for readability, is substandard when it comes to layout, typically introducing too much white-space at the point where the template is called.

I'd like to write two 'wrapper' templates that would call templates but strip white-space:
 * 1) before and after the textual return value of the template, and
 * 2) everywhere within the textual return of the template.

For example, the latter template would be useful when the called template isn't designed to generate any output, but rather perform some calculation or another. In that case, the template should be 'invisible' to the calling page. As it is I often find a) problems with white-space, or b) template code that is hard to read and lacks in-line documentation.

Where I'd normally be saying, I'd like to say:


 * , or

Or something like that. Can I build those templates with this extension?

Cheers, --Dmb 14:10, 4 June 2010 (UTC)

Re:White-space trimming --jdpond 16:07, 4 June 2010 (UTC)

 * I don't know if this answers your question, but...


 * You could absolutely use this extension if you know what you want to remove by specifying the characters to remove. For example:


 * This will eliminate all the newlines from the source.


 * Some commonly used "white space" characters are:


 * "\x20" (ASCII 32 (0x20)), an ordinary space.
 * "\t" (ASCII 9 (0x09)), a tab.
 * "\n" (ASCII 10 (0x0A)), a new line (line feed).
 * "\r" (ASCII 13 (0x0D)), a carriage return.
 * "\0" (ASCII 0 (0x00)), the NUL-byte.
 * "\x0B" (ASCII 11 (0x0B)), a vertical tab


 * On the other hand, if you'd like me to add the PHP equivalent of "trim" and "php_strip_whitespace", I don't see why not, it would only take about 15 minutes to do - just submit that as an MW Extension Enhancement Request. (make sure you select the component "StringFunctionsEscaped").  I'd probably use the #trim_e and the #strip_whitespace_e tags.