Packagech.capi.utils
Classpublic class VariableReplacer
InheritanceVariableReplacer Inheritance Object

Useful class to performe some replacements in a text, using an IMap to store the pairs of key/values.



Public Properties
 PropertyDefined By
  defaultVariableRegexp : RegExp
[static] Defines the regular expression for the variables.
VariableReplacer
  regexp : RegExp
Defines the regular expression of the variables.
VariableReplacer
  replacementCount : uint
[read-only] Defines the number of replacements done on the last String.
VariableReplacer
  variables : IMap
Defines the IMap that contains all pairs variable/value.
VariableReplacer
Public Methods
 MethodDefined By
  
VariableReplacer(variables:IMap = null, regexp:RegExp = null)
Creates a new VariableReplacer object.
VariableReplacer
  
replace(source:String, variables:IMap, regexp:RegExp = null):String
[static] Replaces the variables in the source String using the specified regular expression.
VariableReplacer
  
replaceVar(source:String, variableName:String, value:String, regexp:RegExp = null):String
[static] Replaces the specified variable in the source String using the specified regular expression.
VariableReplacer
  
replaceVars(source:String):String
Replaces all the variables contained in the source String using the specified IMap as source for the variables.
VariableReplacer
Property Detail
defaultVariableRegexpproperty
public static var defaultVariableRegexp:RegExp

Defines the regular expression for the variables. By default, a variable is always of the form ${VARIABLE_NAME}. The allowed characters for a variable name are A-Z, a-z, 0-9 and _.

regexpproperty 
regexp:RegExp  [read-write]

Defines the regular expression of the variables. This regular expression must have at least one parenthesis matching group.


Implementation
    public function get regexp():RegExp
    public function set regexp(value:RegExp):void
replacementCountproperty 
replacementCount:uint  [read-only]

Defines the number of replacements done on the last String.


Implementation
    public function get replacementCount():uint
variablesproperty 
variables:IMap  [read-write]

Defines the IMap that contains all pairs variable/value.


Implementation
    public function get variables():IMap
    public function set variables(value:IMap):void
Constructor Detail
VariableReplacer()Constructor
public function VariableReplacer(variables:IMap = null, regexp:RegExp = null)

Creates a new VariableReplacer object.

Parameters
variables:IMap (default = null) — The variables of the replacer. If no IMap is specified, then a DictionnaryMap will be used.
 
regexp:RegExp (default = null) — The regular expression for the variables. This regular expression must have at least one parenthesis matching group.
Method Detail
replace()method
public static function replace(source:String, variables:IMap, regexp:RegExp = null):String

Replaces the variables in the source String using the specified regular expression. This is a utility method for a fast useablility.

Parameters

source:String — The source String.
 
variables:IMap — The variables.
 
regexp:RegExp (default = null) — The regular expression of the variable.

Returns
String — The String with the replaced variables.
replaceVar()method 
public static function replaceVar(source:String, variableName:String, value:String, regexp:RegExp = null):String

Replaces the specified variable in the source String using the specified regular expression. This is a utility method for a fast useablility.

Parameters

source:String — The source String.
 
variableName:String — The name of the variable (ID in ${ID} with the default RegExp).
 
value:String — The value to set in place of the variable.
 
regexp:RegExp (default = null) — The regular expression of the variable.

Returns
String — The String with the replaced variables.
replaceVars()method 
public function replaceVars(source:String):String

Replaces all the variables contained in the source String using the specified IMap as source for the variables. If a variable is not defined, then an Error will be thrown.

Parameters

source:String — The source String to do the replacement.

Returns
String — The updated String with values.

Throws
Error If — a variable is not defined.