strings
This module provides String manipulation functionality (String templates, Fast writable Strings, ...).
module methods
- naturalCompare(a,b) - natural compare method which can be used for sorting string items in an array. It compares numbers in strings by their number value and not by their string value, allowing a more natural sorting.
module classes
WritableString(value) - Fast writable String.
Use it when you need a writable stream to generate a large String. This is much faster than using string concatenations (e.g. s += "new string data")
value="" - The initial value of the String.
- WritableString::write(s) - Writes a data to the object.
- s - The data to be written.
module members
- mod.templateCodeStartDelimiter="<?" - The default value for String::exec's codeStartDelimiter.
- mod.templateCodeEndDelimiter="?>" - The default value for String::exec's codeEndDelimiter.
native object extensions
- String::exec(locals, codeStartDelimiter, codeEndDelimiter) - Executes script inside a template String.
This is similar to PHP, ASP, JSP, PSP, ... in the way that script code inside special delimiters is executed and everything else is returned as is.
Each template is compiled to script code which is then executed.
There is always an 'out' object exposed to the script code run from the template. This object is a WritableString? object. The script can use it to write to the output.
It is possible to add objects to the script scope before it is run by providing a 'locals' parameter. Inside the template one can either use the <?= someValue ?> to insert a value at the location of the script code or use the <? out.write(someValue) ?> syntax. You can use any JavaScript? statements and constructs inside the template.
- locals={} - A dictionary containing name:value-pairs for local variables exposed to the script that is run from the template.
- codeStartDelimiter=mod.templateCodeStartDelimiter - The start of a codeblock.
- codeEndDelimiter=mod.templateCodeEndDelimiter - The end of a codeblock.
- Returns a string that results from running the template.
e.g.:
outputs:
"Example template run at Thu Mar 2 10:53:05 UTC 2006."
