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
FieldsFields 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
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanbool()Cast result object to a boolean.voidcallVisitors(XPathVisitor visitor) This will traverse the hierarchy, calling the visitor for each member.charcharAt(int index) Returns the character at the specified index.booleanbooleanCompares this string to the specifiedString.booleanTell if two objects are functionally equal.booleanCompares this string to the specified object.fixWhiteSpace(boolean trimHead, boolean trimTail, boolean doublePunctuationSpaces) Conditionally trim all leading and trailing whitespace in the specified String.voidgetChars(int srcBegin, int srcEnd, char[] dst, int dstBegin) Copies characters from this string into the destination character array.intgetType()Tell what kind of class this is.Given a request type, return the equivalent string.booleanTell if this object contains a java String object.intReturns the index within this string of the first occurrence of the specified substring.intlength()Returns the length of this string.doublenum()Cast result object to a number.booleanstartsWith(XString prefix) Tests if this string starts with the specified prefix.booleanstartsWith(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.doubletoDouble()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, toStringMethods 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:
getTypeStringin 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 from0tolength() - 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 theindexargument 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:srcBeginis negative.srcBeginis greater thansrcEndsrcEndis greater than the length of this stringdstBeginis negativedstBegin+(srcEnd-srcBegin)is larger thandst.length
NullPointerException- ifdstisnull
-
equals
Tell if two objects are functionally equal. -
equals
Compares this string to the specifiedString. The result istrueif and only if the argument is notnulland is aStringobject that represents the same sequence of characters as this object.- Parameters:
obj2- the object to compare thisStringagainst.- Returns:
trueif theStrings are equal;falseotherwise.- See Also:
-
equals
Compares this string to the specified object. The result istrueif and only if the argument is notnulland is aStringobject that represents the same sequence of characters as this object.- Parameters:
obj2- the object to compare thisStringagainst.- Returns:
trueif theStringare equal;falseotherwise.- 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:
trueif the character sequence represented by the argument is a prefix of the substring of this object starting at indextoffset;falseotherwise. The result isfalseiftoffsetis negative or greater than the length of thisStringobject; otherwise the result is the same as the result of the expressionthis.subString(toffset).startsWith(prefix)- Throws:
NullPointerException- ifprefixisnull.
-
startsWith
Tests if this string starts with the specified prefix.- Parameters:
prefix- the prefix.- Returns:
trueif the character sequence represented by the argument is a prefix of the character sequence represented by this string;falseotherwise. Note also thattruewill be returned if the argument is an empty string or is equal to thisStringobject as determined by theequals(Object)method.- Throws:
NullPointerException- ifprefixisnull.
-
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:
isthis.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,
-1is returned. - Throws:
NullPointerException- ifstrisnull.
-
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- ifbeginIndexis negative or larger than the length of thisStringobject.
-
substring
Returns a new string that is a substring of this string. The substring begins at the specifiedbeginIndexand 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 thebeginIndexis negative, orendIndexis larger than the length of thisStringobject, orbeginIndexis 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:
callVisitorsin interfaceXPathVisitable- Overrides:
callVisitorsin classXObject- Parameters:
visitor- The visitor whose appropriate method will be called.
-