oscript.data
Class OString

java.lang.Object
  extended byoscript.data.Value
      extended byoscript.data.OObject
          extended byoscript.data.OString
All Implemented Interfaces:
java.io.Externalizable, java.io.Serializable
Direct Known Subclasses:
Symbol

public class OString
extends OObject
implements java.io.Externalizable

A string class. An OString is immutable, once the instance is constructed, it won't change.

Author:
Rob Clark (rob@ti.com)
See Also:
Serialized Form

Field Summary
static java.lang.String[] MEMBER_NAMES
           
static java.lang.String PARENT_TYPE_NAME
           
static Value TYPE
          The type object for an instance of String.
static java.lang.String TYPE_NAME
           
 
Fields inherited from class oscript.data.OObject
EMPTY_EXPR_LIST_EVALUATOR
 
Fields inherited from class oscript.data.Value
DEBUG, NULL, UNDEFINED
 
Constructor Summary
OString()
           
OString(MemberTable args)
          Class Constructor.
OString(java.lang.String stringVal)
          Construct a new string.
 
Method Summary
static Value _bopCast(Value val)
           
 Value bopEquals(Value val)
          Perform the "==" operation.
 Value bopEqualsR(Value val, PackagedScriptObjectException e)
           
 Value bopGreaterThan(Value val)
          Perform the ">" operation.
 Value bopGreaterThanOrEquals(Value val)
          Perform the ">=" operation.
 Value bopGreaterThanOrEqualsR(Value val, PackagedScriptObjectException e)
           
 Value bopGreaterThanR(Value val, PackagedScriptObjectException e)
           
 Value bopLessThan(Value val)
          Perform the "<" operation.
 Value bopLessThanOrEquals(Value val)
          Perform the "<=" operation.
 Value bopLessThanOrEqualsR(Value val, PackagedScriptObjectException e)
           
 Value bopLessThanR(Value val, PackagedScriptObjectException e)
           
 Value bopNotEquals(Value val)
          Perform the "!=" operation.
 Value bopNotEqualsR(Value val, PackagedScriptObjectException e)
           
 Value bopPlus(Value val)
          Perform the "+" operation.
 Value bopPlusR(Value val, PackagedScriptObjectException e)
           
 boolean castToBoolean()
          Convert this object to a native java boolean value.
 long castToExactNumber()
          Convert this object to a native java long value.
 double castToInexactNumber()
          Convert this object to a native java double value.
 java.lang.Object castToJavaObject()
          Convert this object to a native java Object value.
 java.lang.String castToString()
          Convert this object to a native java String value.
static java.lang.String chop(java.lang.String str)
           
 Value elementAt(Value oidx)
          Get the specified index of this object.
 Value elementsAt(Value idx1, Value idx2)
          Get the specified range of this object, if this object is an array.
 boolean endsWith(java.lang.String str)
           
 boolean equals(java.lang.Object obj)
          Compare two objects for equality.
protected  Value getTypeImpl()
          Get the type of this object.
 int hashCode()
          Return a hash code value for this object.
 int indexOf(java.lang.String str)
           
 int indexOf(java.lang.String str, int fromIdx)
           
 OString intern()
          Return a canonical representation of this OString object.
 int lastIndexOf(java.lang.String str)
           
 int lastIndexOf(java.lang.String str, int fromIdx)
           
 int length()
          For types that implement elementAt, this returns the number of elements.
static OString makeString(java.lang.String str)
          Return an intern'd OString....
 Value match(Value regexp)
          Returns the same thing as regexp.exec(this).
 void readExternal(java.io.ObjectInput in)
          Derived class that implements Externalizable must call this if it overrides it.
 Value replace(Value regexp, Value strOrFxn)
          Finds a match between a regular expression and this string object, and replaces the matched substring with a new substring.
 Value search(Value regexp)
          Executes the search for a match between a regular expression and this string object.
 boolean startsWith(java.lang.String str)
           
 java.lang.String substring(int begIdx)
           
 java.lang.String substring(int begIdx, int endIdx)
           
 java.lang.String toLowerCase()
           
 java.lang.String toUpperCase()
           
 java.lang.String trim()
           
 java.lang.String value()
          Get the value of this string.
 void writeExternal(java.io.ObjectOutput out)
          Derived class that implements Externalizable must call this if it overrides it.
 
Methods inherited from class oscript.data.OObject
getMember, populateMemberSet
 
Methods inherited from class oscript.data.Value
_getTypeMember, _populateTypeMemberSet, bopBitwiseAnd, bopBitwiseAndR, bopBitwiseOr, bopBitwiseOrR, bopBitwiseXor, bopBitwiseXorR, bopCast, bopCastR, bopDivide, bopDivideR, bopInstanceOf, bopInstanceOfR, bopLeftShift, bopLeftShiftR, bopLogicalAnd, bopLogicalAndR, bopLogicalOr, bopLogicalOrR, bopMinus, bopMinusR, bopMultiply, bopMultiplyR, bopRemainder, bopRemainderR, bopSignedRightShift, bopSignedRightShiftR, bopUnsignedRightShift, bopUnsignedRightShiftR, callAsConstructor, callAsConstructor, callAsConstructor, callAsExtends, callAsExtends, callAsExtends, callAsFunction, callAsFunction, callAsFunction, getMember, getMember, getMember, getMember, getMember, getMonitor, getType, getTypeMember, getTypeMember, isA, memberSet, noSuchMember, opAssign, populateTypeMemberSet, toString, unhand, uopBitwiseNot, uopDecrement, uopIncrement, uopLogicalNot, uopMinus, uopPlus
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

TYPE

public static final Value TYPE
The type object for an instance of String.


PARENT_TYPE_NAME

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

TYPE_NAME

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

MEMBER_NAMES

public static final java.lang.String[] MEMBER_NAMES
Constructor Detail

OString

public OString()

OString

public OString(java.lang.String stringVal)
Construct a new string.

Parameters:
stringVal - the value of the string

OString

public OString(MemberTable args)
Class Constructor. This is the constructor that gets called via an BuiltinType instance.

Parameters:
args - arguments to this constructor
Throws:
PackagedScriptObjectException(Exception) - if wrong number of args
Method Detail

readExternal

public void readExternal(java.io.ObjectInput in)
                  throws java.io.IOException
Derived class that implements Externalizable must call this if it overrides it. It should override it to save/restore it's own state.

Specified by:
readExternal in interface java.io.Externalizable
Overrides:
readExternal in class Value
Throws:
java.io.IOException

writeExternal

public void writeExternal(java.io.ObjectOutput out)
                   throws java.io.IOException
Derived class that implements Externalizable must call this if it overrides it. It should override it to save/restore it's own state.

Specified by:
writeExternal in interface java.io.Externalizable
Overrides:
writeExternal in class Value
Throws:
java.io.IOException

getTypeImpl

protected Value getTypeImpl()
Get the type of this object. The returned type doesn't have to take into account the possibility of a script type extending a built-in type, since that is handled by Value.getType().

Overrides:
getTypeImpl in class OObject
Returns:
the object's type

value

public final java.lang.String value()
Get the value of this string.

Returns:
the string as a java.lang.String

hashCode

public int hashCode()
Return a hash code value for this object.

Returns:
a hash code value
See Also:
Object.hashCode()

intern

public OString intern()
Return a canonical representation of this OString object. This has the result that x.intern() == y.intern() (for x and y that are OString objects).

Returns:
a OString that has the same value (in the sense of equals ) but is guaraneed to be from a unique pool of OStrings

equals

public boolean equals(java.lang.Object obj)
Compare two objects for equality.

Parameters:
obj - the object to compare to this object
Returns:
true if equals, else false
See Also:
Object.equals(java.lang.Object)

castToBoolean

public boolean castToBoolean()
                      throws PackagedScriptObjectException
Convert this object to a native java boolean value.

Overrides:
castToBoolean in class Value
Returns:
a boolean value
Throws:
PackagedScriptObjectException(NoSuchMethodException)
PackagedScriptObjectException

castToString

public java.lang.String castToString()
                              throws PackagedScriptObjectException
Convert this object to a native java String value.

Overrides:
castToString in class OObject
Returns:
a String value
Throws:
PackagedScriptObjectException(NoSuchMethodException)
PackagedScriptObjectException

_bopCast

public static Value _bopCast(Value val)

castToExactNumber

public long castToExactNumber()
                       throws PackagedScriptObjectException
Convert this object to a native java long value. In order for a string to be converted to an exact number, it must be of the form:
   STRING       ::== ("-")? (HEX_STRING | OCTAL_STRING | DEC_STRING)
   HEX_STRING   ::== ("0x" | "0X") ([0-9] | [a-f] | [A-F])+
   OCTAL_STRING ::== "0" ([0-7])+
   DEC_STRING   ::== ([0-9])+
 

Overrides:
castToExactNumber in class Value
Returns:
a long value
Throws:
PackagedScriptObjectException(NoSuchMethodException)
PackagedScriptObjectException

castToInexactNumber

public double castToInexactNumber()
                           throws PackagedScriptObjectException
Convert this object to a native java double value. In order for a string to be converted to an inexact number, it must be of the form:
   STRING       ::== ("+" | "-")? EXACT_NUMBER ("." EXACT_NUMBER)? (("e" | "E") EXACT_NUMBER)?
   EXACT_NUMBER ::== 
 

Overrides:
castToInexactNumber in class Value
Returns:
a double value
Throws:
PackagedScriptObjectException(NoSuchMethodException)
PackagedScriptObjectException

castToJavaObject

public java.lang.Object castToJavaObject()
                                  throws PackagedScriptObjectException
Convert this object to a native java Object value.

Overrides:
castToJavaObject in class Value
Returns:
a java object
Throws:
PackagedScriptObjectException(NoSuchMemberException)
PackagedScriptObjectException

bopEquals

public Value bopEquals(Value val)
                throws PackagedScriptObjectException
Perform the "==" operation.

Overrides:
bopEquals in class Value
Parameters:
val - the other value
Returns:
the result
Throws:
PackagedScriptObjectException(NoSuchMethodException)
PackagedScriptObjectException

bopEqualsR

public Value bopEqualsR(Value val,
                        PackagedScriptObjectException e)
                 throws PackagedScriptObjectException
Overrides:
bopEqualsR in class Value
Throws:
PackagedScriptObjectException

bopNotEquals

public Value bopNotEquals(Value val)
                   throws PackagedScriptObjectException
Perform the "!=" operation.

Overrides:
bopNotEquals in class Value
Parameters:
val - the other value
Returns:
the result
Throws:
PackagedScriptObjectException(NoSuchMethodException)
PackagedScriptObjectException

bopNotEqualsR

public Value bopNotEqualsR(Value val,
                           PackagedScriptObjectException e)
                    throws PackagedScriptObjectException
Overrides:
bopNotEqualsR in class Value
Throws:
PackagedScriptObjectException

bopLessThan

public Value bopLessThan(Value val)
                  throws PackagedScriptObjectException
Perform the "<" operation.

Overrides:
bopLessThan in class Value
Parameters:
val - the other value
Returns:
the result
Throws:
PackagedScriptObjectException(NoSuchMethodException)
PackagedScriptObjectException

bopLessThanR

public Value bopLessThanR(Value val,
                          PackagedScriptObjectException e)
                   throws PackagedScriptObjectException
Overrides:
bopLessThanR in class Value
Throws:
PackagedScriptObjectException

bopGreaterThan

public Value bopGreaterThan(Value val)
                     throws PackagedScriptObjectException
Perform the ">" operation.

Overrides:
bopGreaterThan in class Value
Parameters:
val - the other value
Returns:
the result
Throws:
PackagedScriptObjectException(NoSuchMethodException)
PackagedScriptObjectException

bopGreaterThanR

public Value bopGreaterThanR(Value val,
                             PackagedScriptObjectException e)
                      throws PackagedScriptObjectException
Overrides:
bopGreaterThanR in class Value
Throws:
PackagedScriptObjectException

bopLessThanOrEquals

public Value bopLessThanOrEquals(Value val)
                          throws PackagedScriptObjectException
Perform the "<=" operation.

Overrides:
bopLessThanOrEquals in class Value
Parameters:
val - the other value
Returns:
the result
Throws:
PackagedScriptObjectException(NoSuchMethodException)
PackagedScriptObjectException

bopLessThanOrEqualsR

public Value bopLessThanOrEqualsR(Value val,
                                  PackagedScriptObjectException e)
                           throws PackagedScriptObjectException
Overrides:
bopLessThanOrEqualsR in class Value
Throws:
PackagedScriptObjectException

bopGreaterThanOrEquals

public Value bopGreaterThanOrEquals(Value val)
                             throws PackagedScriptObjectException
Perform the ">=" operation.

Overrides:
bopGreaterThanOrEquals in class Value
Parameters:
val - the other value
Returns:
the result
Throws:
PackagedScriptObjectException(NoSuchMethodException)
PackagedScriptObjectException

bopGreaterThanOrEqualsR

public Value bopGreaterThanOrEqualsR(Value val,
                                     PackagedScriptObjectException e)
                              throws PackagedScriptObjectException
Overrides:
bopGreaterThanOrEqualsR in class Value
Throws:
PackagedScriptObjectException

bopPlus

public Value bopPlus(Value val)
              throws PackagedScriptObjectException
Perform the "+" operation.

Overrides:
bopPlus in class Value
Parameters:
val - the other value
Returns:
the result
Throws:
PackagedScriptObjectException(NoSuchMethodException)
PackagedScriptObjectException

bopPlusR

public Value bopPlusR(Value val,
                      PackagedScriptObjectException e)
               throws PackagedScriptObjectException
Overrides:
bopPlusR in class Value
Throws:
PackagedScriptObjectException

length

public int length()
           throws PackagedScriptObjectException
For types that implement elementAt, this returns the number of elements. This is the same as the length property of an object.

Overrides:
length in class Value
Returns:
an integer length
Throws:
PackagedScriptObjectException(NoSuchMethodException)
PackagedScriptObjectException
See Also:
elementAt(oscript.data.Value)

elementAt

public Value elementAt(Value oidx)
                throws PackagedScriptObjectException
Get the specified index of this object. This makes a string behave as an array, or at least support array indexing.

Overrides:
elementAt in class Value
Parameters:
oidx - the index to get
Returns:
a string of length one
Throws:
PackagedScriptObjectException(NoSuchMethodException)
PackagedScriptObjectException
See Also:
length()

elementsAt

public Value elementsAt(Value idx1,
                        Value idx2)
                 throws PackagedScriptObjectException
Get the specified range of this object, if this object is an array. This returns a copy of a range of the array.

Overrides:
elementsAt in class Value
Parameters:
idx1 - the index index of the beginning of the range, inclusive
idx2 - the index of the end of the range, inclusive
Returns:
a copy of the specified range of this array
Throws:
PackagedScriptObjectException(NoSuchMemberException)
PackagedScriptObjectException
See Also:
length(), elementAt(oscript.data.Value)

match

public Value match(Value regexp)
Returns the same thing as regexp.exec(this). The regexp should either be a RegExp object or a string that can be compiled to a RegExp object.

Note: this API is modeled after the JavaScript RegExp API, for the benefit of users already familiar with JavaScript.

Parameters:
regexp - the regular expression
Returns:
the result of regexp.exec.

replace

public Value replace(Value regexp,
                     Value strOrFxn)
Finds a match between a regular expression and this string object, and replaces the matched substring with a new substring. The second parameter can be either a replacement string, or a function called to determine the replacement string.

If the second parameter is a string, the following replacement patterns are evaluated and replaced with the appropriate value:

patternDescription
$$ Inserts a $
$& Inserts the matched substring
$` Inserts the portion of the string that precedes the matched substring
$' Inserts the portion of the string that follows the matched substring
$n Inserts the nth parenthesized submatch string
If the second parameter is a function, it is called with the following parameters:
paramDescription
0 the matched string
1-n zero or more parameters for parenthetical matches
n+1 offset of match
n+2 the original string

Note: this API is modeled after the JavaScript RegExp API, for the benefit of users already familiar with JavaScript.

Parameters:
regexp - the regular expression
strOrFxn - replacement string or function
Returns:
the resulting string

search

public Value search(Value regexp)
Executes the search for a match between a regular expression and this string object.

Note: this API is modeled after the JavaScript RegExp API, for the benefit of users already familiar with JavaScript.

Parameters:
regexp - the regular expression
Returns:
the index of the match, or -1 if none

substring

public java.lang.String substring(int begIdx)

substring

public java.lang.String substring(int begIdx,
                                  int endIdx)

indexOf

public int indexOf(java.lang.String str)

indexOf

public int indexOf(java.lang.String str,
                   int fromIdx)

lastIndexOf

public int lastIndexOf(java.lang.String str)

lastIndexOf

public int lastIndexOf(java.lang.String str,
                       int fromIdx)

toUpperCase

public java.lang.String toUpperCase()

toLowerCase

public java.lang.String toLowerCase()

startsWith

public boolean startsWith(java.lang.String str)

endsWith

public boolean endsWith(java.lang.String str)

trim

public java.lang.String trim()

makeString

public static final OString makeString(java.lang.String str)
Return an intern'd OString.... document this better!


chop

public static final java.lang.String chop(java.lang.String str)