Class XString
java.lang.Object
org.loboevolution.apache.xpath.Expression
org.loboevolution.apache.xpath.objects.XObject
org.loboevolution.apache.xpath.objects.XString
- All Implemented Interfaces:
SourceLocator
,ExpressionNode
,XPathVisitable
This class represents an XPath string object, and is capable of converting the string to other
types, such as a number.
-
Field Summary
Fields inherited from class org.loboevolution.apache.xpath.objects.XObject
CLASS_BOOLEAN, CLASS_NODESET, CLASS_NULL, CLASS_NUMBER, CLASS_RTREEFRAG, CLASS_STRING, CLASS_UNKNOWN, m_obj
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionboolean
bool()
Cast result object to a boolean.void
callVisitors
(XPathVisitor visitor) This will traverse the hierarchy, calling the visitor for each member.char
charAt
(int index) Returns the character at the specified index.boolean
boolean
Compares this string to the specifiedString
.boolean
Tell if two objects are functionally equal.boolean
Compares this string to the specified object.fixWhiteSpace
(boolean trimHead, boolean trimTail, boolean doublePunctuationSpaces) Conditionally trim all leading and trailing whitespace in the specified String.void
getChars
(int srcBegin, int srcEnd, char[] dst, int dstBegin) Copies characters from this string into the destination character array.int
getType()
Tell what kind of class this is.Given a request type, return the equivalent string.boolean
Tell if this object contains a java String object.int
Returns the index within this string of the first occurrence of the specified substring.int
length()
Returns the length of this string.double
num()
Cast result object to a number.boolean
startsWith
(XString prefix) Tests if this string starts with the specified prefix.boolean
startsWith
(XString prefix, int toffset) Tests if this string starts with the specified prefix beginning a specified index.str()
Cast result object to a string.substring
(int beginIndex) Returns a new string that is a substring of this string.substring
(int beginIndex, int endIndex) Returns a new string that is a substring of this string.double
toDouble()
Convert a string to a double -- Allowed input is in fixed notation ddd.fff.trim()
Removes white space from both ends of this string.xstr()
Cast result object to a string.Methods inherited from class org.loboevolution.apache.xpath.objects.XObject
allowDetachToRelease, boolWithSideEffects, deepEquals, detach, error, error, execute, greaterThan, greaterThanOrEqual, iter, lessThan, lessThanOrEqual, mutableNodeset, nodelist, nodeset, notEquals, numWithSideEffects, object, setObject, toString
Methods inherited from class org.loboevolution.apache.xpath.Expression
asIterator, asNode, assertion, bool, canTraverseOutsideSubtree, error, execute, execute, execute, exprGetParent, exprSetParent, getColumnNumber, getExpressionOwner, getLineNumber, getPublicId, getSystemId, isSameClass, isStableNumber, num
-
Field Details
-
EMPTYSTRING
Empty string XString object
-
-
Constructor Details
-
XString
Construct a XNodeSet object.- Parameters:
val
- String object this will wrap.
-
-
Method Details
-
getType
public int getType()Tell what kind of class this is. -
getTypeString
Given a request type, return the equivalent string. For diagnostic purposes.- Overrides:
getTypeString
in classXObject
- Returns:
- type string "#UNKNOWN" + object class name
-
hasString
public boolean hasString()Tell if this object contains a java String object.- Returns:
- true if this XMLString can return a string without creating one.
-
num
public double num()Cast result object to a number. Always issues an error. -
toDouble
public double toDouble()Convert a string to a double -- Allowed input is in fixed notation ddd.fff.- Returns:
- A double value representation of the string, or return Double.NaN if the string can not be converted.
-
bool
public boolean bool()Cast result object to a boolean. Always issues an error. -
xstr
Cast result object to a string. -
str
Cast result object to a string. -
length
public int length()Returns the length of this string.- Returns:
- the length of the sequence of characters represented by this object.
-
charAt
public char charAt(int index) Returns the character at the specified index. An index ranges from0
tolength() - 1
. The first character of the sequence is at index0
, the next at index1
, and so on, as for array indexing.- Parameters:
index
- the index of the character.- Returns:
- the character at the specified index of this string. The first character is at index
0
. - Throws:
IndexOutOfBoundsException
- if theindex
argument is negative or not less than the length of this string.
-
getChars
public void getChars(int srcBegin, int srcEnd, char[] dst, int dstBegin) Copies characters from this string into the destination character array.- Parameters:
srcBegin
- index of the first character in the string to copy.srcEnd
- index after the last character in the string to copy.dst
- the destination array.dstBegin
- the start offset in the destination array.- Throws:
IndexOutOfBoundsException
- If any of the following is true:srcBegin
is negative.srcBegin
is greater thansrcEnd
srcEnd
is greater than the length of this stringdstBegin
is negativedstBegin+(srcEnd-srcBegin)
is larger thandst.length
NullPointerException
- ifdst
isnull
-
equals
Tell if two objects are functionally equal. -
equals
Compares this string to the specifiedString
. The result istrue
if and only if the argument is notnull
and is aString
object that represents the same sequence of characters as this object.- Parameters:
obj2
- the object to compare thisString
against.- Returns:
true
if theString
s are equal;false
otherwise.- See Also:
-
equals
Compares this string to the specified object. The result istrue
if and only if the argument is notnull
and is aString
object that represents the same sequence of characters as this object.- Parameters:
obj2
- the object to compare thisString
against.- Returns:
true
if theString
are equal;false
otherwise.- See Also:
-
equals
-
startsWith
Tests if this string starts with the specified prefix beginning a specified index.- Parameters:
prefix
- the prefix.toffset
- where to begin looking in the string.- Returns:
true
if the character sequence represented by the argument is a prefix of the substring of this object starting at indextoffset
;false
otherwise. The result isfalse
iftoffset
is negative or greater than the length of thisString
object; otherwise the result is the same as the result of the expressionthis.subString(toffset).startsWith(prefix)
- Throws:
NullPointerException
- ifprefix
isnull
.
-
startsWith
Tests if this string starts with the specified prefix.- Parameters:
prefix
- the prefix.- Returns:
true
if the character sequence represented by the argument is a prefix of the character sequence represented by this string;false
otherwise. Note also thattrue
will be returned if the argument is an empty string or is equal to thisString
object as determined by theequals(Object)
method.- Throws:
NullPointerException
- ifprefix
isnull
.
-
indexOf
Returns the index within this string of the first occurrence of the specified substring. The integer returned is the smallest value k such that:this.startsWith(str, k)
true
.- Parameters:
str
- any string.- Returns:
- if the string argument occurs as a substring within this object, then the index of the
first character of the first such substring is returned; if it does not occur as a
substring,
-1
is returned. - Throws:
NullPointerException
- ifstr
isnull
.
-
substring
Returns a new string that is a substring of this string. The substring begins with the character at the specified index and extends to the end of this string.Examples:
"unhappy".substring(2) returns "happy" "Harbison".substring(3) returns "bison" "emptiness".substring(9) returns "" (an empty string)
- Parameters:
beginIndex
- the beginning index, inclusive.- Returns:
- the specified substring.
- Throws:
IndexOutOfBoundsException
- ifbeginIndex
is negative or larger than the length of thisString
object.
-
substring
Returns a new string that is a substring of this string. The substring begins at the specifiedbeginIndex
and extends to the character at indexendIndex - 1
. Thus the length of the substring isendIndex-beginIndex
.- Parameters:
beginIndex
- the beginning index, inclusive.endIndex
- the ending index, exclusive.- Returns:
- the specified substring.
- Throws:
IndexOutOfBoundsException
- if thebeginIndex
is negative, orendIndex
is larger than the length of thisString
object, orbeginIndex
is larger thanendIndex
.
-
trim
Removes white space from both ends of this string.- Returns:
- this string, with white space removed from the front and end.
-
fixWhiteSpace
Conditionally trim all leading and trailing whitespace in the specified String. All strings of white space are replaced by a single space character (#x20), except spaces after punctuation which receive double spaces if doublePunctuationSpaces is true. This function may be useful to a formatter, but to get first class results, the formatter should probably do it's own white space handling based on the semantics of the formatting object.- Parameters:
trimHead
- Trim leading whitespace?trimTail
- Trim trailing whitespace?doublePunctuationSpaces
- Use double spaces for punctuation?- Returns:
- The trimmed string.
-
callVisitors
This will traverse the hierarchy, calling the visitor for each member. If the called visitor method returns false, the subtree should not be called.- Specified by:
callVisitors
in interfaceXPathVisitable
- Overrides:
callVisitors
in classXObject
- Parameters:
visitor
- The visitor whose appropriate method will be called.
-