API Documentation | All Packages | All Classes | Index | Frames No Frames |
Class StringUtils

Package | org.openscales.core
Class | public final class StringUtils

Some string utilities.

Public Methods

| Method | Defined by
--- | --- | ---
|  | camelize(str:String):String [static] Camel-case a hyphenated string. | StringUtils
|  | contains(str:String, sub:String):Boolean [static] Test whether a string contains another string. | StringUtils
|  | format(template:String, context:Object, args:Array = null):String [static] Given a string with tokens in the form ${token}, return a string with tokens replaced with properties from the given context object. | StringUtils
|  | sprintf(format:String, ... args):String [static] Formatting output function, Perl's sprintf based, handling padding, truncation, floating-point numbers, left/right alignment and re-ordered arguments functionalities. | StringUtils
|  | startsWith(str:String, sub:String):Boolean [static] Test whether a string starts with another string. | StringUtils
|  | trim(s:String):String [static] Delete leading and ending series of white spaces. | StringUtils

Method detail

camelize | () | method

`public static function camelize(str:String):String`

Camel-case a hyphenated string. Ex. "chicken-head" becomes "chickenHead", and "-chicken-head" becomes "ChickenHead".

Parameters

| `str:String` — The string to be camelized. The original is not modified.

Returns

| `String` — The string, camelized

contains | () | method |

`public static function contains(str:String, sub:String):Boolean`

Test whether a string contains another string.

Parameters

| `str:String` — The string to test.
| `sub:String` — The substring to look for.

Returns

| `Boolean` — The first string contains the second.

format | () | method |

`public static function format(template:String, context:Object, args:Array = null):String`

Given a string with tokens in the form ${token}, return a string with tokens replaced with properties from the given context object. Represent a literal "${" by doubling it, e.g. "${${". Represent a literal "}" by doubling it, e.g. "}}".

This is a port of OpenLayers.BaseType.js format().

Parameters

| `template:String` — A string with tokens to be replaced. A templatehas the form "literal ${token}" where the token will be replaced by the value of context["token"].
| `context:Object` — An object with properties corresponding to the tokens in the format string. If no context, the template is returned unchanged.
| `args:Array` (default = `null`)`` — arguments to pass to any functions found in the context. If a context property is a function, the token will be replaced by the return from the function called with these arguments.

Returns

| `String` — a string with tokens replaced with properties from the given context object.

Example

       Trace.log("["+StringUtils.format(String("${{token}}=${token}"),{token:"item"})+"]");
       // renders:[${token}=item]

sprintf | () | method |

`public static function sprintf(format:String, ... args):String`

Formatting output function, Perl's sprintf based, handling padding, truncation, floating-point numbers, left/right alignment and re-ordered arguments functionalities.

Parameters

| `format:String` — string that containts the text to format.
| `... args` — depending on the format string, the function may expect a sequence of additional arguments, each containing a value.

Returns

| `String` — The formatted string.

See also

for original work
http://perldoc.perl.org/functions/sprintf.html

startsWith | () | method |

`public static function startsWith(str:String, sub:String):Boolean`

Test whether a string starts with another string.

Parameters

| `str:String` — The string to test.
| `sub:String` — The substring to look for.

Returns

| `Boolean` — The first string starts with the second.

trim | () | method |

`public static function trim(s:String):String`

Delete leading and ending series of white spaces.

Parameters

| `s:String` — the string to trim.

Returns

| `String` — a new string.

Example

       Trace.log("["+StringUtils.trim(String("\t \tx y z \t "))+"]");
       // renders:[x y z]