Utility

Various helper functions placed in a Utility class.

Summary
UtilityVarious helper functions placed in a Utility class.
Functions
roundPointHelper for serialization to round points to 1 decimal place
round2Rounds a numeric value to at most 2 digits after the decimal point.
replaceAllSearch for a string of one or multiple characters, replace with another string of one or multiple chars.
shrinkSequencesOfShrink all sequences of a given character in a string to one.
beginsWithTests whether the string begins with the initial string.
substrUntilReturns a substring matching the part of string until the end token.
trimTrim whitespace from a string
ltrimTrim whitespace from left hand side of a string
rtrimTrim whitespace from right hand side of a string

Functions

roundPoint

public static function roundPoint(value: Point):Point

Helper for serialization to round points to 1 decimal place

Parameters

valuea point

Returns

A point with the x and y values rounded

round2

public static function round2(value: Number):String

Rounds a numeric value to at most 2 digits after the decimal point.

replaceAll

public static function replaceAll(str: String,
sFind: String,
sReplace: String):String

Search for a string of one or multiple characters, replace with another string of one or multiple chars.  Modelled after original AS1/2 code by Florian Kruesch.

Parameters

strstring to be searched
sFindstring to find
sReplacestring to replace found string with

Returns

A string with the search patterns replaced

shrinkSequencesOf

public static function shrinkSequencesOf(str: String,
ch: String):String

Shrink all sequences of a given character in a string to one.  Modelled after original AS1/2 code by Timothee Groleau.

Parameters

strinput string
cha single character

Returns

An input string with sequences removed

beginsWith

public static function beginsWith(str: String,
initial: String):Boolean

Tests whether the string begins with the initial string.

Parameters

strstring to be tested
initinitial string

Returns

True if matched

substrUntil

public static function substrUntil(str: String,
endToken: String):String

Returns a substring matching the part of string until the end token.

Parameters

strstring to be searched
initend of match string

Returns

Initial part of the string or whole string if endToken was not found

trim

public static function trim(str: String):String

Trim whitespace from a string

Parameters

strstring to be trimmed

Returns

Trimmed string

ltrim

public static function ltrim(str: String):String

Trim whitespace from left hand side of a string

Parameters

strstring to be trimmed

Returns

Trimmed string

rtrim

public static function rtrim(str: String):String

Trim whitespace from right hand side of a string

Parameters

strstring to be trimmed

Returns

Trimmed string

public static function roundPoint(value: Point):Point
Helper for serialization to round points to 1 decimal place
public static function round2(value: Number):String
Rounds a numeric value to at most 2 digits after the decimal point.
public static function replaceAll(str: String,
sFind: String,
sReplace: String):String
Search for a string of one or multiple characters, replace with another string of one or multiple chars.
public static function shrinkSequencesOf(str: String,
ch: String):String
Shrink all sequences of a given character in a string to one.
public static function beginsWith(str: String,
initial: String):Boolean
Tests whether the string begins with the initial string.
public static function substrUntil(str: String,
endToken: String):String
Returns a substring matching the part of string until the end token.
public static function trim(str: String):String
Trim whitespace from a string
public static function ltrim(str: String):String
Trim whitespace from left hand side of a string
public static function rtrim(str: String):String
Trim whitespace from right hand side of a string
Close