fr.emn.reactiveinput
Class ScriptUtilities

java.lang.Object
  extended byfr.emn.reactiveinput.ScriptUtilities

public class ScriptUtilities
extends java.lang.Object

General script utility methods.


Field Summary
static java.lang.String CLOSE_BLOCK
           
static java.lang.String INDENT_TAB
           
static java.lang.String ITEM_SEPARATOR
           
static java.lang.String OPEN_BLOCK
           
static java.lang.String STRING_DELIMITER
           
 
Constructor Summary
ScriptUtilities()
           
 
Method Summary
static java.lang.String addDelimiters(java.lang.String s)
          Adds end delimiter or block delimiters to the string.
static int[] checkBlockStructure(java.lang.String s)
          Checks parse errors in block delimiters.
static java.lang.String extractSection(java.lang.String script, java.lang.String sectionName)
          Returns a section of the script, null if not found.
static java.lang.String indent(java.lang.String s)
           
static java.lang.String indent(java.lang.String s, boolean addTabs, boolean addLinebreaks)
          Idents a string
static int indexOfCloseBlock(java.lang.String s)
          Returns the index of closing block, ignoring lower level blocks.
static java.lang.String leftRightsScript(java.lang.String[] leftrights, java.lang.String operator)
          TESTED Fusions [left][right][left][right] items (without delimiters) in one string with delimiters.
static java.lang.String[] listElements(java.lang.String listScript)
          Breaks a list of items into separate strings.
static java.lang.String[] listLeftRights(java.lang.String listScript, java.lang.String operator)
          TESTED Breaks a list of items in the form [left][operator][right][separator] into a string array in the form [left][right][left][right]...
static java.lang.String listScript(java.lang.String[] scripts)
          Fusions items (with delimiters) in one string.
static int outsideIndexOf(java.lang.String s, java.lang.String search)
          Returns the first occurrence of the specified string, ignoring all lower-level blocks.
static java.lang.String removeDelimiters(java.lang.String s)
          Removes block and item delimiters from this string.
static java.lang.String repairBlockStructure(java.lang.String s)
          Adds misleading block symbols in script.
static int searchEnd(java.lang.String s)
          Searches for the item end (delimiter or close block) in string.
static int searchOperator(java.lang.String s)
          Searches for the the first operator in item: Returns the index of first non-alphanumeric character.
static java.lang.String toScriptValue(java.lang.Object value)
          Returns the script form of a value.
static java.lang.String[] toStrings(java.util.Vector v)
           
static java.lang.Object toValue(java.lang.String genericValue, java.lang.Class type)
          Returns the object form of a script value.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

OPEN_BLOCK

public static final java.lang.String OPEN_BLOCK
See Also:
Constant Field Values

CLOSE_BLOCK

public static final java.lang.String CLOSE_BLOCK
See Also:
Constant Field Values

ITEM_SEPARATOR

public static final java.lang.String ITEM_SEPARATOR
See Also:
Constant Field Values

STRING_DELIMITER

public static final java.lang.String STRING_DELIMITER
See Also:
Constant Field Values

INDENT_TAB

public static final java.lang.String INDENT_TAB
See Also:
Constant Field Values
Constructor Detail

ScriptUtilities

public ScriptUtilities()
Method Detail

addDelimiters

public static java.lang.String addDelimiters(java.lang.String s)
Adds end delimiter or block delimiters to the string.


checkBlockStructure

public static int[] checkBlockStructure(java.lang.String s)
Checks parse errors in block delimiters.

Returns an array of two int:

[0] = The number of CLOSE_BLOCK without OPEN_BLOCK

[1] = The number of missing CLOSE_BLOCK at the end of the string

Both values must be equal to 0 for the string to be correct.


extractSection

public static java.lang.String extractSection(java.lang.String script,
                                              java.lang.String sectionName)
Returns a section of the script, null if not found.


indent

public static java.lang.String indent(java.lang.String s)

indent

public static java.lang.String indent(java.lang.String s,
                                      boolean addTabs,
                                      boolean addLinebreaks)
Idents a string


indexOfCloseBlock

public static int indexOfCloseBlock(java.lang.String s)
Returns the index of closing block, ignoring lower level blocks. Returns -1 if not found.


leftRightsScript

public static java.lang.String leftRightsScript(java.lang.String[] leftrights,
                                                java.lang.String operator)
TESTED Fusions [left][right][left][right] items (without delimiters) in one string with delimiters.


listElements

public static java.lang.String[] listElements(java.lang.String listScript)
Breaks a list of items into separate strings. Separators are kept.


listLeftRights

public static java.lang.String[] listLeftRights(java.lang.String listScript,
                                                java.lang.String operator)
TESTED Breaks a list of items in the form [left][operator][right][separator] into a string array in the form [left][right][left][right]... Separators are removed.


listScript

public static java.lang.String listScript(java.lang.String[] scripts)
Fusions items (with delimiters) in one string.


outsideIndexOf

public static int outsideIndexOf(java.lang.String s,
                                 java.lang.String search)
Returns the first occurrence of the specified string, ignoring all lower-level blocks.

s must not have parse errors


removeDelimiters

public static java.lang.String removeDelimiters(java.lang.String s)
Removes block and item delimiters from this string.


repairBlockStructure

public static java.lang.String repairBlockStructure(java.lang.String s)
Adds misleading block symbols in script.

Missing block delimiters ared usually added to bad strings to avoid parse error propagation:

"}a{{b}c{" -> "{# }a{{b}c{ #}}"


searchEnd

public static int searchEnd(java.lang.String s)
Searches for the item end (delimiter or close block) in string.


searchOperator

public static int searchOperator(java.lang.String s)
Searches for the the first operator in item: Returns the index of first non-alphanumeric character.


toScriptValue

public static java.lang.String toScriptValue(java.lang.Object value)
Returns the script form of a value. Examples:

"120" (Integer)

"120.58" (Float)

"abc" (String)

"true" (Boolean)

"[120, 55, 28]" (Integer array)

"[[2, 50], [3, 20]]" (2-dimensions Integer array)

etc.

Does not work with primitive arrays.


toStrings

public static java.lang.String[] toStrings(java.util.Vector v)

toValue

public static java.lang.Object toValue(java.lang.String genericValue,
                                       java.lang.Class type)
Returns the object form of a script value. Examples:

"120" (Integer)

"120.58" (Float)

"abc" (String)

"true", "yes" (Boolean)

"[120, 55, 28]" (Integer array)

"[[2, 50], [3, 20]]" (2-dimensions Integer array)

etc.