Class StringValue


public final class StringValue extends Value
A string value
  • Constructor Details

    • StringValue

      public StringValue(String value)
      Constructor
      Parameters:
      value - the String value. Null is taken as equivalent to "".
  • Method Details

    • asString

      public String asString()
      Get the string value as a String
      Specified by:
      asString in class Value
      Returns:
      the value converted to a String
    • asNumber

      public double asNumber()
      Convert the string value to a number
      Specified by:
      asNumber in class Value
      Returns:
      the value converted to a String
    • asBoolean

      public boolean asBoolean()
      Convert the string value to a boolean
      Specified by:
      asBoolean in class Value
      Returns:
      false if the string value is zero-length, true otherwise
    • getDataType

      public int getDataType()
      Return the type of the expression (if known)
      Specified by:
      getDataType in class Expression
      Returns:
      Value.STRING (always)
    • getLength

      public int getLength()
      Get the length of this string, as defined in XPath. This is not the same as the Java length, as a Unicode surrogate pair counts as a single character
    • getLength

      public static int getLength(String s)
      Get the length of a string, as defined in XPath. This is not the same as the Java length, as a Unicode surrogate pair counts as a single character.
      Parameters:
      s - The string whose length is required
    • expand

      public static int[] expand(String s)
      Expand a string containing surrogate pairs into an array of 32-bit characters
    • equals

      public boolean equals(StringValue other)
      Determine if two StringValues are equal
    • conversionPreference

      public int conversionPreference(Class required)
      Get conversion preference for this value to a Java class. A low result indicates higher preference.
      Specified by:
      conversionPreference in class Value
    • convertToJava

      public Object convertToJava(Class target) throws XPathException
      Convert to Java object (for passing to external functions)
      Specified by:
      convertToJava in class Value
      Parameters:
      target - The class required by the external function
      Returns:
      an object of the target class
      Throws:
      XPathException
    • display

      public void display(int level)
      Diagnostic print of expression structure
      Specified by:
      display in class Expression